Skip to content

Commit

Permalink
Add maintenance page
Browse files Browse the repository at this point in the history
This PR adds a down-for-maintenance page that can be manually enabled by setting a new ENABLE_MAINTENANCE_PAGE environment variable to 'enabled'.
  • Loading branch information
kalvinwang authored Sep 3, 2021
2 parents 2059d99 + 8e8768f commit 72d5437
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
13 changes: 13 additions & 0 deletions components/Maintenance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useTranslation } from 'next-i18next'

export const Maintenance: React.FC = () => {
const { t } = useTranslation('common')

return (
<div className="error-content">
<div className="error-label">{t('maintenance.label')}</div>
<div className="error-entry">{t('maintenance.entry')}</div>
<div className="error-entry">{t('maintenance.entry2')}</div>
</div>
)
}
1 change: 0 additions & 1 deletion pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NextPageContext } from 'next'
import { useTranslation } from 'next-i18next'
import { ReactElement } from 'react'

Expand Down
47 changes: 25 additions & 22 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Header } from '../components/Header'
import { Title } from '../components/Title'
import { ClaimSection } from '../components/ClaimSection'
import { TimeoutModal } from '../components/TimeoutModal'
import { Maintenance } from '../components/Maintenance'
import { Footer } from '../components/Footer'

import { ScenarioContent, UrlPrefixes } from '../types/common'
Expand All @@ -26,6 +27,7 @@ export interface HomeProps {
userArrivedFromUioMobile?: boolean
urlPrefixes: UrlPrefixes
enableGoogleAnalytics: string
enableMaintenancePage: string
}

export default function Home({
Expand All @@ -36,6 +38,7 @@ export default function Home({
userArrivedFromUioMobile = false,
urlPrefixes,
enableGoogleAnalytics,
enableMaintenancePage,
}: HomeProps): ReactElement {
const { t } = useTranslation('common')

Expand Down Expand Up @@ -64,28 +67,22 @@ export default function Home({
)

// If any errorCode is provided, render the error page.
let mainComponent: JSX.Element
if (errorCode) {
mainComponent = (
<main className="main">
<Container className="main-content">
<Error userArrivedFromUioMobile />
</Container>
</main>
)
let mainContent: JSX.Element
if (enableMaintenancePage) {
mainContent = <Maintenance />
} else if (errorCode) {
mainContent = <Error userArrivedFromUioMobile />
} else {
mainComponent = (
<main className="main">
<Container className="main-content">
<Title />
<ClaimSection
loading={loading}
userArrivedFromUioMobile={userArrivedFromUioMobile}
statusContent={scenarioContent.statusContent}
detailsContent={scenarioContent.detailsContent}
/>
</Container>
</main>
mainContent = (
<>
<Title />
<ClaimSection
loading={loading}
userArrivedFromUioMobile={userArrivedFromUioMobile}
statusContent={scenarioContent.statusContent}
detailsContent={scenarioContent.detailsContent}
/>
</>
)
}

Expand All @@ -104,7 +101,9 @@ export default function Home({
{enableGoogleAnalytics === 'enabled' && googleAnalytics}
</Head>
<Header userArrivedFromUioMobile={userArrivedFromUioMobile} />
{mainComponent}
<main className="main">
<Container className="main-content">{mainContent}</Container>
</main>
<TimeoutModal userArrivedFromUioMobile={userArrivedFromUioMobile} timedOut={timedOut} urlPrefixes={urlPrefixes} />
<Footer />
</Container>
Expand All @@ -128,6 +127,9 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, locale,
// Set to 'enabled' to include Google Analytics code
const ENABLE_GOOGLE_ANALYTICS = process.env.ENABLE_GOOGLE_ANALYTICS ?? ''

// Set to 'enabled' to display down-for-maintenance page
const ENABLE_MAINTENANCE_PAGE = process.env.ENABLE_MAINTENANCE_PAGE ?? ''

// Other vars.
let errorCode: number | null = null
let scenarioContent: ScenarioContent | null = null
Expand Down Expand Up @@ -199,6 +201,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, locale,
userArrivedFromUioMobile: userArrivedFromUioMobile,
urlPrefixes: URL_PREFIXES,
enableGoogleAnalytics: ENABLE_GOOGLE_ANALYTICS,
enableMaintenancePage: ENABLE_MAINTENANCE_PAGE,
...(await serverSideTranslations(locale || 'en', ['common', 'claim-details', 'claim-status'])),
},
}
Expand Down
5 changes: 5 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"entry": "We are unable to perform your request."
}
},
"maintenance": {
"label": "We'll Be Back Soon",
"entry": "This page is currently unavailable during system maintenance.",
"entry2": "Thank you for your patience as we continue to improve our services."
},
"claim-status": {
"title": "Claim Status",
"your-next-steps": "Your Next Steps",
Expand Down
5 changes: 5 additions & 0 deletions public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"entry": "We are unable to perform your request."
}
},
"maintenance": {
"label": "We'll Be Back Soon",
"entry": "This page is currently unavailable during system maintenance.",
"entry2": "Thank you for your patience as we continue to improve our services."
},
"claim-status": {
"title": "Estatus de solicitud",
"your-next-steps": "Sus próximos pasos",
Expand Down

0 comments on commit 72d5437

Please sign in to comment.