Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change profile to typescript #779

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading
Loading