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,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 {
|
||||
PreviousStaysClientProps,
|
||||
PreviousStaysNonNullResponseObject,
|
||||
} from "@/types/components/myPages/stays/previous"
|
||||
|
||||
export function ClientPreviousStays({
|
||||
initialPreviousStays,
|
||||
}: PreviousStaysClientProps) {
|
||||
const lang = useLang()
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.previous.useInfiniteQuery(
|
||||
{
|
||||
limit: 6,
|
||||
lang,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => {
|
||||
return lastPage?.nextCursor
|
||||
},
|
||||
initialData: {
|
||||
pageParams: [undefined, 1],
|
||||
pages: [initialPreviousStays],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingSpinner />
|
||||
}
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
const stays = data.pages
|
||||
.filter((page): page is PreviousStaysNonNullResponseObject => !!page?.data)
|
||||
.flatMap((page) => page.data)
|
||||
|
||||
return (
|
||||
<ListContainer>
|
||||
<Grids.Stackable>
|
||||
{stays.map((stay) => (
|
||||
<OldStayCard key={stay.attributes.confirmationNumber} stay={stay} />
|
||||
))}
|
||||
</Grids.Stackable>
|
||||
{hasNextPage ? (
|
||||
<ShowMoreButton isPending={isFetching} loadMoreData={loadMoreData} />
|
||||
) : null}
|
||||
</ListContainer>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { env } from "@/env/server"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import ClaimPoints from "@/components/Blocks/DynamicContent/Points/ClaimPoints"
|
||||
@@ -9,7 +8,6 @@ import SectionLink from "@/components/Section/Link"
|
||||
import { Cards } from "./Cards"
|
||||
import { INITIAL_STAYS_FETCH_LIMIT } from "./data"
|
||||
import { L6Progress } from "./L6Progress"
|
||||
import { ClientPreviousStays } from "./OldClient"
|
||||
|
||||
import styles from "./previous.module.css"
|
||||
|
||||
@@ -28,16 +26,14 @@ export default async function PreviousStays({
|
||||
return null
|
||||
}
|
||||
|
||||
const StaysComponent = env.NEW_STAYS_ON_MY_PAGES ? Cards : ClientPreviousStays
|
||||
|
||||
return (
|
||||
<Section>
|
||||
<div className={styles.header}>
|
||||
<SectionHeader heading={title ?? undefined} link={link} />
|
||||
<ClaimPoints />
|
||||
</div>
|
||||
{env.NEW_STAYS_ON_MY_PAGES ? <L6Progress /> : null}
|
||||
<StaysComponent initialPreviousStays={initialPreviousStays} />
|
||||
<L6Progress />
|
||||
<Cards initialPreviousStays={initialPreviousStays} />
|
||||
<SectionLink link={link} variant="mobile" />
|
||||
</Section>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user