diff --git a/components/MyPages/Blocks/Stays/Previous/index.tsx b/components/MyPages/Blocks/Stays/Previous/index.tsx index f4416fba2..80da14fe5 100644 --- a/components/MyPages/Blocks/Stays/Previous/index.tsx +++ b/components/MyPages/Blocks/Stays/Previous/index.tsx @@ -27,19 +27,20 @@ export default function PreviousStays({ ) function loadMoreData() { - fetchNextPage() + if (hasNextPage) { + fetchNextPage() + } } + const stays = data?.pages.flatMap((page) => page.data) ?? [] + return (
- {data?.pages.length ? ( + {stays.length ? ( - page.data) ?? []} - /> + {hasNextPage ? ( ) : null} diff --git a/components/MyPages/Blocks/Stays/Upcoming/index.tsx b/components/MyPages/Blocks/Stays/Upcoming/index.tsx index c33dedcbe..887107ead 100644 --- a/components/MyPages/Blocks/Stays/Upcoming/index.tsx +++ b/components/MyPages/Blocks/Stays/Upcoming/index.tsx @@ -33,16 +33,15 @@ export default function UpcomingStays({ } } + const stays = data?.pages.flatMap((page) => page.data) ?? [] + return (
- {data?.pages.length ? ( + {stays.length ? ( - page.data) ?? []} - /> + {hasNextPage ? ( ) : null} diff --git a/server/routers/user/output.ts b/server/routers/user/output.ts index 1e21dd73d..269fd96ec 100644 --- a/server/routers/user/output.ts +++ b/server/routers/user/output.ts @@ -78,14 +78,16 @@ export const getStaysSchema = z.object({ }), }) ), - links: z.object({ - self: z.string(), - offset: z.number(), - limit: z.number(), - totalCount: z.number(), - }), + links: z + .object({ + self: z.string(), + offset: z.number(), + limit: z.number(), + totalCount: z.number(), + }) + .nullable(), }) -type GetStaysData = z.infer +export type GetStaysData = z.infer -export type Stay = GetStaysData["data"][number] +export type Stay = GetStaysData["data"][0] diff --git a/server/routers/user/query.ts b/server/routers/user/query.ts index e6c90f610..64478860b 100644 --- a/server/routers/user/query.ts +++ b/server/routers/user/query.ts @@ -1,5 +1,3 @@ -import { z } from "zod" - import * as api from "@/lib/api" import { badRequestError, @@ -43,6 +41,7 @@ export const userQueryRouter = router({ } const apiJson = await apiResponse.json() + if (!apiJson.data?.length) { throw internalServerError() } @@ -113,7 +112,7 @@ export const userQueryRouter = router({ } const apiJson = await apiResponse.json() - if (!apiJson.data?.length) { + if (!apiJson.data) { console.error(`Get Previous Stays - No data found from api call`) throw internalServerError() } @@ -127,6 +126,7 @@ export const userQueryRouter = router({ } const nextCursor = + verifiedData.data.links && verifiedData.data.links.offset < verifiedData.data.links.totalCount ? verifiedData.data.links.offset : undefined @@ -177,7 +177,7 @@ export const userQueryRouter = router({ } const apiJson = await apiResponse.json() - if (!apiJson.data?.length) { + if (!apiJson.data) { console.error(`Get Upcoming Stays - No data found from api call`) throw internalServerError() } @@ -191,6 +191,7 @@ export const userQueryRouter = router({ } const nextCursor = + verifiedData.data.links && verifiedData.data.links.offset < verifiedData.data.links.totalCount ? verifiedData.data.links.offset : undefined diff --git a/server/routers/user/temp.ts b/server/routers/user/temp.ts index 1d10371fc..5d9b48657 100644 --- a/server/routers/user/temp.ts +++ b/server/routers/user/temp.ts @@ -1,5 +1,3 @@ -import { randomUUID } from "crypto" - export const benefits = [ { id: 1, @@ -71,6 +69,10 @@ export const nextLevelPerks = { id: 3, explanation: "25% extra bonus points on each stay", }, + { + id: 4, + explanation: "25% extra bonus points on each stay", + }, ], } @@ -113,180 +115,6 @@ export const shortcuts = [ // }, ] -export const previousStays = [ - { - uid: randomUUID(), - dateArrive: new Date("04 27 2024"), - dateDepart: new Date("04 28 2024"), - guests: 2, - hotel: "Scandic Helsinki Hub", - }, - { - uid: randomUUID(), - dateArrive: new Date("05 27 2024"), - dateDepart: new Date("05 28 2024"), - guests: 2, - hotel: "Scandic Örebro Central", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Oslo City", - }, - { - uid: randomUUID(), - dateArrive: new Date("04 27 2024"), - dateDepart: new Date("04 28 2024"), - guests: 2, - hotel: "Scandic Lorem", - }, - { - uid: randomUUID(), - dateArrive: new Date("05 27 2024"), - dateDepart: new Date("05 28 2024"), - guests: 2, - hotel: "Scandic Ipsum", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Dolor Sin Amet", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Anglais", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Park", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Klara", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Järva Krog", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Kiruna", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Umeå", - }, -] - -export const upcomingStays = [ - { - uid: randomUUID(), - dateArrive: new Date("04 27 2024"), - dateDepart: new Date("04 28 2024"), - guests: 2, - hotel: "Scandic Helsinki Hub", - }, - { - uid: randomUUID(), - dateArrive: new Date("05 27 2024"), - dateDepart: new Date("05 28 2024"), - guests: 2, - hotel: "Scandic Örebro Central", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Oslo City", - }, - { - uid: randomUUID(), - dateArrive: new Date("04 27 2024"), - dateDepart: new Date("04 28 2024"), - guests: 2, - hotel: "Scandic Lorem", - }, - { - uid: randomUUID(), - dateArrive: new Date("05 27 2024"), - dateDepart: new Date("05 28 2024"), - guests: 2, - hotel: "Scandic Ipsum", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Dolor Sin Amet", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Anglais", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Park", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Klara", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Järva Krog", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Kiruna", - }, - { - uid: randomUUID(), - dateArrive: new Date("06 27 2024"), - dateDepart: new Date("06 28 2024"), - guests: 2, - hotel: "Scandic Umeå", - }, -] - export const extendedUser = { journeys: challenges.journeys, nights: 14,