diff --git a/components/BenefitTasks.tsx b/components/BenefitTasks.tsx index 321e3d6ca..b2408a47d 100644 --- a/components/BenefitTasks.tsx +++ b/components/BenefitTasks.tsx @@ -11,12 +11,10 @@ interface Tasks { id: string } -interface TaskListProps { +export interface TaskListProps { title: string - dataCy: string tasks: Tasks[] } - interface BenefitTasksProps { locale: string taskList: TaskListProps diff --git a/components/Card.tsx b/components/Card.tsx index 883262e2b..991f434fa 100644 --- a/components/Card.tsx +++ b/components/Card.tsx @@ -9,8 +9,6 @@ interface AlertProps { type: string alertHeading: string alertBody: string - alert_icon_alt_text: string - alert_icon_id: string } interface CardProps { cardTitle: string @@ -31,8 +29,6 @@ const Card = ({ type: '', alertHeading: '', alertBody: '', - alert_icon_alt_text: '', - alert_icon_id: '', }, ], locale, diff --git a/graphql/mappers/decision-reviews.ts b/graphql/mappers/decision-reviews.ts index e2bfdeec1..1452cf28c 100644 --- a/graphql/mappers/decision-reviews.ts +++ b/graphql/mappers/decision-reviews.ts @@ -35,7 +35,7 @@ interface GetSchDecisionReviewsV1 { scDestinationURLEn: string scDestinationURLFr: string schBetaPopUp: boolean - schURLType: string + schURLType?: string }> }> } @@ -95,7 +95,7 @@ export async function getDecisionReviewsContent(): Promise { }) } -export async function getMyDashboardContent() { +export async function getMyDashboardContent(): Promise { const response = await getCachedContent() const pageAlertContent = response?.data.schPageV1ByPath.item.schAlerts @@ -209,3 +209,88 @@ export async function getMyDashboardContent() { } return mappedHome } + +export interface MyDashboardContent { + err?: string + en?: { + pageName: string | undefined + heading: string | undefined + pageAlerts: + | { + id: string | undefined + alertHeading: string | undefined + alertBody: string | undefined + type: string[] | undefined + }[] + | undefined + cards: + | { + id: string + title: string + dropdownText: string + cardAlerts: + | { + id: string + alertHeading: string + alertBody: string | undefined + type: string[] | undefined + }[] + | undefined + lists: { + title: string + tasks: { + id: string + title: string + areaLabel: string + link: string + icon: string + betaPopUp: boolean + }[] + }[] + }[] + | undefined + exitBeta: { title: null | undefined; link: string | undefined } + } + fr?: { + pageName: string | undefined + heading: string | undefined + pageAlerts: + | { + id: string | undefined + alertHeading: string | undefined + alertBody: string | undefined + type: string[] | undefined + }[] + | undefined + cards: + | ( + | { + id: string + title: string + dropdownText: string + cardAlerts: + | { + id: string + alertHeading: string + alertBody: string | undefined + type: string[] | undefined + }[] + | undefined + lists: { + title: string + tasks: { + id: string + title: string + areaLabel: string + link: string + icon: string + betaPopUp: boolean + }[] + }[] + } + | undefined + )[] + | undefined + exitBeta: { title: null | undefined; link: string | undefined } + } +} diff --git a/graphql/mappers/security-settings.ts b/graphql/mappers/security-settings.ts index 231b9f237..3ffbf464f 100644 --- a/graphql/mappers/security-settings.ts +++ b/graphql/mappers/security-settings.ts @@ -154,7 +154,7 @@ export async function getSecuritySettingsContent(): Promise { +export const programs = (acronym: string) => { switch (acronym.toLowerCase()) { case 'ei': return 'Employment Insurance' diff --git a/locales/en.js b/locales/en.ts similarity index 100% rename from locales/en.js rename to locales/en.ts diff --git a/locales/fr.js b/locales/fr.ts similarity index 100% rename from locales/fr.js rename to locales/fr.ts diff --git a/pages/_document.js b/pages/_document.tsx similarity index 100% rename from pages/_document.js rename to pages/_document.tsx diff --git a/pages/my-dashboard.js b/pages/my-dashboard.tsx similarity index 71% rename from pages/my-dashboard.js rename to pages/my-dashboard.tsx index 738673dc9..7ebaad4de 100644 --- a/pages/my-dashboard.js +++ b/pages/my-dashboard.tsx @@ -5,8 +5,14 @@ import Card from '../components/Card' import Heading from '../components/Heading' import ContextualAlert from '../components/ContextualAlert' import InfoMessage from '../components/InfoMessage' -import { getMyDashboardContent } from '../graphql/mappers/my-dashboard' -import { getAuthModalsContent } from '../graphql/mappers/auth-modals' +import { + getMyDashboardContent, + MyDashboardContent, +} from '../graphql/mappers/my-dashboard' +import { + AuthModalsContent, + getAuthModalsContent, +} from '../graphql/mappers/auth-modals' import { getLogger } from '../logging/log-util' import { AuthIsDisabled, @@ -15,19 +21,61 @@ import { Redirect, getIdToken, } from '../lib/auth' -import { authOptions } from '../pages/api/auth/[...nextauth]' +import { authOptions } from './api/auth/[...nextauth]' import { getServerSession } from 'next-auth/next' -import BenefitTasks from './../components/BenefitTasks' -import MostReqTasks from './../components/MostReqTasks' +import BenefitTasks, { TaskListProps } from '../components/BenefitTasks' +import MostReqTasks from '../components/MostReqTasks' import { acronym } from '../lib/acronym' import ErrorPage from '../components/ErrorPage' +import { GetServerSidePropsContext } from 'next' +import { Key } from 'react' -export default function MyDashboard(props) { +interface MyDashboardProps { + locale: string + content: { + err?: '500' | '404' | '503' + heading: string + pageAlerts: { + id: string + alertHeading: string | undefined + alertBody: string + type: string[] + }[] + cards: { + id: string + title: string + dropdownText: string + cardAlerts: { + id: string + alertHeading: string + alertBody: string + type: string + }[] + lists: { + title: string + tasks: { + id: string + title: string + areaLabel: string + link: string + icon: string + betaPopUp: boolean + }[] + }[] + }[] + } + bannerContent?: { err?: '500' | '404' | '503' } + popupContent?: { err?: '500' | '404' | '503' } + popupContentNA?: { err?: '500' | '404' | '503' } + authModals?: { err?: '500' | '404' | '503' } + aaPrefix: string +} +export default function MyDashboard(props: MyDashboardProps) { /* istanbul ignore next */ const t = props.locale === 'en' ? en : fr const errorCode = - props.content?.err || + props.content.err || props.bannerContent?.err || props.popupContent?.err || props.popupContentNA?.err || @@ -35,14 +83,14 @@ export default function MyDashboard(props) { if (errorCode !== undefined) { return ( { const mostReq = card.lists[0] - var tasks = card.lists.slice(1, card.lists.length) + const tasks = card.lists.slice(1, card.lists.length) return ( - {tasks.map((taskList, index) => { + {tasks.map((taskList: TaskListProps, index: Key) => { return (
{ - logger.error(error) - return { err: '500' } - }) + const content = await getMyDashboardContent().catch( + (error): MyDashboardContent => { + logger.error(error) + return { err: '500' } + }, + ) - const authModals = await getAuthModalsContent().catch((error) => { - logger.error(error) - return { err: '500' } - }) + const authModals = await getAuthModalsContent().catch( + (error): AuthModalsContent => { + logger.error(error) + return { err: '500' } + }, + ) if (locale === 'und') { locale = 'en' @@ -217,30 +276,30 @@ export async function getServerSideProps({ req, res, locale }) { locale, langToggleLink, content: - content?.err !== undefined + content.err !== undefined ? content : locale === 'en' ? content.en : content.fr, meta, aaPrefix: - content?.err !== undefined + content.err !== undefined ? '' - : `ESDC-EDSC_MSCA-MSDC-SCH:${content.en?.heading || content.en?.title}`, + : `ESDC-EDSC_MSCA-MSDC-SCH:${content.en?.heading}`, aaMenuPrefix: - content?.err !== undefined ? '' : `ESDC-EDSC_MSCA-MSDC-SCH:Nav Menu`, + content.err !== undefined ? '' : `ESDC-EDSC_MSCA-MSDC-SCH:Nav Menu`, popupStaySignedIn: - authModals?.err !== undefined + authModals.err !== undefined ? authModals : locale === 'en' - ? authModals.mappedPopupStaySignedIn.en - : authModals.mappedPopupStaySignedIn.fr, + ? authModals.mappedPopupStaySignedIn?.en + : authModals.mappedPopupStaySignedIn?.fr, popupYouHaveBeenSignedout: - authModals?.err !== undefined + authModals.err !== undefined ? authModals : locale === 'en' - ? authModals.mappedPopupSignedOut.en - : authModals.mappedPopupSignedOut.fr, + ? authModals.mappedPopupSignedOut?.en + : authModals.mappedPopupSignedOut?.fr, }, } }