Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1254 - add campaign title to certificate #1264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ Read more at [End-2-End Testing](https://github.com/podkrepi-bg/frontend/blob/ma
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-63-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

Please check [contributors guide](https://github.com/podkrepi-bg/frontend/blob/master/CONTRIBUTING.md) for:
Expand Down
43 changes: 24 additions & 19 deletions src/components/pdf/Certificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Document, Page, StyleSheet, Text, View, Font, Image } from '@react-pdf/

import Logo from './Logo'
import { DonationResponse } from 'gql/donations'
import { PersonResponse } from 'gql/person'
import { formatDateString } from 'common/util/date'
import { money } from 'common/util/money'

Expand All @@ -22,7 +21,6 @@ const styles = StyleSheet.create({
position: 'absolute',
height: '100%',
width: '100%',
display: 'block',
},
heading: {
fontSize: '36',
Expand Down Expand Up @@ -52,37 +50,44 @@ const styles = StyleSheet.create({
},
donationText: {
textAlign: 'center',
marginTop: '50',
paddingTop: '5',
width: '300',
alignSelf: 'center',
fontSize: '16',
},
donationRow: {
textAlign: 'center',
color: '#2A4E84',
fontSize: '14',
width: '450',
height: '55',
alignSelf: 'center',
},
dateAndSignView: {
display: 'flex',
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: '15',
},
date: {
marginTop: '25',
marginTop: '10',
marginLeft: '50',
},
dateText: {
marginTop: '2',
marginTop: '5',
marginLeft: '50',
fontSize: '11',
},
members: {
fontSize: '11',
marginTop: '71',
marginTop: '60',
marginRight: '60',
marginLeft: '50',
},
signs: {
position: 'absolute',
left: '350',
top: '20',
top: '5',
display: 'flex',
justifyContent: 'space-around',
flexDirection: 'row',
Expand All @@ -106,11 +111,8 @@ const styles = StyleSheet.create({

type Props = {
donation: DonationResponse
person?: PersonResponse
}
export default function Certificate({ donation, person }: Props) {
const name = `${person?.firstName} ${person?.lastName}`
const formattedDate = formatDateString(donation.createdAt)
export default function Certificate({ donation }: Props) {
return (
<Document title="Дарение">
<Page size="LETTER" style={styles.page}>
Expand All @@ -121,20 +123,23 @@ export default function Certificate({ donation, person }: Props) {
<Text style={styles.subheading}>за дарение № {donation.id.slice(0, 2)}</Text>
</View>
<View>
<Text style={styles.text1}>С този сертификат Управителният съвет на Сдружение</Text>
<Text style={styles.text2}>„Подкрепи БГ“ удостоверява, че:</Text>
<Text style={styles.name}>{name}</Text>
<Text style={styles.text1}>С този сертификат Управителният съвет на</Text>
<Text style={styles.text2}>Сдружение „Подкрепи БГ“ удостоверява, че:</Text>
<Text style={styles.name}>
{donation.person?.firstName} {donation.person?.lastName}
</Text>
</View>
<View>
<View style={{ marginTop: '10' }}>
<Text style={styles.donationText}>
дари сума в размер на{' '}
<Text style={{ color: '#2A4E84' }}>{money(donation?.amount ?? 0)}</Text> за дейността на
сдружението.
<Text style={styles.donationRow}>{money(donation?.amount ?? 0)}</Text>
</Text>
<Text style={styles.donationText}>за кампания:</Text>
<Text style={styles.donationRow}>{donation?.targetVault?.campaign?.title ?? '-'}</Text>
</View>
<View style={styles.dateAndSignView}>
<View>
<Text style={styles.date}>{formattedDate}</Text>
<Text style={styles.date}>{formatDateString(donation.createdAt)}</Text>
<Text style={styles.dateText}>Дата</Text>
</View>
<View style={styles.signs}>
Expand Down
15 changes: 13 additions & 2 deletions src/gql/donations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ export type DonationResponse = {
currency: Currency
amount: number
personId?: UUID
person?: { firsName: string; lastName: string }
targetVault: { name: string }
person?: {
id: string
firstName: string
lastName: string
}
targetVault?: {
id: string
campaign?: {
id: string
slug: string
title: string
}
}
}

export type UserDonationResponse = DonationResponse & {
Expand Down
14 changes: 6 additions & 8 deletions src/pages/api/pdf/certificate/[donationId].tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { renderToStream } from '@react-pdf/renderer'
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
import { getToken } from 'next-auth/jwt'
import { renderToStream } from '@react-pdf/renderer'

import { apiClient } from 'service/apiClient'
import { UserDonationResponse } from 'gql/donations'
import { apiClient } from 'service/apiClient'
import { endpoints } from 'service/apiEndpoints'
import Certificate from 'components/pdf/Certificate'
import { authConfig } from 'service/restRequests'
import { getToken } from 'next-auth/jwt'

import Certificate from 'components/pdf/Certificate'

const Handler: NextApiHandler = async (req: NextApiRequest, res: NextApiResponse) => {
const id = Array.isArray(req.query.donationId) ? req.query.donationId[0] : req.query.donationId
Expand All @@ -17,17 +18,14 @@ const Handler: NextApiHandler = async (req: NextApiRequest, res: NextApiResponse
return
}
const { data: donation } = await apiClient.get<UserDonationResponse>(
// Casting to string here might lead to an error
endpoints.donation.getUserDonation(id).url,
authConfig(jwt?.accessToken),
)

if (!donation) {
res.status(404).json({ notFound: true })
} else {
const pdfStream = await renderToStream(
<Certificate donation={donation} person={donation.person} />,
)
const pdfStream = await renderToStream(<Certificate donation={donation} />)
res.setHeader('Content-Type', 'application/pdf')
pdfStream.pipe(res)
}
Expand Down