From 7b92be973c1d952db325c3955738d5a82a9ce2f5 Mon Sep 17 00:00:00 2001 From: Arvid Norlin Date: Mon, 22 Apr 2024 14:04:20 +0200 Subject: [PATCH] fix: move typings --- .../(protected)/my-pages/stays/page.tsx | 2 -- components/MyPages/AccountPage/Content.tsx | 35 +++++++++---------- .../Blocks/Benefits/CurrentLevel/index.tsx | 3 +- .../Blocks/Benefits/NextLevel/index.tsx | 9 ++--- .../MyPages/Blocks/Stays/Previous/index.tsx | 10 ++---- .../MyPages/Blocks/Stays/Soonest/index.tsx | 10 ++---- .../MyPages/Blocks/Stays/Upcoming/index.tsx | 10 ++---- .../components/myPages/myPage/accountPage.ts | 16 +++++++++ types/components/myPages/myPage/shortcuts.ts | 2 -- types/components/myPages/myStays/title.ts | 2 +- 10 files changed, 43 insertions(+), 56 deletions(-) create mode 100644 types/components/myPages/myPage/accountPage.ts diff --git a/app/[lang]/(live)/(protected)/my-pages/stays/page.tsx b/app/[lang]/(live)/(protected)/my-pages/stays/page.tsx index 9b5b5ab66..477630040 100644 --- a/app/[lang]/(live)/(protected)/my-pages/stays/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/stays/page.tsx @@ -15,7 +15,6 @@ export default async function MyStays({ params }: PageArgs) { subtitle={ "Excited about your next trip? So are we. Below are your upcoming stays with us, complete with all the details you need to make each visit perfect. Can't wait to welcome you back, friend!" } - link={null} /> ) { subtitle={ "Revisit your stays and rekindle those our moments together, with ease." } - link={null} /> ) diff --git a/components/MyPages/AccountPage/Content.tsx b/components/MyPages/AccountPage/Content.tsx index 5bb2b1ff8..327a8da61 100644 --- a/components/MyPages/AccountPage/Content.tsx +++ b/components/MyPages/AccountPage/Content.tsx @@ -3,7 +3,6 @@ import { Lang } from "@/constants/languages" import { AccountPageContentItem, ContentEntries, - DynamicContent, DynamicContentComponents, } from "@/types/requests/myPages/accountpage" import { User } from "@/types/user" @@ -16,36 +15,34 @@ import Shortcuts from "@/components/MyPages/Blocks/Shortcuts" import UpcomingStays from "@/components/MyPages/Blocks/Stays/Upcoming" import SoonestStays from "@/components/MyPages/Blocks/Stays/Soonest" import { renderOptions } from "@/components/JsonToHtml/renderOptions" +import { AccountPageContentProps } from "@/types/components/myPages/myPage/accountPage" +import PreviousStays from "../Blocks/Stays/Previous" + +function DynamicComponent({ user, lang, content }: AccountPageContentProps) { + const link = content.link.linkConnection.edges.length + ? { + href: content.link.linkConnection.edges[0].node.url, + text: content.link.link_text, + } + : null -function DynamicComponent({ - user, - lang, - content, -}: { - content: DynamicContent - lang: Lang - user: User -}) { const componentProps = { + lang, title: content.title, // TODO: rename preamble to subtitle in Contentstack subtitle: content.preamble, - link: content.link.linkConnection.edges.length - ? { - href: content.link.linkConnection.edges[0].node.url, - text: content.link.link_text, - } - : null, + ...link, } + switch (content.component) { case DynamicContentComponents.membership_overview: return case DynamicContentComponents.previous_stays: - return null + return case DynamicContentComponents.soonest_stays: - return + return case DynamicContentComponents.upcoming_stays: - return + return case DynamicContentComponents.current_benefits: return case DynamicContentComponents.next_benefits: diff --git a/components/MyPages/Blocks/Benefits/CurrentLevel/index.tsx b/components/MyPages/Blocks/Benefits/CurrentLevel/index.tsx index 5a3add942..85c4a6bb4 100644 --- a/components/MyPages/Blocks/Benefits/CurrentLevel/index.tsx +++ b/components/MyPages/Blocks/Benefits/CurrentLevel/index.tsx @@ -11,12 +11,13 @@ export type CurrentLevelProps = { subtitle?: string link: { text: string; href: string } | null } +import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage" export default async function CurrentBenefitsBlock({ title, subtitle, link, -}: CurrentLevelProps) { +}: AccountPageComponentProps) { const benefits = await serverClient().user.benefits.current() return ( diff --git a/components/MyPages/Blocks/Benefits/NextLevel/index.tsx b/components/MyPages/Blocks/Benefits/NextLevel/index.tsx index 78b77fcf5..fc894cba7 100644 --- a/components/MyPages/Blocks/Benefits/NextLevel/index.tsx +++ b/components/MyPages/Blocks/Benefits/NextLevel/index.tsx @@ -7,18 +7,13 @@ import Button from "@/components/TempDesignSystem/Button" import Title from "@/components/Title" import styles from "./next.module.css" - -export type NextLevelProps = { - title: string - subtitle?: string - link: { href: string; text: string } | null -} +import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage" export default async function NextLevelBenefitsBlock({ title, subtitle, link, -}: NextLevelProps) { +}: AccountPageComponentProps) { const { nextLevel, perks } = await serverClient().user.benefits.nextLevel() return ( diff --git a/components/MyPages/Blocks/Stays/Previous/index.tsx b/components/MyPages/Blocks/Stays/Previous/index.tsx index 5592c41d9..f284716c2 100644 --- a/components/MyPages/Blocks/Stays/Previous/index.tsx +++ b/components/MyPages/Blocks/Stays/Previous/index.tsx @@ -11,21 +11,15 @@ import ShowMoreButton from "../ShowMoreButton" import StayList from "../StayList" import EmptyPreviousStaysBlock from "./EmptyPreviousStays" +import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage" import type { Page } from "@/types/components/myPages/myStays/page" -type PreviousStaysProps = { - lang: Lang - title: string - subtitle?: string - link: { href: string; text: string } | null -} - export default function PreviousStays({ lang, title, subtitle, link, -}: PreviousStaysProps) { +}: AccountPageComponentProps) { const { data, isFetching, fetchNextPage, hasNextPage } = trpc.user.stays.previous.useInfiniteQuery( {}, diff --git a/components/MyPages/Blocks/Stays/Soonest/index.tsx b/components/MyPages/Blocks/Stays/Soonest/index.tsx index 0104f82af..521bb84c4 100644 --- a/components/MyPages/Blocks/Stays/Soonest/index.tsx +++ b/components/MyPages/Blocks/Stays/Soonest/index.tsx @@ -1,4 +1,3 @@ -import { Lang } from "@/constants/languages" import { serverClient } from "@/lib/trpc/server" import Header from "../Header" @@ -7,19 +6,14 @@ import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays" import styles from "./soonest.module.css" -type UpcomingStaysProps = { - lang: Lang - title: string - subtitle?: string - link: { text: string; href: string } | null -} +import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage" export default async function UpcomingStays({ lang, title, subtitle, link, -}: UpcomingStaysProps) { +}: AccountPageComponentProps) { const stays = await serverClient().user.stays.soonestUpcoming() return ( diff --git a/components/MyPages/Blocks/Stays/Upcoming/index.tsx b/components/MyPages/Blocks/Stays/Upcoming/index.tsx index 9a4cc30f2..05d4f3882 100644 --- a/components/MyPages/Blocks/Stays/Upcoming/index.tsx +++ b/components/MyPages/Blocks/Stays/Upcoming/index.tsx @@ -11,21 +11,15 @@ import ShowMoreButton from "../ShowMoreButton" import StayList from "../StayList" import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays" +import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage" import type { Page } from "@/types/components/myPages/myStays/page" -type UpcomingStaysProps = { - lang: Lang - title: string - subtitle?: string - link: { text: string; href: string } | null -} - export default function UpcomingStays({ lang, title, subtitle, link, -}: UpcomingStaysProps) { +}: AccountPageComponentProps) { const { data, hasNextPage, isFetching, fetchNextPage } = trpc.user.stays.upcoming.useInfiniteQuery( {}, diff --git a/types/components/myPages/myPage/accountPage.ts b/types/components/myPages/myPage/accountPage.ts new file mode 100644 index 000000000..e1de317be --- /dev/null +++ b/types/components/myPages/myPage/accountPage.ts @@ -0,0 +1,16 @@ +import { Lang } from "@/constants/languages" +import { DynamicContent } from "@/types/requests/myPages/accountpage" +import { User } from "@/types/user" + +export type AccountPageContentProps = { + content: DynamicContent + lang: Lang + user: User +} + +export type AccountPageComponentProps = { + lang: Lang + title: string + subtitle?: string + link?: { href: string; text: string } +} diff --git a/types/components/myPages/myPage/shortcuts.ts b/types/components/myPages/myPage/shortcuts.ts index 1813af12d..df586f313 100644 --- a/types/components/myPages/myPage/shortcuts.ts +++ b/types/components/myPages/myPage/shortcuts.ts @@ -1,5 +1,3 @@ -import { Shortcut } from "@/types/requests/myPages/accountpage" -import { PageLink } from "@/types/requests/utils/pageLink" import { ReactNode } from "react" export type ShortcutsProps = { diff --git a/types/components/myPages/myStays/title.ts b/types/components/myPages/myStays/title.ts index 4a765266d..3e4839b11 100644 --- a/types/components/myPages/myStays/title.ts +++ b/types/components/myPages/myStays/title.ts @@ -1,5 +1,5 @@ export type HeaderProps = { title: string subtitle?: string - link: { href: string; text: string } | null + link?: { href: string; text: string } }