feat(SW-66, SW-348): search functionality and ui
This commit is contained in:
63
components/Blocks/DynamicContent/Stays/Upcoming/Client.tsx
Normal file
63
components/Blocks/DynamicContent/Stays/Upcoming/Client.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
"use client"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import Grids from "@/components/TempDesignSystem/Grids"
|
||||
|
||||
import ListContainer from "../ListContainer"
|
||||
import ShowMoreButton from "../ShowMoreButton"
|
||||
import StayCard from "../StayCard"
|
||||
|
||||
import type {
|
||||
UpcomingStaysClientProps,
|
||||
UpcomingStaysNonNullResponseObject,
|
||||
} from "@/types/components/myPages/stays/upcoming"
|
||||
|
||||
export default function ClientUpcomingStays({
|
||||
initialUpcomingStays,
|
||||
}: UpcomingStaysClientProps) {
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.upcoming.useInfiniteQuery(
|
||||
{
|
||||
limit: 6,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => {
|
||||
return lastPage?.nextCursor
|
||||
},
|
||||
initialData: {
|
||||
pageParams: [undefined, 1],
|
||||
pages: [initialUpcomingStays],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
// TS having a hard time with the filtered type.
|
||||
// This is only temporary as we will not return null
|
||||
// later on when we handle errors appropriately.
|
||||
const filteredStays = (data?.pages.filter((page) => page && page.data) ??
|
||||
[]) as unknown as UpcomingStaysNonNullResponseObject[]
|
||||
const stays = filteredStays.flatMap((page) => page.data)
|
||||
|
||||
return isLoading ? (
|
||||
<LoadingSpinner />
|
||||
) : stays.length ? (
|
||||
<ListContainer>
|
||||
<Grids.Stackable>
|
||||
{stays.map((stay) => (
|
||||
<StayCard key={stay.attributes.confirmationNumber} stay={stay} />
|
||||
))}
|
||||
</Grids.Stackable>
|
||||
{hasNextPage ? (
|
||||
<ShowMoreButton disabled={isFetching} loadMoreData={loadMoreData} />
|
||||
) : null}
|
||||
</ListContainer>
|
||||
) : null
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
.container {
|
||||
display: grid;
|
||||
grid-template-rows: 1fr min(50px);
|
||||
background-color: var(--Base-Surface-Primary-light-Normal);
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
min-height: 250px;
|
||||
margin-bottom: var(--Spacing-x-half);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.titleContainer {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: var(--Scandic-Brand-Pale-Peach);
|
||||
}
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.burgundyTitle {
|
||||
color: var(--Scandic-Brand-Burgundy);
|
||||
}
|
||||
|
||||
.link {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { homeHrefs } from "@/constants/homeHrefs"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { ArrowRightIcon } from "@/components/Icons"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import styles from "./emptyUpcomingStays.module.css"
|
||||
|
||||
export default async function EmptyUpcomingStaysBlock() {
|
||||
const { formatMessage } = await getIntl()
|
||||
return (
|
||||
<section className={styles.container}>
|
||||
<div className={styles.titleContainer}>
|
||||
<Title as="h5" level="h3" color="red" className={styles.title}>
|
||||
{formatMessage({ id: "You have no upcoming stays." })}
|
||||
<span className={styles.burgundyTitle}>
|
||||
{formatMessage({ id: "Where should you go next?" })}
|
||||
</span>
|
||||
</Title>
|
||||
</div>
|
||||
<Link
|
||||
href={homeHrefs[env.NODE_ENV][getLang()]}
|
||||
className={styles.link}
|
||||
color="peach80"
|
||||
>
|
||||
{formatMessage({ id: "Get inspired" })}
|
||||
<ArrowRightIcon color="peach80" />
|
||||
</Link>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
34
components/Blocks/DynamicContent/Stays/Upcoming/index.tsx
Normal file
34
components/Blocks/DynamicContent/Stays/Upcoming/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import SectionContainer from "@/components/Section/Container"
|
||||
import SectionHeader from "@/components/Section/Header"
|
||||
import SectionLink from "@/components/Section/Link"
|
||||
|
||||
import ClientUpcomingStays from "./Client"
|
||||
import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"
|
||||
|
||||
import styles from "./upcoming.module.css"
|
||||
|
||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
|
||||
export default async function UpcomingStays({
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
}: AccountPageComponentProps) {
|
||||
const initialUpcomingStays = await serverClient().user.stays.upcoming({
|
||||
limit: 6,
|
||||
})
|
||||
|
||||
return (
|
||||
<SectionContainer className={styles.container}>
|
||||
<SectionHeader title={title} preamble={subtitle} link={link} />
|
||||
{initialUpcomingStays?.data.length ? (
|
||||
<ClientUpcomingStays initialUpcomingStays={initialUpcomingStays} />
|
||||
) : (
|
||||
<EmptyUpcomingStaysBlock />
|
||||
)}
|
||||
<SectionLink link={link} variant="mobile" />
|
||||
</SectionContainer>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.container {
|
||||
display: inline-grid;
|
||||
}
|
||||
Reference in New Issue
Block a user