Feat(LOY-428): Previous Stays Redesign * feat(LOY-428): Previous stays WIP * fix(LOY-428): fix alignment issue * fix(LOY-428): css fixes & imagefallback prop value * fix(LOY-428): use css vars * fix(LOY-428): add unit test for relative time text * chore(LOY-428): remove else if conditions * fix(LOY-428): named exports & remove duplicate width/height setting * fix(LOY-428): better formatting of upcoming stays months text * fix(LOY-428): fewer typography wrappers Approved-by: Matilda Landström
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
"use client"
|
|
|
|
import { LoadingSpinner } from "@scandic-hotels/design-system/LoadingSpinner"
|
|
import { trpc } from "@scandic-hotels/trpc/client"
|
|
|
|
import Grids from "@/components/TempDesignSystem/Grids"
|
|
import useLang from "@/hooks/useLang"
|
|
|
|
import ListContainer from "../ListContainer"
|
|
import ShowMoreButton from "../ShowMoreButton"
|
|
import StayCard from "../StayCard"
|
|
|
|
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) => (
|
|
<StayCard key={stay.attributes.confirmationNumber} stay={stay} />
|
|
))}
|
|
</Grids.Stackable>
|
|
{hasNextPage ? (
|
|
<ShowMoreButton disabled={isFetching} loadMoreData={loadMoreData} />
|
|
) : null}
|
|
</ListContainer>
|
|
)
|
|
}
|