Merged in chore(LOY-531)-cleanup-old-stays (pull request #3498)
chore(LOY-531): cleanup old stays * chore(LOY-531): cleanup old stays Approved-by: Emma Zettervall Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import ButtonLink from "@scandic-hotels/design-system/ButtonLink"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import Link from "@scandic-hotels/design-system/OldDSLink"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
@@ -16,40 +12,6 @@ export default async function EmptyUpcomingStays() {
|
||||
|
||||
const href = `/${lang}`
|
||||
|
||||
if (!env.NEW_STAYS_ON_MY_PAGES) {
|
||||
return (
|
||||
<section className={styles.container}>
|
||||
<div className={styles.titleContainer}>
|
||||
<Typography variant="Title/sm" className={styles.title}>
|
||||
<h3>
|
||||
{intl.formatMessage({
|
||||
id: "stays.noUpcomingStays",
|
||||
defaultMessage: "You have no upcoming stays.",
|
||||
})}
|
||||
<span className={styles.burgundyTitle}>
|
||||
{intl.formatMessage({
|
||||
id: "stays.whereToGoNext",
|
||||
defaultMessage: "Where should you go next?",
|
||||
})}
|
||||
</span>
|
||||
</h3>
|
||||
</Typography>
|
||||
</div>
|
||||
<Link
|
||||
href={href}
|
||||
className={styles.link}
|
||||
color="Text/Interactive/Secondary"
|
||||
>
|
||||
{intl.formatMessage({
|
||||
id: "stays.getInspired",
|
||||
defaultMessage: "Get inspired",
|
||||
})}
|
||||
<MaterialIcon icon="arrow_forward" color="CurrentColor" />
|
||||
</Link>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={styles.emptyUpcomingStaysContainer}>
|
||||
<Typography variant="Title/Subtitle/md">
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { LoadingSpinner } from "@scandic-hotels/design-system/LoadingSpinner"
|
||||
import { ShowMoreButton } from "@scandic-hotels/design-system/ShowMoreButton"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
|
||||
import Grids from "@/components/TempDesignSystem/Grids"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
import ListContainer from "../ListContainer"
|
||||
import OldStayCard from "../OldStayCard"
|
||||
|
||||
import type {
|
||||
UpcomingStaysClientProps,
|
||||
UpcomingStaysNonNullResponseObject,
|
||||
} from "@/types/components/myPages/stays/upcoming"
|
||||
|
||||
export default function ClientUpcomingStays({
|
||||
initialUpcomingStays,
|
||||
}: UpcomingStaysClientProps) {
|
||||
const lang = useLang()
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.upcoming.useInfiniteQuery(
|
||||
{
|
||||
limit: 6,
|
||||
lang,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => {
|
||||
return lastPage?.nextCursor
|
||||
},
|
||||
initialData: {
|
||||
pageParams: [undefined, 1],
|
||||
pages: [initialUpcomingStays],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingSpinner />
|
||||
}
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
const stays = data.pages
|
||||
.filter((page): page is UpcomingStaysNonNullResponseObject => !!page?.data)
|
||||
.flatMap((page) => page.data)
|
||||
|
||||
return stays.length ? (
|
||||
<ListContainer>
|
||||
<Grids.Stackable>
|
||||
{stays.map((stay) => (
|
||||
<OldStayCard key={stay.attributes.confirmationNumber} stay={stay} />
|
||||
))}
|
||||
</Grids.Stackable>
|
||||
{hasNextPage ? (
|
||||
<ShowMoreButton isPending={isFetching} loadMoreData={loadMoreData} />
|
||||
) : null}
|
||||
</ListContainer>
|
||||
) : null
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { env } from "@/env/server"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { Section } from "@/components/Section"
|
||||
@@ -6,8 +5,6 @@ import { SectionHeader } from "@/components/Section/Header"
|
||||
import SectionLink from "@/components/Section/Link"
|
||||
|
||||
import UpcomingStaysCarousel from "./Carousel"
|
||||
import EmptyUpcomingStays from "./EmptyUpcomingStays"
|
||||
import ClientUpcomingStays from "./OldClient"
|
||||
|
||||
import styles from "./upcoming.module.css"
|
||||
|
||||
@@ -25,26 +22,12 @@ export default async function UpcomingStays({
|
||||
const hasStays =
|
||||
initialUpcomingStays?.data && initialUpcomingStays.data.length > 0
|
||||
|
||||
if (env.NEW_STAYS_ON_MY_PAGES) {
|
||||
if (!hasStays) return null
|
||||
|
||||
return (
|
||||
<Section className={styles.container}>
|
||||
{title && <SectionHeader heading={title} link={link} />}
|
||||
<UpcomingStaysCarousel initialUpcomingStays={initialUpcomingStays} />
|
||||
<SectionLink link={link} variant="mobile" />
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
if (!hasStays) return null
|
||||
|
||||
return (
|
||||
<Section className={styles.container}>
|
||||
{title && <SectionHeader heading={title} link={link} />}
|
||||
{hasStays ? (
|
||||
<ClientUpcomingStays initialUpcomingStays={initialUpcomingStays} />
|
||||
) : (
|
||||
<EmptyUpcomingStays />
|
||||
)}
|
||||
<UpcomingStaysCarousel initialUpcomingStays={initialUpcomingStays} />
|
||||
<SectionLink link={link} variant="mobile" />
|
||||
</Section>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user