fix language difference when printing resume

This commit is contained in:
Amruth Pillai
2022-09-15 19:49:57 +02:00
parent 2faa15db5a
commit ec27e5e6ab
12 changed files with 1077 additions and 1129 deletions

View File

@ -70,7 +70,7 @@ const ArtboardController: React.FC<ReactZoomPanPinchRef> = ({ zoomIn, zoomOut, c
const url = await mutateAsync({ username, slug }); const url = await mutateAsync({ username, slug });
download(`/api${url}`); download(url);
}; };
return ( return (

View File

@ -48,7 +48,7 @@ const Export = () => {
const url = await mutateAsync({ username, slug }); const url = await mutateAsync({ username, slug });
download(`/api${url}`); download(url);
}; };
return ( return (

View File

@ -11,17 +11,17 @@
"@beam-australia/react-env": "^3.1.1", "@beam-australia/react-env": "^3.1.1",
"@date-io/dayjs": "^2.15.0", "@date-io/dayjs": "^2.15.0",
"@emotion/css": "^11.10.0", "@emotion/css": "^11.10.0",
"@emotion/react": "^11.10.0", "@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.0", "@emotion/styled": "^11.10.4",
"@hello-pangea/dnd": "^16.0.0", "@hello-pangea/dnd": "^16.0.0",
"@hookform/resolvers": "2.9.7", "@hookform/resolvers": "2.9.8",
"@monaco-editor/react": "^4.4.5", "@monaco-editor/react": "^4.4.5",
"@mui/icons-material": "^5.10.3", "@mui/icons-material": "^5.10.3",
"@mui/lab": "^5.0.0-alpha.97", "@mui/lab": "^5.0.0-alpha.99",
"@mui/material": "^5.10.3", "@mui/material": "^5.10.5",
"@mui/system": "^5.10.3", "@mui/system": "^5.10.5",
"@mui/x-date-pickers": "5.0.0-beta.7", "@mui/x-date-pickers": "5.0.1",
"@next/env": "^12.2.5", "@next/env": "^12.3.0",
"@react-oauth/google": "^0.2.6", "@react-oauth/google": "^0.2.6",
"@reduxjs/toolkit": "^1.8.5", "@reduxjs/toolkit": "^1.8.5",
"axios": "^0.27.2", "axios": "^0.27.2",
@ -33,15 +33,15 @@
"md5-hex": "^4.0.0", "md5-hex": "^4.0.0",
"monaco-editor": "^0.34.0", "monaco-editor": "^0.34.0",
"nanoid": "^3.3.4", "nanoid": "^3.3.4",
"next": "12.2.5", "next": "12.3.0",
"next-i18next": "^12.0.0", "next-i18next": "^12.0.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-colorful": "^5.6.1", "react-colorful": "^5.6.1",
"react-dnd": "16.0.1", "react-dnd": "16.0.1",
"react-dnd-html5-backend": "16.0.1", "react-dnd-html5-backend": "16.0.1",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-hook-form": "^7.34.2", "react-hook-form": "^7.35.0",
"react-hot-toast": "2.3.0", "react-hot-toast": "2.4.0",
"react-hotkeys-hook": "^3.4.7", "react-hotkeys-hook": "^3.4.7",
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"react-markdown": "^8.0.3", "react-markdown": "^8.0.3",
@ -53,32 +53,32 @@
"redux-saga": "^1.2.1", "redux-saga": "^1.2.1",
"redux-undo": "^1.0.1", "redux-undo": "^1.0.1",
"remark-gfm": "^3.0.1", "remark-gfm": "^3.0.1",
"sharp": "^0.30.7", "sharp": "^0.31.0",
"uuid": "^8.3.2", "uuid": "^9.0.0",
"webfontloader": "^1.6.28" "webfontloader": "^1.6.28"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.18.13", "@babel/core": "^7.19.1",
"@reactive-resume/schema": "workspace:*", "@reactive-resume/schema": "workspace:*",
"eslint-plugin-unused-imports": "^2.0.0", "eslint-plugin-unused-imports": "^2.0.0",
"@tailwindcss/typography": "^0.5.4", "@tailwindcss/typography": "^0.5.7",
"@types/downloadjs": "^1.4.3", "@types/downloadjs": "^1.4.3",
"@types/lodash": "^4.14.184", "@types/lodash": "^4.14.185",
"@types/node": "^18.7.13", "@types/node": "^18.7.18",
"@types/react": "^18.0.17", "@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/react-redux": "^7.1.24", "@types/react-redux": "^7.1.24",
"@types/tailwindcss": "^3.0.11", "@types/tailwindcss": "^3.0.11",
"@types/uuid": "^8.3.4", "@types/uuid": "^8.3.4",
"@types/webfontloader": "^1.6.34", "@types/webfontloader": "^1.6.34",
"autoprefixer": "^10.4.8", "autoprefixer": "^10.4.11",
"csstype": "^3.1.0", "csstype": "^3.1.1",
"eslint-config-next": "^12.2.5", "eslint-config-next": "^12.3.0",
"eslint-plugin-tailwindcss": "^3.6.0", "eslint-plugin-tailwindcss": "^3.6.1",
"next-sitemap": "^3.1.21", "next-sitemap": "^3.1.22",
"postcss": "^8.4.16", "postcss": "^8.4.16",
"sass": "^1.54.5", "sass": "^1.54.9",
"tailwindcss": "^3.1.8", "tailwindcss": "^3.1.8",
"typescript": "^4.8.2" "typescript": "^4.8.3"
} }
} }

View File

@ -98,7 +98,7 @@ const Preview: NextPage<Props> = ({ username, slug, resume: initialData }) => {
try { try {
const url = await mutateAsync({ username, slug }); const url = await mutateAsync({ username, slug });
download(`/api${url}`); download(url);
} catch { } catch {
toast.error('Something went wrong, please try again later.'); toast.error('Something went wrong, please try again later.');
} }

View File

@ -3,6 +3,7 @@ import clsx from 'clsx';
import get from 'lodash/get'; import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import { GetServerSideProps, NextPage } from 'next'; import { GetServerSideProps, NextPage } from 'next';
import { useRouter } from 'next/router';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useEffect } from 'react'; import { useEffect } from 'react';
@ -54,10 +55,20 @@ export const getServerSideProps: GetServerSideProps<Props | Promise<Props>, Quer
}; };
const Printer: NextPage<Props> = ({ resume: initialData, locale }) => { const Printer: NextPage<Props> = ({ resume: initialData, locale }) => {
const router = useRouter();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const resume = useAppSelector((state) => state.resume.present); const resume = useAppSelector((state) => state.resume.present);
useEffect(() => {
if (router.locale !== locale) {
const { pathname, asPath, query } = router;
router.push({ pathname, query }, asPath, { locale });
}
}, [router, locale]);
useEffect(() => { useEffect(() => {
if (initialData) dispatch(setResume(initialData)); if (initialData) dispatch(setResume(initialData));
}, [dispatch, initialData]); }, [dispatch, initialData]);

View File

@ -71,7 +71,7 @@ const Preview: NextPage<Props> = ({ shortId }) => {
try { try {
const url = await mutateAsync({ username: resume.user.username, slug: resume.slug }); const url = await mutateAsync({ username: resume.user.username, slug: resume.slug });
download(`/api${url}`); download(url);
} catch { } catch {
toast.error('Something went wrong, please try again later.'); toast.error('Something went wrong, please try again later.');
} }

View File

@ -28,9 +28,9 @@ export const formatDateString = (date: string | DateRange, formatStr: string): s
// If `date` is a string // If `date` is a string
if (isString(date)) { if (isString(date)) {
if (!dayjs(date).utc().utc().isValid()) return null; if (!dayjs(date).isValid()) return null;
return dayjs(date).utc().format(formatStr); return dayjs(date).utc(true).format(formatStr);
} }
// If `date` is a DateRange // If `date` is a DateRange
@ -39,8 +39,8 @@ export const formatDateString = (date: string | DateRange, formatStr: string): s
if (!dayjs(date.start).isValid()) return null; if (!dayjs(date.start).isValid()) return null;
if (!isEmpty(date.end) && dayjs(date.end).isValid()) { if (!isEmpty(date.end) && dayjs(date.end).isValid()) {
return `${dayjs(date.start).format(formatStr)} - ${dayjs(date.end).format(formatStr)}`; return `${dayjs(date.start).utc(true).format(formatStr)} - ${dayjs(date.end).utc(true).format(formatStr)}`;
} }
return `${dayjs(date.start).format(formatStr)} - ${presentString}`; return `${dayjs(date.start).utc(true).format(formatStr)} - ${presentString}`;
}; };

View File

@ -17,17 +17,17 @@
], ],
"dependencies": { "dependencies": {
"env-cmd": "^10.1.0", "env-cmd": "^10.1.0",
"turbo": "^1.4.3" "turbo": "^1.4.6"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.35.1", "@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.35.1", "@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.0", "eslint": "^8.23.1",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-simple-import-sort": "^8.0.0",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"standard-version": "^9.5.0", "standard-version": "^9.5.0",
"typescript": "^4.8.2" "typescript": "^4.8.3"
}, },
"resolutions": { "resolutions": {
"@types/react": "17.0.2", "@types/react": "17.0.2",

2084
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
"build": "tsc" "build": "tsc"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.23.0", "eslint": "^8.23.1",
"typescript": "^4.8.2" "typescript": "^4.8.3"
} }
} }

View File

@ -8,7 +8,7 @@
"start": "node dist/main" "start": "node dist/main"
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.159.0", "@aws-sdk/client-s3": "^3.171.0",
"@nestjs/axios": "^0.1.0", "@nestjs/axios": "^0.1.0",
"@nestjs/common": "^9.0.11", "@nestjs/common": "^9.0.11",
"@nestjs/config": "^2.2.0", "@nestjs/config": "^2.2.0",
@ -21,7 +21,7 @@
"@nestjs/serve-static": "^3.0.0", "@nestjs/serve-static": "^3.0.0",
"@nestjs/terminus": "^9.1.1", "@nestjs/terminus": "^9.1.1",
"@nestjs/typeorm": "^9.0.1", "@nestjs/typeorm": "^9.0.1",
"@types/passport": "^1.0.10", "@types/passport": "^1.0.11",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"cache-manager": "^4.1.0", "cache-manager": "^4.1.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
@ -29,7 +29,7 @@
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"csvtojson": "^2.0.10", "csvtojson": "^2.0.10",
"dayjs": "^1.11.5", "dayjs": "^1.11.5",
"google-auth-library": "^8.4.0", "google-auth-library": "^8.5.1",
"joi": "^17.6.0", "joi": "^17.6.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"multer": "^1.4.4", "multer": "^1.4.4",
@ -41,24 +41,24 @@
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"pg": "^8.8.0", "pg": "^8.8.0",
"playwright-chromium": "^1.25.1", "playwright-chromium": "^1.25.2",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.5.6", "rxjs": "^7.5.6",
"typeorm": "0.3.9", "typeorm": "0.3.9",
"uuid": "^8.3.2" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^9.1.1", "@nestjs/cli": "^9.1.3",
"@nestjs/schematics": "^9.0.1", "@nestjs/schematics": "^9.0.3",
"@reactive-resume/schema": "workspace:*", "@reactive-resume/schema": "workspace:*",
"@types/bcryptjs": "^2.4.2", "@types/bcryptjs": "^2.4.2",
"@types/cookie-parser": "^1.4.3", "@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.13", "@types/express": "^4.17.14",
"@types/lodash": "^4.14.184", "@types/lodash": "^4.14.185",
"@types/multer": "^1.4.7", "@types/multer": "^1.4.7",
"@types/node": "^18.7.13", "@types/node": "^18.7.18",
"@types/nodemailer": "^6.4.5", "@types/nodemailer": "^6.4.6",
"@types/passport-jwt": "^3.0.6", "@types/passport-jwt": "^3.0.6",
"@types/passport-local": "^1.0.34", "@types/passport-local": "^1.0.34",
"prettier": "^2.7.1", "prettier": "^2.7.1",
@ -66,7 +66,7 @@
"ts-loader": "^9.3.1", "ts-loader": "^9.3.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0", "tsconfig-paths": "^4.1.0",
"typescript": "^4.8.2", "typescript": "^4.8.3",
"webpack": "^5.74.0" "webpack": "^5.74.0"
} }
} }

View File

@ -27,6 +27,7 @@ export class PrinterService implements OnModuleInit, OnModuleDestroy {
async printAsPdf(username: string, slug: string): Promise<string> { async printAsPdf(username: string, slug: string): Promise<string> {
const url = this.configService.get<string>('app.url'); const url = this.configService.get<string>('app.url');
const serverUrl = this.configService.get<string>('app.serverUrl');
const secretKey = this.configService.get<string>('app.secretKey'); const secretKey = this.configService.get<string>('app.secretKey');
const page = await this.browser.newPage(); const page = await this.browser.newPage();
@ -45,7 +46,7 @@ export class PrinterService implements OnModuleInit, OnModuleDestroy {
const pdf = await PDFDocument.create(); const pdf = await PDFDocument.create();
const directory = join(__dirname, '..', 'assets/exports'); const directory = join(__dirname, '..', 'assets/exports');
const filename = `RxResume_PDFExport_${nanoid()}.pdf`; const filename = `RxResume_PDFExport_${nanoid()}.pdf`;
const publicUrl = `/assets/exports/${filename}`; const publicUrl = `${serverUrl}/assets/exports/${filename}`;
for (let index = 0; index < resumePages.length; index++) { for (let index = 0; index < resumePages.length; index++) {
await page.evaluate((page) => (document.body.innerHTML = page.innerHTML), resumePages[index]); await page.evaluate((page) => (document.body.innerHTML = page.innerHTML), resumePages[index]);