@velocitycareerlabs/vc-renderer-sample 1.25.0-dev-build.16fb31afd → 1.25.0-dev-build.19b953994

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velocitycareerlabs/vc-renderer-sample",
3
- "version": "1.25.0-dev-build.16fb31afd",
3
+ "version": "1.25.0-dev-build.19b953994",
4
4
  "description": "VC Renderer Sample",
5
5
  "repository": "https://github.com/velocitycareerlabs/packages",
6
6
  "publishConfig": {
@@ -12,7 +12,7 @@
12
12
  "@emotion/styled": "^11.11.0",
13
13
  "@mui/icons-material": "^6.0.0",
14
14
  "@mui/material": "^6.0.0",
15
- "@react-pdf/renderer": "^4.1.5",
15
+ "@react-pdf/renderer": "^3.0.0",
16
16
  "@testing-library/jest-dom": "^5.17.0",
17
17
  "@testing-library/react": "^13.4.0",
18
18
  "@testing-library/user-event": "^13.5.0",
@@ -20,7 +20,7 @@
20
20
  "@types/node": "^16.18.119",
21
21
  "@types/react": "18.3.4",
22
22
  "@types/react-dom": "18.3.0",
23
- "@velocitycareerlabs/vc-renderer": "1.25.0-dev-build.16fb31afd",
23
+ "@velocitycareerlabs/vc-renderer": "1.25.0-dev-build.19b953994",
24
24
  "react": "18.3.1",
25
25
  "react-dom": "^18.3.1",
26
26
  "react-scripts": "5.0.1",
@@ -58,5 +58,5 @@
58
58
  "last 1 safari version"
59
59
  ]
60
60
  },
61
- "gitHead": "633ac8221e186bfc915b5007ea3253fdede52142"
61
+ "gitHead": "70c50ceb4c67c3800fd4e8d36c08be12a76ba9bd"
62
62
  }
package/src/App.tsx CHANGED
@@ -1,14 +1,13 @@
1
- /* eslint-disable better-mutation/no-mutation */
2
1
  import { useCallback, useState } from 'react';
3
2
  import {
4
3
  VcsSummaryRenderer,
5
4
  VcDetailsRenderer,
6
5
  } from '@velocitycareerlabs/vc-renderer';
7
- import { Typography, Box, Button } from '@mui/material';
8
- import { pdf } from '@react-pdf/renderer';
6
+ import { Typography, Box } from '@mui/material';
9
7
  import { Sidebar } from './components/Sidebar';
10
8
  import { SummaryFooter } from './components/SummaryFooter';
11
9
  import { VcDetailsFooter } from './components/VcDetailsFooter';
10
+ import { PrintPdfButton } from './components/PrintPdfButton';
12
11
  import {
13
12
  PdfCredentialDetailsVcPrepared,
14
13
  PdfCredentialsDetailsVcPrepared,
@@ -43,23 +42,6 @@ const App = () => {
43
42
  });
44
43
  }, []);
45
44
 
46
- const printVc = async (Component: any) => {
47
- const blob = await pdf(Component).toBlob();
48
- const iframe: HTMLIFrameElement = document.createElement('iframe');
49
- document.body.appendChild(iframe);
50
- iframe.style.display = 'none';
51
- iframe.src = URL.createObjectURL(blob);
52
- iframe.onload = () => {
53
- setTimeout(() => {
54
- iframe.focus();
55
- const contectWindow = iframe?.contentWindow;
56
- if (contectWindow) {
57
- contectWindow.print();
58
- }
59
- }, 1);
60
- };
61
- };
62
-
63
45
  return (
64
46
  <div className="App">
65
47
  <Typography variant="h6" pt={8} mb={1}>
@@ -279,64 +261,52 @@ const App = () => {
279
261
  <Typography variant="h6" pt={8}>
280
262
  Printable. Using vcsPrepared
281
263
  </Typography>
282
-
283
- <Button
284
- onClick={() => printVc(<PdfCredentialDetailsVcPrepared />)}
285
- variant="contained"
286
- >
287
- Print Credentail Details
288
- </Button>
289
- <Button
290
- onClick={() => printVc(<PdfCredentialsDetailsVcPrepared />)}
291
- variant="contained"
292
- sx={{ marginLeft: 4 }}
293
- >
294
- Print Multiple Credentils
295
- </Button>
264
+ <Box sx={styles.buttonContainer}>
265
+ <PrintPdfButton
266
+ pdfDocument={<PdfCredentialDetailsVcPrepared />}
267
+ label="Print Credentail Details"
268
+ />
269
+ <PrintPdfButton
270
+ pdfDocument={<PdfCredentialsDetailsVcPrepared />}
271
+ label="Print Multiple Credentils"
272
+ />
273
+ </Box>
296
274
 
297
275
  <Typography variant="h6" pt={8}>
298
276
  Printable. Using Raw Data
299
277
  </Typography>
300
- <Button
301
- onClick={() => printVc(<PdfCredentialDetailsVcRaw />)}
302
- variant="contained"
303
- >
304
- Print Credentail Details
305
- </Button>
306
- <Button
307
- onClick={() => printVc(<PdfCredentialsDetailsVcsRaw />)}
308
- variant="contained"
309
- sx={{ marginLeft: 4 }}
310
- >
311
- Print Multiple Credentails
312
- </Button>
278
+ <Box sx={styles.buttonContainer}>
279
+ <PrintPdfButton
280
+ pdfDocument={<PdfCredentialDetailsVcRaw />}
281
+ label="Print Credentail Details"
282
+ />
283
+ <PrintPdfButton
284
+ pdfDocument={<PdfCredentialsDetailsVcsRaw />}
285
+ label="Print Multiple Credentils"
286
+ />
287
+ </Box>
313
288
 
314
289
  <Typography variant="h6" pt={8}>
315
290
  Printable. Missing Data
316
291
  </Typography>
317
- <Button
318
- onClick={() => printVc(<PdfCredentialDetailsVcPreparedMissingData />)}
319
- variant="contained"
320
- >
321
- Print Credentail wo header data
322
- </Button>
323
- <Button
324
- onClick={() => printVc(<PdfCredentialsDetailsVcPreparedMissingData />)}
325
- variant="contained"
326
- sx={{ marginLeft: 4 }}
327
- >
328
- Print Multiple Credentails wo header data
329
- </Button>
292
+ <Box sx={styles.buttonContainer}>
293
+ <PrintPdfButton
294
+ pdfDocument={<PdfCredentialDetailsVcPreparedMissingData />}
295
+ label="Print Credentail wo header data"
296
+ />
297
+ <PrintPdfButton
298
+ pdfDocument={<PdfCredentialsDetailsVcPreparedMissingData />}
299
+ label="Print Multiple Credentails wo header data"
300
+ />
301
+ </Box>
330
302
 
331
303
  <Typography variant="h6" pt={8}>
332
304
  Printable. Missing Data Raw
333
305
  </Typography>
334
- <Button
335
- onClick={() => printVc(<PdfCredentialsDetailsVcsRawMissingData />)}
336
- variant="contained"
337
- >
338
- Print Credentail missing data
339
- </Button>
306
+ <PrintPdfButton
307
+ pdfDocument={<PdfCredentialsDetailsVcsRawMissingData />}
308
+ label="Print Credentail missing data"
309
+ />
340
310
  </div>
341
311
  );
342
312
  };
@@ -392,4 +362,9 @@ const styles = {
392
362
  height: '100px',
393
363
  },
394
364
  },
365
+ buttonContainer: {
366
+ display: 'flex',
367
+ justifyContent: 'center',
368
+ gap: '10px',
369
+ },
395
370
  };
@@ -96,9 +96,9 @@ export const PdfCredentialDetailsVcRaw = () => {
96
96
  applicantName="John Doe"
97
97
  userName="Jane Doe"
98
98
  appLogo={logo192}
99
- categoriesTitle={{ [CREDENTIALS[0].did]: 'Assessments' }}
100
- vcsStatus={{ [CREDENTIALS[0].did]: 'Verified' as any }}
101
- sidebarItems={{ [CREDENTIALS[0].did]: sidebarItems }}
99
+ categoriesTitle={{ [CREDENTIALS[0].id]: 'Assessments' }}
100
+ vcsStatus={{ [CREDENTIALS[0].id]: 'Verified' as any }}
101
+ sidebarItems={{ [CREDENTIALS[0].id]: sidebarItems }}
102
102
  />
103
103
  </Document>
104
104
  );
@@ -106,25 +106,25 @@ export const PdfCredentialDetailsVcRaw = () => {
106
106
 
107
107
  export const PdfCredentialsDetailsVcsRaw = () => {
108
108
  const categoriesTitle = {
109
- [CREDENTIALS[6].did]: 'Contacts',
110
- [CREDENTIALS[5].did]: 'Contacts',
111
- [CREDENTIALS[4].did]: 'Documents',
112
- [CREDENTIALS[3].did]: 'Employment History',
113
- [CREDENTIALS[2].did]: 'Badges & Achievements',
114
- [CREDENTIALS[1].did]: 'Contacts',
115
- [CREDENTIALS[0].did]: 'Assessments',
109
+ [CREDENTIALS[6].id]: 'Contacts',
110
+ [CREDENTIALS[5].id]: 'Contacts',
111
+ [CREDENTIALS[4].id]: 'Documents',
112
+ [CREDENTIALS[3].id]: 'Employment History',
113
+ [CREDENTIALS[2].id]: 'Badges & Achievements',
114
+ [CREDENTIALS[1].id]: 'Contacts',
115
+ [CREDENTIALS[0].id]: 'Assessments',
116
116
  };
117
117
  const vcsStatus = CREDENTIALS.reduce<{ [key: string]: string }>((acc, vc) => {
118
- const { did } = vc;
119
- acc[did] = 'Verified';
118
+ const { id } = vc;
119
+ acc[id] = 'Verified';
120
120
  return acc;
121
121
  }, {});
122
122
 
123
123
  const sidebarItemsMapped = CREDENTIALS.reduce<{
124
124
  [key: string]: React.ReactNode[];
125
125
  }>((acc, vc) => {
126
- const { did } = vc;
127
- acc[did] = sidebarItems;
126
+ const { id } = vc;
127
+ acc[id] = sidebarItems;
128
128
  return acc;
129
129
  }, {});
130
130
  return (
@@ -203,16 +203,16 @@ export const PdfCredentialsDetailsVcPreparedMissingData = () => {
203
203
 
204
204
  export const PdfCredentialsDetailsVcsRawMissingData = () => {
205
205
  const categoriesTitle = {
206
- [CREDENTIALS[5].did]: 'Contacts',
207
- [CREDENTIALS[4].did]: 'Documents',
208
- [CREDENTIALS[3].did]: 'Employment History',
209
- [CREDENTIALS[2].did]: 'Badges & Achievements',
210
- [CREDENTIALS[1].did]: 'Contacts',
206
+ [CREDENTIALS[5].id]: 'Contacts',
207
+ [CREDENTIALS[4].id]: 'Documents',
208
+ [CREDENTIALS[3].id]: 'Employment History',
209
+ [CREDENTIALS[2].id]: 'Badges & Achievements',
210
+ [CREDENTIALS[1].id]: 'Contacts',
211
211
  };
212
212
  const vcsStatus = [CREDENTIALS[1]].reduce<{ [key: string]: string }>(
213
213
  (acc, vc) => {
214
- const { did } = vc;
215
- acc[did] = 'Verified';
214
+ const { id } = vc;
215
+ acc[id] = 'Verified';
216
216
  return acc;
217
217
  },
218
218
  {}
@@ -221,8 +221,8 @@ export const PdfCredentialsDetailsVcsRawMissingData = () => {
221
221
  const sidebarItemsMapped = [CREDENTIALS[1]].reduce<{
222
222
  [key: string]: React.ReactNode[];
223
223
  }>((acc, vc) => {
224
- const { did } = vc;
225
- acc[did] = sidebarItems;
224
+ const { id } = vc;
225
+ acc[id] = sidebarItems;
226
226
  return acc;
227
227
  }, {});
228
228
 
@@ -0,0 +1,46 @@
1
+ /* eslint-disable better-mutation/no-mutation */
2
+ import React from 'react';
3
+ import { BlobProvider } from '@react-pdf/renderer';
4
+ import { Button } from '@mui/material';
5
+
6
+ type PrintPdfButtonProps = {
7
+ pdfDocument: React.ReactElement;
8
+ label: string;
9
+ };
10
+
11
+ export const PrintPdfButton: React.FC<PrintPdfButtonProps> = ({
12
+ pdfDocument,
13
+ label,
14
+ }) => {
15
+ const handlePrint = React.useCallback((blobUrl: string) => {
16
+ const iframe = document.createElement('iframe');
17
+ iframe.style.display = 'none';
18
+ document.body.appendChild(iframe);
19
+ iframe.src = blobUrl;
20
+ iframe.onload = () => {
21
+ setTimeout(() => {
22
+ iframe.focus();
23
+ const { contentWindow } = iframe;
24
+ if (contentWindow) {
25
+ contentWindow.onafterprint = () => {
26
+ document.body.removeChild(iframe);
27
+ URL.revokeObjectURL(blobUrl);
28
+ };
29
+ contentWindow.print();
30
+ }
31
+ }, 100);
32
+ };
33
+ }, []);
34
+
35
+ return (
36
+ <BlobProvider document={pdfDocument}>
37
+ {({ url }) => {
38
+ return (
39
+ <Button variant="contained" onClick={() => url && handlePrint(url)}>
40
+ {label}
41
+ </Button>
42
+ );
43
+ }}
44
+ </BlobProvider>
45
+ );
46
+ };
@@ -449,7 +449,8 @@ export const CREDENTIALS_MAPPED = [
449
449
  summary: {
450
450
  title: 'Badge',
451
451
  subTitle: 'Open Badge',
452
- summaryDetail: 'Residential Electricity',
452
+ summaryDetail:
453
+ 'Residential Electricity very long two rows summary description',
453
454
  logo: 'https://www.velocitynetwork.foundation/wp-content/uploads/2024/08/Residential-Electricity-Badge.jpg',
454
455
  issuerLogo:
455
456
  'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRAHXPluq6GtTRPDIHRv5kJPy86uFjp5sO7hg&s',