PDF Report titles are now dynamic
This commit is contained in:
@@ -29,9 +29,11 @@ interface Props {
|
|||||||
logo: string;
|
logo: string;
|
||||||
qrcode: string;
|
qrcode: string;
|
||||||
renderDetails: React.ReactNode;
|
renderDetails: React.ReactNode;
|
||||||
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PDFReport = ({
|
const PDFReport = ({
|
||||||
|
title,
|
||||||
date,
|
date,
|
||||||
name,
|
name,
|
||||||
email,
|
email,
|
||||||
@@ -68,7 +70,7 @@ const PDFReport = ({
|
|||||||
{ fontSize: 14 },
|
{ fontSize: 14 },
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
English Skills Test Result Report
|
{title}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.textPadding}>
|
<View style={styles.textPadding}>
|
||||||
|
|||||||
@@ -303,12 +303,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
);
|
);
|
||||||
const overallResult = overallScore / overallTotal;
|
const overallResult = overallScore / overallTotal;
|
||||||
|
|
||||||
// generate the performance summary based on the overall result
|
|
||||||
const performanceSummary = getPerformanceSummary(
|
|
||||||
"level",
|
|
||||||
overallResult
|
|
||||||
);
|
|
||||||
|
|
||||||
// generate the overall detail report
|
// generate the overall detail report
|
||||||
const overallDetail = {
|
const overallDetail = {
|
||||||
module: "Overall",
|
module: "Overall",
|
||||||
@@ -319,16 +313,32 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const testDetails = [overallDetail, ...finalResults];
|
const testDetails = [overallDetail, ...finalResults];
|
||||||
|
|
||||||
const [stat] = stats;
|
const [stat] = stats;
|
||||||
|
|
||||||
|
// generate the performance summary based on the overall result
|
||||||
|
const performanceSummary = getPerformanceSummary(
|
||||||
|
stat.module,
|
||||||
|
overallResult
|
||||||
|
);
|
||||||
|
|
||||||
// level exams have a different report structure than the skill exams
|
// level exams have a different report structure than the skill exams
|
||||||
const renderDetails = () => {
|
const getCustomData = () => {
|
||||||
if (stat.module === "level") {
|
if (stat.module === "level") {
|
||||||
return <LevelExamDetails detail={overallDetail} />;
|
return {
|
||||||
|
title: "ENGLISH LEVEL TEST RESULT REPORT ",
|
||||||
|
details: <LevelExamDetails detail={overallDetail} />,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return <SkillExamDetails testDetails={testDetails} />;
|
return {
|
||||||
|
title: "ENGLISH SKILLS TEST RESULT REPORT",
|
||||||
|
details: <SkillExamDetails testDetails={testDetails} />,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { title, details } = getCustomData();
|
||||||
const pdfStream = await ReactPDF.renderToStream(
|
const pdfStream = await ReactPDF.renderToStream(
|
||||||
<PDFReport
|
<PDFReport
|
||||||
|
title={title}
|
||||||
date={new Date(stat.date).toLocaleString()}
|
date={new Date(stat.date).toLocaleString()}
|
||||||
name={user.name}
|
name={user.name}
|
||||||
email={user.email}
|
email={user.email}
|
||||||
@@ -336,7 +346,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
gender={user.demographicInformation?.gender}
|
gender={user.demographicInformation?.gender}
|
||||||
summary={performanceSummary}
|
summary={performanceSummary}
|
||||||
testDetails={testDetails}
|
testDetails={testDetails}
|
||||||
renderDetails={renderDetails()}
|
renderDetails={details}
|
||||||
logo={"public/logo_title.png"}
|
logo={"public/logo_title.png"}
|
||||||
qrcode={qrcode}
|
qrcode={qrcode}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user