Skip to content

Commit

Permalink
Convert security settings and decision review to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Pham committed Dec 16, 2024
1 parent 35e49c4 commit af36e9f
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 71 deletions.
4 changes: 2 additions & 2 deletions components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ButtonProps {
iconEnd?: boolean
href?: string
type?: 'submit' | 'reset' | 'button'
onClick: MouseEventHandler<HTMLElement>
onClick?: MouseEventHandler<HTMLElement>
disabled?: boolean
className?: string
attributes?: { [key: string]: string }
Expand All @@ -27,7 +27,7 @@ const Button = ({
iconEnd,
href = 'no ref',
type,
onClick,
onClick = () => {},
disabled,
className,
attributes,
Expand Down
61 changes: 49 additions & 12 deletions graphql/mappers/decision-reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const getCachedContent = () => {
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchDecisionReviewsV1`
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchDecisionReviewsV1`,
)
if (!response.ok) return null
return (await response.json()) as GetSchDecisionReviewsV1
Expand All @@ -58,17 +58,17 @@ const getCachedContent = () => {
})
}

export async function getDecisionReviewsContent() {
export async function getDecisionReviewsContent(): Promise<DecisionReviewContent> {
const response = await getCachedContent()

const askFragment = findFragmentByScId(
response,
'decision-review-ask-service-canada'
'decision-review-ask-service-canada',
)

const appealFragment = findFragmentByScId(
response,
'decision-review-appeal-to-sst'
'decision-review-appeal-to-sst',
)

const mappedDecisionReviews = {
Expand All @@ -82,7 +82,7 @@ export async function getDecisionReviewsContent() {
text: level.scTitleEn,
id: level.scId,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameEn,
heading: response?.data.schPageV1ByPath.item.scTitleEn,
Expand All @@ -95,7 +95,7 @@ export async function getDecisionReviewsContent() {
areaLabel: askFragment?.scFragments[0].scLinkTextAssistiveEn,
link: buildLink(
askFragment?.scFragments[0].schURLType,
askFragment?.scFragments[0].scDestinationURLEn
askFragment?.scFragments[0].scDestinationURLEn,
),
betaPopUp: askFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -108,7 +108,7 @@ export async function getDecisionReviewsContent() {
areaLabel: appealFragment?.scFragments[0].scLinkTextAssistiveEn,
link: buildLink(
appealFragment?.scFragments[0].schURLType,
appealFragment?.scFragments[0].scDestinationURLEn
appealFragment?.scFragments[0].scDestinationURLEn,
),
betaPopUp: appealFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -125,7 +125,7 @@ export async function getDecisionReviewsContent() {
text: level.scTitleFr,
id: level.scId,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameFr,
heading: response?.data.schPageV1ByPath.item.scTitleFr,
Expand All @@ -138,7 +138,7 @@ export async function getDecisionReviewsContent() {
areaLabel: askFragment?.scFragments[0].scLinkTextAssistiveFr,
link: buildLink(
askFragment?.scFragments[0].schURLType,
askFragment?.scFragments[0].scDestinationURLFr
askFragment?.scFragments[0].scDestinationURLFr,
),
betaPopUp: askFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -151,7 +151,7 @@ export async function getDecisionReviewsContent() {
areaLabel: appealFragment?.scFragments[0].scLinkTextAssistiveFr,
link: buildLink(
appealFragment?.scFragments[0].schURLType,
appealFragment?.scFragments[0].scDestinationURLFr
appealFragment?.scFragments[0].scDestinationURLFr,
),
betaPopUp: appealFragment?.scFragments[0].schBetaPopUp,
},
Expand All @@ -164,11 +164,48 @@ export async function getDecisionReviewsContent() {

const findFragmentByScId = (
res: GetSchDecisionReviewsV1 | null,
id: string
id: string,
) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
({ scId }) => scId === id
({ scId }) => scId === id,
) ?? null
)
}

// TODO: Figure out which of these actually need to be optional
export interface DecisionReviewContent {
err?: string
en?: {
id: string
breadcrumb: { link: string; text: string; id: string }[] | undefined
pageName: string | undefined
heading: string | undefined
content: {
content: string | undefined
button: {
id: string | undefined
text: string | undefined
areaLabel: string | undefined
link: string | undefined
betaPopUp: boolean | undefined
}
}[]
}
fr?: {
id: string
breadcrumb: { link: string; text: string; id: string }[] | undefined
pageName: string | undefined
heading: string | undefined
content: {
content: string | undefined
button: {
id: string | undefined
text: string | undefined
areaLabel: string | undefined
link: string | undefined
betaPopUp: boolean | undefined
}
}[]
}
}
57 changes: 47 additions & 10 deletions graphql/mappers/security-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const getCachedContent = () => {
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchSecuritySettingsV1`
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchSecuritySettingsV1`,
)
if (!response.ok) return null
return (await response.json()) as GetSchSecuritySettingsV1
Expand All @@ -105,7 +105,7 @@ const getCachedContent = () => {
})
}

export async function getSecuritySettingsContent() {
export async function getSecuritySettingsContent(): Promise<SecuritySettingsContent> {
const response = await getCachedContent()

const enLookingForFragment =
Expand All @@ -124,7 +124,7 @@ export async function getSecuritySettingsContent() {
const securityQuestions =
findFragmentByScId(
response,
'security-settings-main-content'
'security-settings-main-content',
)?.scFragments?.find(({ scId }) => scId === 'security-questions') ?? null

const mappedSecurity = {
Expand All @@ -136,15 +136,15 @@ export async function getSecuritySettingsContent() {
link: level.scPageNameEn,
text: level.scTitleEn,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameEn,
heading: response?.data.schPageV1ByPath.item.scTitleEn,
subHeading: enContentFragment?.json[0].content[0].value,
lookingFor: {
title: enLookingForFragment?.json[0].content[0].value,
subText: enLookingForFragment?.json[1].content.map(
({ value }) => value ?? null
({ value }) => value ?? null,
),
link: '/profile',
id: 'profile',
Expand All @@ -154,7 +154,7 @@ export async function getSecuritySettingsContent() {
text: securityQuestions?.scLinkTextEn,
link: buildLink(
securityQuestions?.schURLType,
securityQuestions?.scDestinationURLEn
securityQuestions?.scDestinationURLEn,
),
},
subTitle: securityQuestions?.scDescriptionEn.json[0].content[0].value,
Expand All @@ -168,7 +168,7 @@ export async function getSecuritySettingsContent() {
link: level.scPageNameFr,
text: level.scTitleFr,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameFr,
heading: response?.data.schPageV1ByPath.item.scTitleFr,
Expand All @@ -186,7 +186,7 @@ export async function getSecuritySettingsContent() {
text: securityQuestions?.scLinkTextFr,
link: buildLink(
securityQuestions?.schURLType,
securityQuestions?.scDestinationURLFr
securityQuestions?.scDestinationURLFr,
),
},
subTitle: securityQuestions?.scDescriptionFr.json[0].content[0].value,
Expand All @@ -198,11 +198,48 @@ export async function getSecuritySettingsContent() {

const findFragmentByScId = (
res: GetSchSecuritySettingsV1 | null,
id: string
id: string,
) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
({ scId }) => scId === id
({ scId }) => scId === id,
) ?? null
)
}

// TODO: Figure out which of these actually need to be optional
export interface SecuritySettingsContent {
err?: string
en?: {
breadcrumb: { link: string; text: string }[] | undefined
pageName: string | undefined
heading: string | undefined
subHeading: string | undefined
lookingFor: {
title: string | undefined
subText: (string | null)[] | undefined
link: string
id: string
}
securityQuestions: {
linkTitle: { text: string | undefined; link: string }
subTitle: string | undefined
}
}
fr?: {
breadcrumb: { link: string; text: string }[] | undefined
pageName: string | undefined
heading: string | undefined
subHeading: string | undefined
lookingFor: {
title: string | undefined
subText: (string | null)[] | undefined
link: string
id: string
}
securityQuestions: {
linkTitle: { text: string | undefined; link: string }
subTitle: string | undefined
}
}
}
Loading

0 comments on commit af36e9f

Please sign in to comment.