Skip to content

Commit

Permalink
pdf/Certificate: Get donor's names from session token (#1690)
Browse files Browse the repository at this point in the history
Anonymous donations don't have personId to find them by users
  • Loading branch information
sashko9807 authored Dec 19, 2023
1 parent fc639de commit e385e2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
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

0 comments on commit e385e2e

Please sign in to comment.