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

pdf/Certificate: Get donor's names from session token #1690

Merged
merged 1 commit into from
Dec 19, 2023
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
13 changes: 7 additions & 6 deletions src/components/client/pdf/Certificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { formatDateString } from 'common/util/date'
import { money } from 'common/util/money'
import theme from 'common/theme'
import { DonationType } from 'gql/donations.enums'
import { ServerUser } from 'service/auth'

Font.register({
family: 'Arial',
Expand Down Expand Up @@ -122,11 +123,12 @@ const styles = StyleSheet.create({

type Props = {
donation: DonationResponse
user: ServerUser | null | undefined
}
export default function Certificate({ donation }: Props) {
const companyName = donation.person?.company
? donation.person.company.companyName
: donation.affiliate.company.companyName
export default function Certificate({ donation, user }: Props) {
const userName = `${user?.given_name} ${user?.family_name}` ?? ''
const companyName = `${user?.company}` ?? ''

return (
<Document title="Дарение">
<Page size="LETTER" style={styles.page}>
Expand All @@ -143,8 +145,7 @@ export default function Certificate({ donation }: Props) {
<Text style={styles.text1}>С този сертификат Управителният съвет на</Text>
<Text style={styles.text2}>Сдружение „Подкрепи БГ“ удостоверява, че:</Text>
<Text style={styles.name}>
{donation.type === DonationType.donation &&
`${donation.person?.firstName} ${donation.person?.lastName}`}
{donation.type === DonationType.donation && userName}
{donation.type === DonationType.corporate && companyName}
</Text>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/pdf/certificate/[donationId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Handler: NextApiHandler = async (req: NextApiRequest, res: NextApiResponse
if (!donation) {
res.status(404).json({ notFound: true })
} else {
const pdfStream = await renderToStream(<Certificate donation={donation} />)
const pdfStream = await renderToStream(<Certificate donation={donation} user={jwt?.user} />)
res.setHeader('Content-Type', 'application/pdf')
pdfStream.pipe(res)
}
Expand Down
1 change: 1 addition & 0 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ServerUser = ParsedToken & {
session_state: string
'allowed-origins': string[]
selfReg?: boolean
company: string
// access
realm_access: { roles: RealmRole[] }
resource_access: { account: { roles: ResourceRole[] } }
Expand Down
Loading