Skip to content

Commit

Permalink
Karina/wmdp 184 enfore required (#92)
Browse files Browse the repository at this point in the history
* add ts check to all js files

* add dev note regarding incremental type checking

* add TS-specific eslint

* update read me with development typecheck and linting tips

* update read me with development typecheck and linting tips

* add and setup prettier

* WMDP-26 Set Up PR Template (#2)

Changes
added a .github folder which should store all github related processes (e.g. github actions, and templates)
added PR template
Context for reviewers
We want to establish a consistent pull request template that we’ll use.

* Update app/.babelrc

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/package.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* add eslintrc.js

* add stories dir and examples

* .eslint.js: prettier updates to eslint file

* add storybook dependencies

* Fix pull request template conflict (#8)

- Fixed the filename case conflict between `.github/PULL_REQUEST_TEMPLATE.md` and `.github/pull_request_template.md`
- Updated the pull request template to be slightly more generic

* Karina/wmdp 61 initial nextjs setup (#4)

* yarn create next-app --typescript

* clean up auto-generated pages, public and styles

* next.config.js: setup i18n locale for internationalization

* next.config.js: add code comment re: internationalization

* add html tags for VO

* Update app/styles/Home.module.css

update stickcy nav

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* tsconfig: target es6

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* add testRegex and testPathIgnorePatterns

* setup jest-axe

* add new lines add end of files

* Karina/wmdp 35 setup test suite (#5)

* yarn create next-app --typescript

* clean up auto-generated pages, public and styles

* next.config.js: setup i18n locale for internationalization

* next.config.js: add code comment re: internationalization

* add html tags for VO

* Update app/styles/Home.module.css

update stickcy nav

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* tsconfig: target es6

* add babelec

* add __mocks__ with mock styles for testing

* -test: add first jest test and snapshot test for Home page
- add jest.setup.js to require jest-dom

* - add jest.config.js
- package.json: add react testing library, babel and jest dependencies
- add first test
- update jsx
- yarn.lock updated with new packages

* Update app/.babelrc

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/package.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* add testRegex and testPathIgnorePatterns

* setup jest-axe

* add new lines add end of files

* jest.config.js: add inline comments

* README: add tsconfig documentation

* README: add test script documentation

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Karina/wmdp 33 linter typechecker (#6)

* yarn create next-app --typescript

* clean up auto-generated pages, public and styles

* next.config.js: setup i18n locale for internationalization

* next.config.js: add code comment re: internationalization

* add html tags for VO

* Update app/styles/Home.module.css

update stickcy nav

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* tsconfig: target es6

* add babelec

* add __mocks__ with mock styles for testing

* -test: add first jest test and snapshot test for Home page
- add jest.setup.js to require jest-dom

* - add jest.config.js
- package.json: add react testing library, babel and jest dependencies
- add first test
- update jsx
- yarn.lock updated with new packages

* .eslintrc.json: extend nava eslint config

* package.json: add eslint-config-nava

* add ts check to all js files

* add dev note regarding incremental type checking

* add TS-specific eslint

* update read me with development typecheck and linting tips

* update read me with development typecheck and linting tips

* add and setup prettier

* Update app/.babelrc

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/package.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update package.json

add scripts to package.json

* run prettier

* add checkJs to tsconfig, remove duplicate code from js files

* add typescript parser and implement type information with linting

* eslintrc: add prettier recommended plugin

* preettierrc: add trailing comma check, remove redundant code

* README: add auto-generated modified note

* Update app/README.md

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* add testRegex and testPathIgnorePatterns

* re-add localesubpaths to next.config.js

* tsconfig.json: remove inline comment

* README: add docimentation for eslint and tsconfig

* setup jest-axe

* add new lines add end of files

* jest.config.js: add inline comments

* README - add documentation for test

* README: add tsconfig documentation

* README: add test script documentation

* README: add documentation for dependencies

* yarn.lock

* Update app/__mocks__/styleMock.js

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* fix eslint errors

* WIP

* Create a separate tsconfig file to specify jsx mode for ts-jest vs next.js (#9)

Create a separate tsconfig file to specify jsx mode.

Next.js requires the typescript jsx mode to be `preserve`, but ts-jest
needs it to be a flavor of `react`. See:

- https://www.typescriptlang.org/docs/handbook/jsx.html
- https://kulshekhar.github.io/ts-jest/docs/getting-started/options/tsconfig
- kulshekhar/ts-jest#63 (comment)
- vercel/next.js#19155 (reply in thread)

* add home page story and uswds dependency

* update dependencies

* add uswds

* support sass in storybook

* fix eslint errors (#10)

* fix eslint errors

* update prettier and linting rules so that they're compatible

* add new eslint rule to README

* WIP - debugging uswds storybook with Rocket

* add storybook static to git ignore

* Remove storybook-static.

* Dockerize the application.

* Create LICENSE.md using Apache 2.0 (#13)

* Dockerize the application (#12)

* WIP.

* Both next.js and storybook working.

* USWDS 3.x instructions require uswds-compile. Can't use next.js or storybook sass without more unknown glue.

* Clean up unnecessary WIP stuff.

* Refactor to use same naming convention for all uswds assets. Add comments.

* Update dockerization to better support local development.

* Remove extraneous yarn command.

* Run formatter.

* Write some brief documentation.

* Fix typo.

* setup CI for NextJS template app (#16)

* Let prettier format project files.

* Run prettier via yarn format.

* Let prettier format project files (#17)

* yarn: add next.intl

* add messages directory with english and spanish json messages pages

* .storybook/preview: set up next-intl with storybook

* next.config: update next local config for itnernationalization

* app.tsx: add next-intl local/messages provider for internationalization

* tests: add nextintlprovider to jest tests, update snapshots

* update gulp

* create src directories -- move src folders

* add tests and stories for Layout and Index

* add scss loading for storybook

* run linter and prettier

* run prettier

* run prettier and lint

* update yarn.lock

* add prettier alphabetize imports -- add storybook-static to prettier ignore

* show compile warnigns

* remove space

* add container background

* WIP: successfully leveraging built-in nextjs sass compiling.

* Working storybook + nextjs + sass + uswds build.

- Drops support for [CSS
  modules](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css)
- Drops requirement for Gulp and USWDS compile
- Requires postcss and postcss-loader, which storybook says should be
  deprecated

* wip

* delete deprecated flies, add yarn.lock

* add welcome and eligibility page

* update ci.yml (#19)

* Run prettier.

* Update packages.

* Simplify docker. Update README. Use postinstalll script.

* Fix postinstall command.

* Tell prettier to ignore USWDS static assets.

* Disable nextjs telemetry.

* refactor

* jest

* test wip

* Add -p flag to creating public dir so mkdir doesn't error.

* Change comment style so we don't get unnecessary indents.

* Refactor which files storybook recognizes as stories.

* Use storybook lazy compilation.

* Remove no longer needed gulpfile.

* Unpin package versions; use at least instead.

* Remove no longer needed css import.

* add stories

* run prettier, no trailing comma

* correct linting errors

* Remove storybook lazy compilation. Not working.

* Remove non-essential storybook dependencies.

* Don't bind mount node_modules.

* delete depracated code

* host fonts locally for easier sb and jest setup and wider browser support

* support tsconfig module imports in jest and sb

* Switch base image to alpine.

* Run yarn format.

* Update README about node_modules in docker.

* setup next-i18next in project, jest, and sb -- todo: get sb globe to render

* Run formatter.

* Streamline docker build even more.

* Remove no longer installed storybook addons.

* Remove storybook-addon-i18next.

* Run formatter.

* Try storybook-i18n addon. Not quite right.

* Match eslint rule for space before parens to rule as described in README.

* Match prettier and eslint for trailing commas.

* Use the storybook-react-i18next addon for internationalization in storybook.

* Remove wip test of fs package.

* Restore homepage to previous state.

* Document i18n config.

* add storybook-static to git ignore

* add import order to prettier

* add src/ - move pages to src

* app- update import

* public: update translations

* _app.tsx: add Layout to app

* add components dir and Layout component

* index: update deprecated index layout

* update template styles

* update index story

* apply title class to template title

* update tests and stories

* run prettier - add prettier-plugin-sort-imports

* run eslint - add JSX global to linter

* fix translation

* yarn format and delete dead code

* run lint

* Copy over application-template-nextjs at ca2cc15.

Install and configure storybook, sass, and USWDS 3.0 [#15](navapbc/template-application-nextjs#15)

- Install and configure storybook
- Create the first story
- Install and configure [USWDS 3.0](https://designsystem.digital.gov/) as the design system
- Modify `Dockerfile` and `docker-compose.yml` to support USWDS and storybook
- Gitignore storybook, uswds assets, and compiled css
- Prettier ignore uswds assets
- Use postinstall hook to copy uswds static assets
- Stop using CSS modules
- Update some package dependencies
- Switch Docker base image to use alpine for increased speed

* Copy over application-template-nextjs at cd06ba6.

Setup i18n for next.js, jest, and storybook [#24](navapbc/template-application-nextjs#24)

- Install and configure [next-i18next](https://github.com/i18next/next-i18next) for Next.js internationalization
- Move next.js i18n config out of `next.config.js` and into `next-i18next.config.js`
- Modify `pages/_app.tsx` and `pages/index.tsx` to support i18n
- Move jest i18n config into `/tests/jest-i18n.ts`
- Install and configure [storybook-react-i18next](https://storybook.js.org/addons/storybook-react-i18next) for storybook internationalization
- Add support for `<em>` tags in react-i18next in both next.js and storybook.

Extras:
- Remove `space-before-function-paren` eslint rule
- Update eslint to follow prettier's rules
- Rename `test` dir to `tests` (plural)

* Copy over application-template-nextjs at cfe7c3d.

Adds a src dir, layout component, alphabetizes imports [#26](navapbc/template-application-nextjs#26)

- adds `src/` directory for project's webpack compilable JS and JSON files (this update is supported out of the box by [NextJS](https://nextjs.org/docs/advanced-features/src-directory) and pfml also uses this folder structure)
   - moves `api/`, `pages/` and `messages/` directories to `src/`
   - creates `components` directory and adds template `Layout` component

Extras:
- sets up prettier alphabetize imports
- adds storybook-static to prettier ignore
- sets $theme-show-compile-warnings to true for uswds

* Copy over application-template-nextjs at 0a349fa.

Enable dependabot version updates and codeql security scanning as CI jobs [#29](navapbc/template-application-nextjs#29)

- Enable and configure [dependabot version updates](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates)
- Enable and configure [codeql security scanning](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning)

Note: These features were already enabled in this repo, so this commit
is just bringing in stylistic updates to make the two repos identical.

* en/common.json: add contact questions

* add contact page

* remove dead code

* contact: add contact page basic styling and copy

* create TextInput component -- add tests and storybook for contact page and textinput component

* Copy over application-template-nextjs at f59d2ac.

 Add layout styles missing from PR #26.
[#37](navapbc/template-application-nextjs#37)

* fix tests

* update tests

* wip

* fix tests

* run lint and format

* address rocket's comments

* update yarn.lock

* update eslint.json

* update eslintrc

* update textinput types for build

* run prettier

* add number-format

* fix bug

* en: update copy for header and index page

* Layout: update header to match new design

* remove depracated font imports

* pages: add clinic page, update contact page to route to clinic page

* add clinic.json to public directory

* add search.svg: magnifying glass for uswds search button

* tsconfig: add public module import

* update keys

* wip

* public: add clinic page copy

* ButtonLink: add disabled prop

* pages: handle clinic selection and disable button if clinic isn't selected

* unselect if research is reset

* add income page

* add jest tests

* add stories

* update income table styling

* Update app/jest.config.js

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/package.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/public/locales/en/common.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/public/locales/en/common.json

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* Update app/src/components/Dropdown.tsx

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* update tests

* add accordion storybook test

* add jest tests for conditional alternate page routing from eligibility page

* add alternate jest test

* update styles

* add review page

* run prettier and lint

* update tests

* Update app/src/pages/clinic.tsx

Co-authored-by: Tomas Apodaca <thomas.apodaca@gsa.gov>

* Update app/src/pages/clinic.tsx

Co-authored-by: Tomas Apodaca <thomas.apodaca@gsa.gov>

* add numberOfClinicsToReturn

* add numberOfClinicsToReturn

* add Table component and summary page

* wip

* wip

* wip

* wip

* wip

* add localStorage hook to persist data across refresh - add conditional continue button to contact page

* eligibility: add conditional review routing

* wip

* clinic: address type bug

* add Alert story

* add summary and review story

* dangerouslyset inner html of alert

* update tests

* prepoluate selected clinic from review page

* Eligibility: add 'have you had WIC before' question and radio

* Overview tables: add before qiestion and answers to review and summary

* fix broken eligibility test

* address type issue

* format

* add minimum phone length

* remove dead code

* remove dead code

* contact: remove dead width code

* Karina/wmdp 182 restrict user flow (#101)

* remove dead code

* contact: getServersideProps- WIP rerouting

* contact, clinic, income and review: restrict user access to these pages based off of previousRoute

* contact, clinic, income and review: restrict user access to these pages based off of previousRoute

* remove dead code

* address getserversideprops type error

* yarn format

* update snaps

* Update app/src/pages/clinic.tsx

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

* yarn format

Co-authored-by: Rocket <rocketnova@users.noreply.github.com>

Co-authored-by: Alsia Plybeah <alsia@navapbc.com>
Co-authored-by: Rocket <rocketnova@users.noreply.github.com>
Co-authored-by: Shawn VanderJagt <91338100+shawnvanderjagt@users.noreply.github.com>
Co-authored-by: Tomas Apodaca <thomas.apodaca@gsa.gov>
  • Loading branch information
5 people committed Sep 27, 2022
1 parent 7f3d4d8 commit 3d93a03
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 36 deletions.
3 changes: 2 additions & 1 deletion app/src/components/Alert.tsx
@@ -1,3 +1,4 @@
import { Trans } from 'next-i18next'
import { ReactElement } from 'react'

type Props = {
Expand All @@ -14,7 +15,7 @@ const Alert = (props: Props): ReactElement => {
role="alert"
>
<div className="usa-alert__body">
<p className="usa-alert__text">{text}</p>
<Trans className="usa-alert__text" i18nKey={text} />
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/OverviewTables.tsx
Expand Up @@ -68,7 +68,7 @@ const OverviewTables = (props: Props): ReactElement => {
},
{
header: t('Eligibility.before'),
body: session?.eligibility?.before.replace(/[2]/g, '') || '',
body: session?.eligibility?.before?.replace(/[2]/g, '') || '',
},
{
header: t('Eligibility.programs'),
Expand Down
43 changes: 32 additions & 11 deletions app/src/pages/clinic.tsx
@@ -1,6 +1,10 @@
import { useAppContext } from '@context/state'
import clinics from '@public/clinic-output/clinics-with-ids.json'
import type { GetServerSideProps, NextPage } from 'next'
import type {
GetServerSideProps,
GetServerSidePropsResult,
NextPage,
} from 'next'
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import Image from 'next/image'
Expand Down Expand Up @@ -34,13 +38,10 @@ const Clinic: NextPage<Props> = (props: Props) => {
}>({ label: t('Clinic.button'), route: '/contact' })

useEffect(() => {
const prevRouteIndex = props.previousRoute.lastIndexOf('/')
const previousRoute = props.previousRoute.substring(prevRouteIndex)

if (previousRoute === '/review') {
if (props.previousRoute === '/review') {
setContinueBtn({
label: t('updateAndReturn'),
route: previousRoute,
route: props.previousRoute,
})
}
}, [props.previousRoute, t])
Expand Down Expand Up @@ -216,12 +217,32 @@ export const getServerSideProps: GetServerSideProps = async ({
locale,
req,
}) => {
return {
props: {
previousRoute: req.headers.referer,
...(await serverSideTranslations(locale || 'en', ['common'])),
},
const prevRouteIndex = req.headers.referer?.lastIndexOf('/')
const previousRoute =
prevRouteIndex && req.headers.referer?.substring(prevRouteIndex)
let returnval: GetServerSidePropsResult<{ [key: string]: object | string }> =
{
props: {
previousRoute: previousRoute as string,
...(await serverSideTranslations(locale || 'en', ['common'])),
},
}

if (
!['/income', '/review', '/contact', '/eligibility'].includes(
previousRoute as string
)
) {
returnval = {
...returnval,
redirect: {
destination: previousRoute || '/',
permanent: false,
},
}
}

return returnval
}

export default Clinic
65 changes: 49 additions & 16 deletions app/src/pages/contact.tsx
@@ -1,5 +1,9 @@
import { useAppContext } from '@context/state'
import type { GetServerSideProps, NextPage } from 'next'
import type {
GetServerSideProps,
GetServerSidePropsResult,
NextPage,
} from 'next'
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import Link from 'next/link'
Expand All @@ -19,17 +23,26 @@ const Contact: NextPage<Props> = (props: Props) => {
const [form, setForm] = useState(session?.contact)
const [continueBtn, setContinueBtn] = useState<{
label: string
width: string
}>({ label: t('continue'), width: '105px' })
}>({ label: t('continue') })
const requiredMet = (): boolean => {
const validPhoneLength = form.phone.replace(/[^0-9]/g, '').length === 10
return (
validPhoneLength &&
['firstName', 'lastName', 'phone'].every(
(field) => form[field as keyof typeof form]
)
)
}
const [disabled, setDisabled] = useState<boolean>(!requiredMet())

useEffect(() => {
const prevRouteIndex = props.previousRoute.lastIndexOf('/')
const previousRoute = props.previousRoute.substring(prevRouteIndex)
setDisabled(!requiredMet())
}, [form])

if (previousRoute === '/review') {
useEffect(() => {
if (props.previousRoute === '/review') {
setContinueBtn({
label: t('updateAndReturn'),
width: '239px',
})
}
}, [props.previousRoute, t])
Expand Down Expand Up @@ -85,13 +98,13 @@ const Contact: NextPage<Props> = (props: Props) => {
<abbr className="usa-hint usa-hint--required"> *</abbr>
</label>
<NumberFormat
className="usa-input"
format="###-###-####"
id="phone"
mask="_"
onChange={handleChange}
role="textbox"
className="usa-input"
id="phone"
value={form.phone}
onChange={handleChange}
/>
<br />
<br />
Expand All @@ -105,7 +118,11 @@ const Contact: NextPage<Props> = (props: Props) => {
/>
<br />
<br />
<ButtonLink href="/review" label={continueBtn.label} />
<ButtonLink
disabled={disabled}
href="/review"
label={continueBtn.label}
/>
<br />
</form>
)
Expand All @@ -115,12 +132,28 @@ export const getServerSideProps: GetServerSideProps = async ({
locale,
req,
}) => {
return {
props: {
previousRoute: req.headers.referer,
...(await serverSideTranslations(locale || 'en', ['common'])),
},
const prevRouteIndex = req.headers.referer?.lastIndexOf('/')
const previousRoute =
prevRouteIndex && req.headers.referer?.substring(prevRouteIndex)
let returnval: GetServerSidePropsResult<{ [key: string]: object | string }> =
{
props: {
previousRoute: previousRoute as string,
...(await serverSideTranslations(locale || 'en', ['common'])),
},
}

if (!['/clinic', '/review'].includes(previousRoute as string)) {
returnval = {
...returnval,
redirect: {
destination: previousRoute || '/',
permanent: false,
},
}
}

return returnval
}

export default Contact
26 changes: 25 additions & 1 deletion app/src/pages/eligibility.tsx
Expand Up @@ -21,6 +21,22 @@ const Eligibility: NextPage<Props> = (props: Props) => {
route: incomeRoute,
})
const [form, setForm] = useState(session?.eligibility)
const requiredMet = () => {
const categorical = [
'pregnant',
'baby',
'child',
'guardian',
'pregnant',
'none',
].some((category) => form[category as keyof typeof form])
const programs = ['insurance', 'snap', 'tanf', 'none2'].some(
(program) => form[program as keyof typeof form]
)

return form.residential && categorical && form.before && programs
}
const [disabled, setDisabled] = useState<boolean>(!requiredMet())

useEffect(() => {
/* NOTE: We are using useEffect() because we want to make sure the props provided by getServerSideProps() are reliably loaded into the page. */
Expand All @@ -36,6 +52,10 @@ const Eligibility: NextPage<Props> = (props: Props) => {
} else setContinueBtn({ ...continueBtn, route: incomeRoute })
}, [form.none, props.previousRoute])

useEffect(() => {
setDisabled(!requiredMet())
}, [form])

const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
const { value, name }: { value: string; name: string } = e.target
const castValue = value as keyof typeof form
Expand Down Expand Up @@ -193,7 +213,11 @@ const Eligibility: NextPage<Props> = (props: Props) => {
<br />
<br />
<br />
<ButtonLink href={continueBtn.route} label={continueBtn.label} />
<ButtonLink
href={continueBtn.route}
disabled={disabled}
label={continueBtn.label}
/>
<br />
</form>
)
Expand Down
28 changes: 25 additions & 3 deletions app/src/pages/income.tsx
@@ -1,5 +1,9 @@
import incomeData from '@public/data/income.json'
import type { GetServerSideProps, NextPage } from 'next'
import type {
GetServerSideProps,
GetServerSidePropsResult,
NextPage,
} from 'next'
import { Trans, useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import Link from 'next/link'
Expand Down Expand Up @@ -102,12 +106,30 @@ const TD = styled.td`
min-width: 20rem;
`

export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
return {
export const getServerSideProps: GetServerSideProps = async ({
locale,
req,
}) => {
const prevRouteIndex = req.headers.referer?.lastIndexOf('/')
const previousRoute =
prevRouteIndex && req.headers.referer?.substring(prevRouteIndex)
let returnval: GetServerSidePropsResult<{ [key: string]: object }> = {
props: {
...(await serverSideTranslations(locale || 'en', ['common'])),
},
}

if (!['/eligibility', '/clinic'].includes(previousRoute as string)) {
returnval = {
...returnval,
redirect: {
destination: previousRoute || '/',
permanent: false,
},
}
}

return returnval
}

export default Income
30 changes: 27 additions & 3 deletions app/src/pages/review.tsx
@@ -1,4 +1,8 @@
import type { GetServerSideProps, NextPage } from 'next'
import type {
GetServerSideProps,
GetServerSidePropsResult,
NextPage,
} from 'next'
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'

Expand All @@ -19,12 +23,32 @@ const Review: NextPage = () => {
)
}

export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
return {
export const getServerSideProps: GetServerSideProps = async ({
locale,
req,
}) => {
const prevRouteIndex = req.headers.referer?.lastIndexOf('/')
const previousRoute =
prevRouteIndex && req.headers.referer?.substring(prevRouteIndex)
let returnval: GetServerSidePropsResult<{ [key: string]: object }> = {
props: {
...(await serverSideTranslations(locale || 'en', ['common'])),
},
}

if (
!['/clinic', '/eligibility', '/contact'].includes(previousRoute as string)
) {
returnval = {
...returnval,
redirect: {
destination: previousRoute || '/',
permanent: false,
},
}
}

return returnval
}

export default Review

0 comments on commit 3d93a03

Please sign in to comment.