Skip to content

Commit

Permalink
fix(printer/i18n): fix dates not showing up in resume language when p…
Browse files Browse the repository at this point in the history
…rinting

fix #729
  • Loading branch information
AmruthPillai committed Mar 18, 2022
1 parent 5fa45ef commit 90321e1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client/pages/[username]/[slug]/printer.tsx
Expand Up @@ -3,6 +3,7 @@ import clsx from 'clsx';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { GetServerSideProps, NextPage } from 'next';
import { useRouter } from 'next/router';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useEffect } from 'react';

Expand All @@ -20,6 +21,7 @@ type QueryParams = {

type Props = {
resume?: Resume;
locale: string;
redirect?: any;
};

Expand All @@ -35,7 +37,13 @@ export const getServerSideProps: GetServerSideProps<Props | Promise<Props>, Quer
const resume = await fetchResumeByIdentifier({ username, slug, options: { secretKey } });
const displayLocale = resume.metadata.locale || locale || 'en';

return { props: { resume, ...(await serverSideTranslations(displayLocale, ['common'])) } };
return {
props: {
resume,
locale: displayLocale,
...(await serverSideTranslations(displayLocale, ['common'])),
},
};
} catch (error) {
return {
redirect: {
Expand All @@ -46,7 +54,9 @@ export const getServerSideProps: GetServerSideProps<Props | Promise<Props>, Quer
}
};

const Printer: NextPage<Props> = ({ resume: initialData }) => {
const Printer: NextPage<Props> = ({ resume: initialData, locale }) => {
const router = useRouter();

const dispatch = useAppDispatch();

const resume = useAppSelector((state) => state.resume);
Expand All @@ -55,6 +65,12 @@ const Printer: NextPage<Props> = ({ resume: initialData }) => {
if (initialData) dispatch(setResume(initialData));
}, [dispatch, initialData]);

useEffect(() => {
const { pathname, asPath, query } = router;

router.push({ pathname, query }, asPath, { locale });
}, [router, locale]);

if (!resume || isEmpty(resume)) return null;

const layout: string[][][] = get(resume, 'metadata.layout', []);
Expand Down

0 comments on commit 90321e1

Please sign in to comment.