feat: loosen up the zod validations and return null instead of throwing
This commit is contained in:
@@ -1,64 +1,29 @@
|
||||
"use client"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import Header from "@/components/SectionHeader"
|
||||
import Grids from "@/components/TempDesignSystem/Grids"
|
||||
import SectionHeader from "@/components/SectionHeader"
|
||||
|
||||
import Container from "../Container"
|
||||
import ListContainer from "../ListContainer"
|
||||
import ShowMoreButton from "../ShowMoreButton"
|
||||
import StayCard from "../StayCard"
|
||||
import EmptyPreviousStaysBlock from "./EmptyPreviousStays"
|
||||
import ClientPreviousStays from "./Client"
|
||||
|
||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
|
||||
export default function PreviousStays({
|
||||
export default async function PreviousStays({
|
||||
lang,
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
}: AccountPageComponentProps) {
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.previous.useInfiniteQuery(
|
||||
{},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
}
|
||||
)
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
const initialPreviousStays = await serverClient().user.stays.previous()
|
||||
if (!initialPreviousStays?.data) {
|
||||
return null
|
||||
}
|
||||
|
||||
const stays = data?.pages.flatMap((page) => page.data) ?? []
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Header title={title} subtitle={subtitle} link={link} />
|
||||
{isLoading ? (
|
||||
<LoadingSpinner />
|
||||
) : stays.length ? (
|
||||
<ListContainer>
|
||||
<Grids.Stackable>
|
||||
{stays.map((stay) => (
|
||||
<StayCard
|
||||
key={stay.attributes.confirmationNumber}
|
||||
lang={lang}
|
||||
stay={stay}
|
||||
/>
|
||||
))}
|
||||
</Grids.Stackable>
|
||||
{hasNextPage ? (
|
||||
<ShowMoreButton disabled={isFetching} loadMoreData={loadMoreData} />
|
||||
) : null}
|
||||
</ListContainer>
|
||||
) : (
|
||||
<EmptyPreviousStaysBlock />
|
||||
)}
|
||||
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
||||
<ClientPreviousStays
|
||||
initialPreviousStays={initialPreviousStays}
|
||||
lang={lang}
|
||||
/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user