Skip to content

Commit

Permalink
Merge pull request #779 from DTS-STN/typescript-conversion
Browse files Browse the repository at this point in the history
Change profile to typescript
  • Loading branch information
Charles-Pham authored Dec 13, 2024
2 parents 4586a6c + 35e49c4 commit 1f0165c
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 53 deletions.
2 changes: 1 addition & 1 deletion components/ProfileTasks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from 'next/link'

interface Task {
export interface Task {
title: string
areaLabel: string
link: string
Expand Down
61 changes: 53 additions & 8 deletions graphql/mappers/auth-modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const getCachedContent = () => {
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchAuthModalsV1`
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchAuthModalsV1`,
)
if (!response.ok) return null
return (await response.json()) as GetSchAuthModalsV1
Expand All @@ -91,7 +91,7 @@ const getCachedContent = () => {
})
}

export async function getAuthModalsContent() {
export async function getAuthModalsContent(): Promise<AuthModalsContent> {
const response = await getCachedContent()
const resSignedOutContent = response?.data.youHaveBeenSignedOut.item
const resStaySignedIn = response?.data.staySignedIn.item
Expand Down Expand Up @@ -125,27 +125,27 @@ export async function getAuthModalsContent() {
en: {
bannerHeading: resStaySignedIn?.scHeadingEn,
signOutLinkText: resStaySignedIn?.scFragments.filter(
(fragment) => fragment.scId === 'sign-out'
(fragment) => fragment.scId === 'sign-out',
)[0].scLinkTextEn,
staySignedInLinktext: resStaySignedIn?.scFragments.filter(
(fragment) => fragment.scId === 'stay-signed-in'
(fragment) => fragment.scId === 'stay-signed-in',
)[0].scLinkTextEn,
bannerContent: resStaySignedIn?.scContentEn.json.map((data) =>
data.content.map((paragraph) => paragraph.value)
data.content.map((paragraph) => paragraph.value),
),
bannerMinutesAnd: 'minutes and',
bannerSeconds: 'seconds',
},
fr: {
bannerHeading: resStaySignedIn?.scHeadingFr,
signOutLinkText: resStaySignedIn?.scFragments.filter(
(fragment) => fragment.scId === 'sign-out'
(fragment) => fragment.scId === 'sign-out',
)[0].scLinkTextFr,
staySignedInLinktext: resStaySignedIn?.scFragments.filter(
(fragment) => fragment.scId === 'stay-signed-in'
(fragment) => fragment.scId === 'stay-signed-in',
)[0].scLinkTextFr,
bannerContent: resStaySignedIn?.scContentFr.json.map((data) =>
data.content.map((paragraph) => paragraph.value)
data.content.map((paragraph) => paragraph.value),
),
bannerMinutesAnd: 'minutes et',
bannerSeconds: 'secondes',
Expand All @@ -154,3 +154,48 @@ export async function getAuthModalsContent() {

return { mappedPopupStaySignedIn, mappedPopupSignedOut }
}

// TODO: Check which of these properties should actually be optional and switch to using a question mark instead
export interface AuthModalsContent {
err?: string
mappedPopupStaySignedIn?: {
en: {
bannerHeading: string | undefined
signOutLinkText: string | undefined
staySignedInLinktext: string | undefined
bannerContent: string[][] | undefined
bannerMinutesAnd: string
bannerSeconds: string
}
fr: {
bannerHeading: string | undefined
signOutLinkText: string | undefined
staySignedInLinktext: string | undefined
bannerContent: string[][] | undefined
bannerMinutesAnd: string
bannerSeconds: string
}
}
mappedPopupSignedOut?: {
en: {
bannerBoldText: string | undefined
bannerText: string | undefined
bannerLink: string | undefined
bannerLinkHref: string | undefined
bannerButtonText: string | undefined
bannerButtonLink: string
icon: string | undefined
bannerHeading: string | undefined
}
fr: {
bannerBoldText: string | undefined
bannerText: string | undefined
bannerLink: string | undefined
bannerLinkHref: string | undefined
bannerButtonText: string | undefined
bannerButtonLink: string
icon: string | undefined
bannerHeading: string | undefined
}
}
}
102 changes: 96 additions & 6 deletions graphql/mappers/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const getCachedContent = () => {
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchProfileV1`
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchProfileV1`,
)
if (!response.ok) return null
return (await response.json()) as GetSchProfileV1
Expand All @@ -81,7 +81,7 @@ const getCachedContent = () => {
})
}

export async function getProfileContent() {
export async function getProfileContent(): Promise<ProfileContent> {
const response = await getCachedContent()

// LookingFor Fragment
Expand All @@ -95,7 +95,7 @@ export async function getProfileContent() {
// BackToDashboard Fragment
const backToDashboardFragment = findFragmentByScId(
response,
'back-to-my-dashboard'
'back-to-my-dashboard',
)

// ProfileIntro Fragment
Expand All @@ -110,7 +110,7 @@ export async function getProfileContent() {
link: level.scPageNameEn,
text: level.scTitleEn,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scTitleEn,
heading: profileIntroFragment?.scContentEn?.json[0].content[0].value,
Expand Down Expand Up @@ -162,7 +162,7 @@ export async function getProfileContent() {
link: level.scPageNameFr,
text: level.scTitleFr,
}
}
},
),
pageName: response?.data.schPageV1ByPath.item.scTitleFr,
heading: profileIntroFragment?.scContentFr?.json[0].content[0].value,
Expand Down Expand Up @@ -213,7 +213,97 @@ export async function getProfileContent() {
const findFragmentByScId = (res: GetSchProfileV1 | null, id: string) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
({ scId }) => scId === id
({ scId }) => scId === id,
) ?? null
)
}

// TODO: Check which of these properties should actually be optional and switch to using a question mark instead
export interface ProfileContent {
err?: string
en?:
| {
breadcrumb:
| {
link: string
text: string
}[]
| undefined
pageName: string | undefined
heading: string | undefined
list:
| (
| {
id: string
title: string | undefined
tasks:
| {
id: string
title: string
areaLabel: string
link: string
icon: string
betaPopUp: boolean
}[]
| undefined
}
| undefined
)[]
| undefined
lookingFor: {
title: string | undefined
subText: (string | undefined)[]
link: string
id: string
}
backToDashboard: {
id: string | undefined
btnText: string | undefined
btnLink: string | undefined
}
title?: string | undefined
}
| undefined
fr?: {
breadcrumb:
| {
link: string
text: string
}[]
| undefined
pageName: string | undefined
heading: string | undefined
list:
| (
| {
id: string
title: string | undefined
tasks:
| {
id: string
title: string
areaLabel: string
link: string
icon: string
betaPopUp: boolean
}[]
| undefined
}
| undefined
)[]
| undefined
lookingFor: {
title: string | undefined
subText: (string | undefined)[]
link: string
id: string
}
backToDashboard:
| {
id: string | undefined
btnText: string | undefined
btnLink: string | undefined
}
| undefined
}
}
8 changes: 4 additions & 4 deletions pages/contact-us/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ export const getServerSideProps = (async ({ req, res, locale, params }) => {
aaMenuPrefix: `ESDC-EDSC_MSCA-MSDC-SCH:Nav Menu`,
popupStaySignedIn:
locale === 'en'
? authModals.mappedPopupStaySignedIn.en
: authModals.mappedPopupStaySignedIn.fr,
? authModals.mappedPopupStaySignedIn?.en
: authModals.mappedPopupStaySignedIn?.fr,
popupYouHaveBeenSignedout:
locale === 'en'
? authModals.mappedPopupSignedOut.en
: authModals.mappedPopupSignedOut.fr,
? authModals.mappedPopupSignedOut?.en
: authModals.mappedPopupSignedOut?.fr,
},
}
}) satisfies GetServerSideProps<ContactUsPageProps>
Expand Down
8 changes: 4 additions & 4 deletions pages/contact-us/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ export const getServerSideProps = (async ({ req, res, locale }) => {
aaMenuPrefix: `ESDC-EDSC_MSCA-MSDC-SCH:Nav Menu`,
popupStaySignedIn:
locale === 'en'
? authModals.mappedPopupStaySignedIn.en
: authModals.mappedPopupStaySignedIn.fr,
? authModals.mappedPopupStaySignedIn?.en
: authModals.mappedPopupStaySignedIn?.fr,
popupYouHaveBeenSignedout:
locale === 'en'
? authModals.mappedPopupSignedOut.en
: authModals.mappedPopupSignedOut.fr,
? authModals.mappedPopupSignedOut?.en
: authModals.mappedPopupSignedOut?.fr,
},
}
}) satisfies GetServerSideProps<ContactLandingProps>
Expand Down
Loading

0 comments on commit 1f0165c

Please sign in to comment.