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

Reports async fixes #340

Merged
merged 2 commits into from
Jan 27, 2025
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
15 changes: 2 additions & 13 deletions frontend-new/src/experiences/report/reportDocx/SkillReportDocx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const SkillReportDocx = async (props: SkillReportDocxProps): Promise<Blob> => {
new Paragraph({
children: [
new TextRun({
text: prettifyText(ReportContent.REPORT_BODY_TEXT(formatDate(conversationConductedAt!))),
text: prettifyText(ReportContent.REPORT_BODY_TEXT(formatDate(conversationConductedAt))),
size: 22,
}),
],
Expand Down Expand Up @@ -220,18 +220,7 @@ const SkillReportDocx = async (props: SkillReportDocxProps): Promise<Blob> => {
},
],
});

return new Promise((resolve, reject) => {
Packer.toBlob(doc).then(
(blob) => {
resolve(blob);
},
(error) => {
console.log(error);
reject(error);
}
);
});
return Packer.toBlob(doc);
};

export default SkillReportDocx;
24 changes: 14 additions & 10 deletions frontend-new/src/experiences/report/reportDocx/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { saveAs } from "src/experiences/saveAs";

export class DocxReportDownloadProvider implements IReportFormatProvider {
async download(props: ReportProps) {
const fileName = "compass-skills-report.docx";
const blob = await SkillReportDocx({
name: props.name,
email: props.email,
phone: props.phone,
address: props.address,
experiences: props.experiences,
conversationConductedAt: props.conversationConductedAt,
});
saveAs(blob, fileName);
try {
const fileName = "compass-skills-report.docx";
const blob = await SkillReportDocx({
name: props.name,
email: props.email,
phone: props.phone,
address: props.address,
experiences: props.experiences,
conversationConductedAt: props.conversationConductedAt,
});
saveAs(blob, fileName);
} catch (error) {
console.error("Failed to download report", error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const SkillReportPDF: React.FC<SkillReportProps> = ({
{renderPersonalInfo(email, ReportContent.IMAGE_URLS.EMAIL_ICON, DATA_TEST_ID.SKILL_REPORT_EMAIL)}
</View>
<Text x={0} y={0} style={styles.bodyText} data-testid={DATA_TEST_ID.SKILL_REPORT_BODY_TEXT}>
{prettifyText(ReportContent.REPORT_BODY_TEXT(formatDate(conversationConductedAt!)))}
{prettifyText(ReportContent.REPORT_BODY_TEXT(formatDate(conversationConductedAt)))}
</Text>
<View style={styles.divider} />
<Text x={0} y={0} style={styles.experiencesTitle} data-testid={DATA_TEST_ID.SKILL_REPORT_EXPERIENCES_TITLE}>
Expand Down
30 changes: 18 additions & 12 deletions frontend-new/src/experiences/report/reportPdf/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { saveAs } from "src/experiences/saveAs";

export class PDFReportDownloadProvider implements IReportFormatProvider {
async download(props: ReportProps) {
const fileName = "compass-skills-report.pdf";
const blob = await pdf(
<SkillReportPDF
name={props.name}
email={props.email}
phone={props.phone}
address={props.address}
experiences={props.experiences}
conversationConductedAt={props.conversationConductedAt}
/>
).toBlob();
saveAs(blob, fileName);
try {
const fileName = "compass-skills-report.pdf";
const report = pdf(
<SkillReportPDF
name={props.name}
email={props.email}
phone={props.phone}
address={props.address}
experiences={props.experiences}
conversationConductedAt={props.conversationConductedAt}
/>,
);
// noinspection JSVoidFunctionReturnValueUsed Intellij is wrong here, this is a promise
const blob = await report.toBlob();
saveAs(blob, fileName);
} catch (error) {
console.error("Failed to download report", error);
}
}
}
10 changes: 5 additions & 5 deletions frontend-new/src/experiences/report/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ export const getUniqueSkills = (experiences: Experience[]): Skill[] => {
return skillOnly.sort((a, b) => a.preferredLabel.localeCompare(b.preferredLabel));
};

export const formatDate = (dateString: string): string => {
const date = new Date(dateString);
export const formatDate = (dateString: string | null): string => {
const date = dateString ? new Date(dateString) : new Date();
const options: Intl.DateTimeFormatOptions = { month: "long", day: "2-digit", year: "numeric" };
return date.toLocaleDateString("en-US", options);
};

// Utility function to group experiences by work type
export const groupExperiencesByWorkType = (experiences: Experience[]) => {
const selfEmploymentExperiences = experiences.filter(
(experience) => experience.work_type === WorkType.SELF_EMPLOYMENT
(experience) => experience.work_type === WorkType.SELF_EMPLOYMENT,
);

const salaryWorkExperiences = experiences.filter(
(experience) => experience.work_type === WorkType.FORMAL_SECTOR_WAGED_EMPLOYMENT
(experience) => experience.work_type === WorkType.FORMAL_SECTOR_WAGED_EMPLOYMENT,
);

const unpaidWorkExperiences = experiences.filter((experience) => experience.work_type === WorkType.UNSEEN_UNPAID);

const traineeWorkExperiences = experiences.filter(
(experience) => experience.work_type === WorkType.FORMAL_SECTOR_UNPAID_TRAINEE_WORK
(experience) => experience.work_type === WorkType.FORMAL_SECTOR_UNPAID_TRAINEE_WORK,
);

return { selfEmploymentExperiences, salaryWorkExperiences, unpaidWorkExperiences, traineeWorkExperiences };
Expand Down
Loading