feat: loosen up the zod validations and return null instead of throwing
This commit is contained in:
@@ -18,4 +18,4 @@
|
||||
justify-content: center;
|
||||
min-height: 280px;
|
||||
padding: var(--Spacing-x7) var(--Spacing-x3);
|
||||
}
|
||||
}
|
||||
@@ -17,29 +17,6 @@
|
||||
grid-area: header;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--some-black-color, #000);
|
||||
font-family: var(--typography-Script-1-fontFamily);
|
||||
font-size: 1.6rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.8rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: var(--some-black-color, #000);
|
||||
font-family: var(--typography-Title-1-fontFamily);
|
||||
font-size: 1.6rem;
|
||||
font-weight: 900;
|
||||
inline-size: 18rem;
|
||||
line-height: 1.8rem;
|
||||
margin: 0;
|
||||
overflow-wrap: break-word;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.section {
|
||||
display: grid;
|
||||
gap: 0.8rem;
|
||||
@@ -121,17 +98,6 @@
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.journey .subtitle {
|
||||
font-size: 2.6rem;
|
||||
line-height: 3.2rem;
|
||||
}
|
||||
|
||||
.journey .title {
|
||||
font-size: 2.6rem;
|
||||
inline-size: 25rem;
|
||||
line-height: 3.2rem;
|
||||
}
|
||||
|
||||
.victories {
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-rows: var(--card-height) 1fr 1fr;
|
||||
@@ -139,20 +105,11 @@
|
||||
|
||||
.circle {
|
||||
align-items: center;
|
||||
background-color: var(--some-white-color, #fff);
|
||||
background-color: var(--Main-Grey-White);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
height: 2rem;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.victory .subtitle {
|
||||
font-size: 1.3rem;
|
||||
line-height: 1.6rem;
|
||||
}
|
||||
|
||||
.victory .title {
|
||||
inline-size: 13rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Image from "@/components/Image"
|
||||
import BiroScript from "@/components/TempDesignSystem/Text/BiroScript"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -25,8 +26,10 @@ export default async function Challenges({
|
||||
<section className={styles.journeys}>
|
||||
{journeys.map((journey) => (
|
||||
<article className={styles.journey} key={journey.title}>
|
||||
<p className={styles.subtitle}>{journey.tag}</p>
|
||||
<h4 className={styles.title}>{journey.title}</h4>
|
||||
<BiroScript color="black">{journey.tag}</BiroScript>
|
||||
<Title as="h5" level="h4">
|
||||
{journey.title}
|
||||
</Title>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
@@ -48,8 +51,10 @@ export default async function Challenges({
|
||||
width={12}
|
||||
/>
|
||||
</div>
|
||||
<p className={styles.subtitle}>{victory.tag}</p>
|
||||
<h4 className={styles.title}>{victory.title}</h4>
|
||||
<BiroScript color="black">{victory.tag}</BiroScript>
|
||||
<Title as="h5" level="h4">
|
||||
{victory.title}
|
||||
</Title>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
|
||||
@@ -16,6 +16,9 @@ export default async function Overview({
|
||||
title,
|
||||
}: AccountPageComponentProps) {
|
||||
const user = await serverClient().user.get()
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<section className={styles.container}>
|
||||
<Header link={link} subtitle={subtitle} title={title} topTitle />
|
||||
|
||||
@@ -16,16 +16,19 @@ async function CurrentPointsBalance({
|
||||
}: AccountPageComponentProps) {
|
||||
const user = await serverClient().user.get()
|
||||
const { formatMessage } = await getIntl()
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
const membership = getMembership(user.memberships)
|
||||
return (
|
||||
<div>
|
||||
<Header title={title} link={link} subtitle={subtitle} />
|
||||
|
||||
<div className={styles.card}>
|
||||
<h2>{`${formatMessage({ id: "Total points" })}*`}</h2>
|
||||
<p
|
||||
className={styles.points}
|
||||
>{`${formatMessage({ id: "Points" })}: ${membership?.currentPoints || "N/A"}`}</p>
|
||||
<h2>{`${formatMessage({ id: "Total Points" })}*`}</h2>
|
||||
<p className={styles.points}>
|
||||
{`${formatMessage({ id: "Points" })}: ${membership?.currentPoints || "N/A"}`}
|
||||
</p>
|
||||
<p className={styles.disclaimer}>
|
||||
{`*${formatMessage({ id: "Points may take up to 10 days to be displayed." })}`}
|
||||
</p>
|
||||
|
||||
45
components/MyPages/Blocks/Points/EarnAndBurn/Client.tsx
Normal file
45
components/MyPages/Blocks/Points/EarnAndBurn/Client.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
"use client"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import DesktopTable from "./Desktop"
|
||||
import MobileTable from "./Mobile"
|
||||
|
||||
import type {
|
||||
ClientEarnAndBurnProps,
|
||||
TransactionsObject,
|
||||
} from "@/types/components/myPages/myPage/earnAndBurn"
|
||||
|
||||
export default function ClientEarnAndBurn({
|
||||
initialData,
|
||||
lang,
|
||||
}: ClientEarnAndBurnProps) {
|
||||
/**
|
||||
* desctruct fetchNextPage, hasNextPage once pagination is
|
||||
* possible through API
|
||||
*/
|
||||
const { data } = trpc.user.transaction.friendTransactions.useInfiniteQuery(
|
||||
{ limit: 5 },
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage?.nextCursor,
|
||||
initialData: {
|
||||
pageParams: [undefined, 1],
|
||||
pages: [initialData],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// 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 filteredTransactions = (data?.pages.filter(
|
||||
(page) => page && page.data
|
||||
) ?? []) as unknown as TransactionsObject[]
|
||||
const transactions = filteredTransactions.flatMap((page) => page.data)
|
||||
return (
|
||||
<>
|
||||
<MobileTable lang={lang} transactions={transactions} />
|
||||
<DesktopTable lang={lang} transactions={transactions} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import styles from "./row.module.css"
|
||||
|
||||
import type { RowProps } from "@/types/components/myPages/myPage/earnAndBurn"
|
||||
|
||||
export default function Row({ transaction, lang }: RowProps) {
|
||||
const { formatMessage } = useIntl()
|
||||
const description =
|
||||
transaction.hotelName && transaction.city
|
||||
? `${transaction.hotelName}, ${transaction.city} ${transaction.nights} ${formatMessage({ id: "nights" })}`
|
||||
: `${transaction.nights} ${formatMessage({ id: "nights" })}`
|
||||
const arrival = dt(transaction.checkinDate).locale(lang).format("DD MMM YYYY")
|
||||
const departure = dt(transaction.checkoutDate)
|
||||
.locale(lang)
|
||||
.format("DD MMM YYYY")
|
||||
const values = [
|
||||
arrival,
|
||||
description,
|
||||
transaction.confirmationNumber,
|
||||
departure,
|
||||
transaction.awardPoints,
|
||||
]
|
||||
return (
|
||||
<tr className={styles.tr}>
|
||||
{values.map((value, idx) => (
|
||||
<td key={`value-${idx}`} className={styles.td}>
|
||||
{value}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
.tr {
|
||||
border: 1px solid #e6e9ec;
|
||||
}
|
||||
|
||||
.td {
|
||||
text-align: left;
|
||||
padding: 16px 32px;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
.container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.thead {
|
||||
background-color: var(--Main-Grey-10);
|
||||
border-left: 1px solid var(--Main-Grey-10);
|
||||
border-right: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.th {
|
||||
text-align: left;
|
||||
padding: 20px 32px;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
width: 100%;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
border: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import Row from "./Row"
|
||||
|
||||
import styles from "./desktop.module.css"
|
||||
|
||||
import type { TableProps } from "@/types/components/myPages/myPage/earnAndBurn"
|
||||
|
||||
const tableHeadings = [
|
||||
"Arrival date",
|
||||
"Description",
|
||||
"Booking number",
|
||||
"Transaction date",
|
||||
"Points",
|
||||
]
|
||||
|
||||
export default function DesktopTable({ lang, transactions }: TableProps) {
|
||||
const { formatMessage } = useIntl()
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
{transactions.length ? (
|
||||
<table className={styles.table}>
|
||||
<thead className={styles.thead}>
|
||||
<tr>
|
||||
{tableHeadings.map((heading) => (
|
||||
<th key={heading} className={styles.th}>
|
||||
{formatMessage({ id: heading })}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transactions.map((transaction) => (
|
||||
<Row
|
||||
lang={lang}
|
||||
key={transaction.confirmationNumber}
|
||||
transaction={transaction}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
// TODO: add once pagination is available through API
|
||||
// <Button
|
||||
// disabled={isFetching}
|
||||
// intent="primary"
|
||||
// bgcolor="white"
|
||||
// type="button"
|
||||
// onClick={loadMoreData}
|
||||
// >
|
||||
// {formatMessage({id:"See more transactions"})}
|
||||
// </Button>
|
||||
<table className={styles.table}>
|
||||
<thead className={styles.thead}>
|
||||
<tr>
|
||||
{tableHeadings.map((heading) => (
|
||||
<th key={heading} className={styles.th}>
|
||||
{heading}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colSpan={tableHeadings.length} className={styles.placeholder}>
|
||||
{formatMessage({ id: "No transactions available" })}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
|
||||
import styles from "./mobile.module.css"
|
||||
|
||||
import type { TableProps } from "@/types/components/myPages/myPage/earnAndBurn"
|
||||
|
||||
export default function MobileTable({ lang, transactions }: TableProps) {
|
||||
const { formatMessage } = useIntl()
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<table className={styles.table}>
|
||||
<thead className={styles.thead}>
|
||||
<tr>
|
||||
<Body asChild>
|
||||
<th className={styles.th}>
|
||||
{formatMessage({ id: "Transactions" })}
|
||||
</th>
|
||||
</Body>
|
||||
<Body asChild>
|
||||
<th className={styles.th}>{formatMessage({ id: "Points" })}</th>
|
||||
</Body>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transactions.length ? (
|
||||
transactions.map((transaction) => (
|
||||
<tr className={styles.tr} key={transaction.confirmationNumber}>
|
||||
<td className={`${styles.td} ${styles.transactionDetails}`}>
|
||||
<span className={styles.transactionDate}>
|
||||
{dt(transaction.checkinDate)
|
||||
.locale(lang)
|
||||
.format("DD MMM YYYY")}
|
||||
</span>
|
||||
{transaction.hotelName && transaction.city ? (
|
||||
<span>{`${transaction.hotelName}, ${transaction.city}`}</span>
|
||||
) : null}
|
||||
<span>
|
||||
{`${transaction.nights} ${formatMessage({ id: transaction.nights === 1 ? "night" : "nights" })}`}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
className={`${styles.mobileTd} ${styles.transactionPoints}`}
|
||||
>
|
||||
{`${transaction.awardPoints} P`}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td className={styles.placeholder} colSpan={2}>
|
||||
{formatMessage({ id: "Empty" })}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
.table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.thead {
|
||||
background-color: var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.th {
|
||||
padding: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.tr {
|
||||
border-top: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.td {
|
||||
padding: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.transactionDetails {
|
||||
display: grid;
|
||||
font-size: var(--typography-Footnote-Regular-fontSize);
|
||||
}
|
||||
|
||||
.transactionDate {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.transactionPoints {
|
||||
font-size: var(--typography-Body-Regular-fontSize);
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
text-align: center;
|
||||
padding: var(--Spacing-x4);
|
||||
border: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
.container {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@@ -2,97 +2,3 @@
|
||||
display: grid;
|
||||
gap: var(--Spacing-x3);
|
||||
}
|
||||
|
||||
.mobileTable {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mobileThead {
|
||||
background-color: var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.mobileTh {
|
||||
font-size: var(--typography-Body-Regular-fontSize);
|
||||
font-weight: 500;
|
||||
padding: var(--Spacing-x2);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.mobileTr {
|
||||
border-top: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.mobileTd {
|
||||
padding: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.mobileTransactionDetails {
|
||||
display: grid;
|
||||
font-size: var(--typography-Footnote-Regular-fontSize);
|
||||
}
|
||||
|
||||
.mobileTransactionDate {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.mobileTransactionPoints {
|
||||
font-size: var(--typography-Body-Regular-fontSize);
|
||||
}
|
||||
|
||||
.mobilePlaceholder {
|
||||
text-align: center;
|
||||
padding: var(--Spacing-x4);
|
||||
border: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.tableContainer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.thead {
|
||||
background-color: var(--Main-Grey-10);
|
||||
border-left: 1px solid var(--Main-Grey-10);
|
||||
border-right: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
.tr {
|
||||
border: 1px solid #e6e9ec;
|
||||
}
|
||||
|
||||
.th {
|
||||
text-align: left;
|
||||
padding: 20px 32px;
|
||||
}
|
||||
|
||||
.td {
|
||||
text-align: left;
|
||||
padding: 16px 32px;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
width: 100%;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
border: 1px solid var(--Main-Grey-10);
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
.mobileTableContainer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tableContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,187 +1,28 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import Header from "@/components/SectionHeader"
|
||||
|
||||
import ClientEarnAndBurn from "./Client"
|
||||
|
||||
import styles from "./earnAndBurn.module.css"
|
||||
|
||||
import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
import { Page, RowProps } from "@/types/components/myPages/myPage/earnAndBurn"
|
||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
|
||||
const tableHeadings = [
|
||||
"Arrival date",
|
||||
"Description",
|
||||
"Booking number",
|
||||
"Transaction date",
|
||||
"Points",
|
||||
]
|
||||
|
||||
function EarnAndBurn({
|
||||
export default async function EarnAndBurn({
|
||||
lang,
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
subtitle,
|
||||
title,
|
||||
}: AccountPageComponentProps) {
|
||||
const intl = useIntl()
|
||||
const { data, hasNextPage, fetchNextPage } =
|
||||
trpc.user.transaction.friendTransactions.useInfiniteQuery(
|
||||
{ limit: 5 },
|
||||
{
|
||||
getNextPageParam: (lastPage: Page) => lastPage.nextCursor,
|
||||
}
|
||||
)
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
const initialTransactions =
|
||||
await serverClient().user.transaction.friendTransactions({ limit: 5 })
|
||||
if (!initialTransactions) {
|
||||
return null
|
||||
}
|
||||
|
||||
const transactions = data?.pages.flatMap((page) => page.data) ?? []
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Header title={title} link={link} subtitle={subtitle} />
|
||||
|
||||
<div className={styles.mobileTableContainer}>
|
||||
<table className={styles.mobileTable}>
|
||||
<thead className={styles.mobileThead}>
|
||||
<tr>
|
||||
<th className={styles.mobileTh}>
|
||||
{intl.formatMessage({ id: "Transactions" })}
|
||||
</th>
|
||||
<th className={styles.mobileTh}>
|
||||
{intl.formatMessage({ id: "Points" })}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transactions.length ? (
|
||||
transactions.map((transaction) => (
|
||||
<tr
|
||||
className={styles.mobileTr}
|
||||
key={transaction.confirmationNumber}
|
||||
>
|
||||
<td
|
||||
className={`${styles.mobileTd} ${styles.mobileTransactionDetails}`}
|
||||
>
|
||||
<span className={styles.mobileTransactionDate}>
|
||||
{dt(transaction.checkinDate)
|
||||
.locale(lang)
|
||||
.format("DD MMM YYYY")}
|
||||
</span>
|
||||
{transaction.hotelName && transaction.city ? (
|
||||
<span>{`${transaction.hotelName}, ${transaction.city}`}</span>
|
||||
) : null}
|
||||
<span>
|
||||
{`${transaction.nights} ${intl.formatMessage({ id: transaction.nights === 1 ? "night" : "nights" })}`}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
className={`${styles.mobileTd} ${styles.mobileTransactionPoints}`}
|
||||
>
|
||||
{`${transaction.awardPoints} P`}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td className={styles.mobilePlaceholder} colSpan={2}>
|
||||
{intl.formatMessage({ id: "Empty" })}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className={styles.tableContainer}>
|
||||
{transactions.length ? (
|
||||
<table className={styles.table}>
|
||||
<thead className={styles.thead}>
|
||||
<tr>
|
||||
{tableHeadings.map((heading) => (
|
||||
<th key={heading} className={styles.th}>
|
||||
{intl.formatMessage({ id: heading })}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transactions.map((transaction) => (
|
||||
<Row
|
||||
lang={lang}
|
||||
key={transaction.confirmationNumber}
|
||||
transaction={transaction}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
// TODO: add once pagination is available through API
|
||||
// <Button
|
||||
// disabled={isFetching}
|
||||
// intent="primary"
|
||||
// bgcolor="white"
|
||||
// type="button"
|
||||
// onClick={loadMoreData}
|
||||
// >
|
||||
// {intl.formatMessage({id:"See more transactions"})}
|
||||
// </Button>
|
||||
<table className={styles.table}>
|
||||
<thead className={styles.thead}>
|
||||
<tr>
|
||||
{tableHeadings.map((heading) => (
|
||||
<th key={heading} className={styles.th}>
|
||||
{heading}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td
|
||||
colSpan={tableHeadings.length}
|
||||
className={styles.placeholder}
|
||||
>
|
||||
{intl.formatMessage({ id: "No transactions available" })}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
<ClientEarnAndBurn initialData={initialTransactions} lang={lang} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Row({ transaction, lang }: RowProps) {
|
||||
const intl = useIntl()
|
||||
const description =
|
||||
transaction.hotelName && transaction.city
|
||||
? `${intl.formatMessage({ id: transaction.hotelName })}, ${transaction.city} ${transaction.nights} ${intl.formatMessage({ id: "nights" })}`
|
||||
: `${transaction.nights} ${intl.formatMessage({ id: "nights" })}`
|
||||
const arrival = dt(transaction.checkinDate).locale(lang).format("DD MMM YYYY")
|
||||
const departure = dt(transaction.checkoutDate)
|
||||
.locale(lang)
|
||||
.format("DD MMM YYYY")
|
||||
const values = [
|
||||
arrival,
|
||||
description,
|
||||
transaction.confirmationNumber,
|
||||
departure,
|
||||
transaction.awardPoints,
|
||||
]
|
||||
return (
|
||||
<tr className={styles.tr}>
|
||||
{values.map((value, idx) => (
|
||||
<td key={`value-${idx}`} className={styles.td}>
|
||||
{value}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
export default EarnAndBurn
|
||||
|
||||
67
components/MyPages/Blocks/Stays/Previous/Client.tsx
Normal file
67
components/MyPages/Blocks/Stays/Previous/Client.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
"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 EmptyPreviousStaysBlock from "./EmptyPreviousStays"
|
||||
|
||||
import type {
|
||||
PreviousStaysClientProps,
|
||||
PreviousStaysNonNullResponseObject,
|
||||
} from "@/types/components/myPages/stays/previous"
|
||||
|
||||
export default function ClientPreviousStays({
|
||||
initialPreviousStays,
|
||||
lang,
|
||||
}: PreviousStaysClientProps) {
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.previous.useInfiniteQuery(
|
||||
{},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage?.nextCursor,
|
||||
initialData: {
|
||||
pageParams: [undefined, 1],
|
||||
pages: [initialPreviousStays],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
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 PreviousStaysNonNullResponseObject[]
|
||||
const stays = filteredStays.flatMap((page) => page.data)
|
||||
|
||||
return 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 />
|
||||
)
|
||||
}
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,14 +16,17 @@ export default async function SoonestStays({
|
||||
subtitle,
|
||||
link,
|
||||
}: AccountPageComponentProps) {
|
||||
const { data: stays } = await serverClient().user.stays.upcoming({ limit: 3 })
|
||||
const response = await serverClient().user.stays.upcoming({ limit: 3 })
|
||||
if (!response?.data) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={styles.container}>
|
||||
<Header title={title} subtitle={subtitle} link={link} />
|
||||
{stays.length ? (
|
||||
{response.data.length ? (
|
||||
<Grids.Stackable>
|
||||
{stays.map((stay) => (
|
||||
{response.data.map((stay) => (
|
||||
<StayCard
|
||||
key={stay.attributes.confirmationNumber}
|
||||
lang={lang}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Calendar } from "react-feather"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import { CalendarIcon } from "@/components/Icons"
|
||||
import Image from "@/components/Image"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
|
||||
import styles from "./stay.module.css"
|
||||
@@ -33,14 +33,14 @@ export default function StayCard({ stay, lang }: StayCardProps) {
|
||||
{hotelInformation.hotelName}
|
||||
</Title>
|
||||
<div className={styles.date}>
|
||||
<Calendar
|
||||
height={20}
|
||||
width={20}
|
||||
color="var(--Scandic-Brand-Burgundy)"
|
||||
/>
|
||||
<time dateTime={arrivalDateTime}>{arrivalDate}</time>
|
||||
<CalendarIcon color="burgundy" />
|
||||
<Caption asChild>
|
||||
<time dateTime={arrivalDateTime}>{arrivalDate}</time>
|
||||
</Caption>
|
||||
{" - "}
|
||||
<time dateTime={departDateTime}>{departDate}</time>
|
||||
<Caption asChild>
|
||||
<time dateTime={departDateTime}>{departDate}</time>
|
||||
</Caption>
|
||||
</div>
|
||||
</footer>
|
||||
</article>
|
||||
|
||||
@@ -36,8 +36,4 @@
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--Spacing-x-half);
|
||||
font-family: var(--typography-Caption-Regular-fontFamily);
|
||||
font-size: var(--typography-Caption-Regular-fontSize);
|
||||
font-weight: var(--typography-Caption-Regular-fontWeight);
|
||||
line-height: var(--typography-Caption-Regular-lineHeight);
|
||||
}
|
||||
|
||||
67
components/MyPages/Blocks/Stays/Upcoming/Client.tsx
Normal file
67
components/MyPages/Blocks/Stays/Upcoming/Client.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
"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 EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"
|
||||
|
||||
import type {
|
||||
UpcomingStaysClientProps,
|
||||
UpcomingStaysNonNullResponseObject,
|
||||
} from "@/types/components/myPages/stays/upcoming"
|
||||
|
||||
export default function ClientUpcomingStays({
|
||||
initialUpcomingStays,
|
||||
lang,
|
||||
}: UpcomingStaysClientProps) {
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
trpc.user.stays.upcoming.useInfiniteQuery(
|
||||
{},
|
||||
{
|
||||
getNextPageParam: (lastPage) => 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}
|
||||
lang={lang}
|
||||
stay={stay}
|
||||
/>
|
||||
))}
|
||||
</Grids.Stackable>
|
||||
{hasNextPage ? (
|
||||
<ShowMoreButton disabled={isFetching} loadMoreData={loadMoreData} />
|
||||
) : null}
|
||||
</ListContainer>
|
||||
) : (
|
||||
<EmptyUpcomingStaysBlock />
|
||||
)
|
||||
}
|
||||
@@ -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 EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"
|
||||
import ClientUpcomingStays from "./Client"
|
||||
|
||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
|
||||
export default function UpcomingStays({
|
||||
export default async function UpcomingStays({
|
||||
lang,
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
}: AccountPageComponentProps) {
|
||||
const { data, hasNextPage, isFetching, fetchNextPage, isLoading } =
|
||||
trpc.user.stays.upcoming.useInfiniteQuery(
|
||||
{ limit: 6 },
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
}
|
||||
)
|
||||
|
||||
function loadMoreData() {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
const initialUpcomingStays = await serverClient().user.stays.upcoming()
|
||||
if (!initialUpcomingStays?.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>
|
||||
) : (
|
||||
<EmptyUpcomingStaysBlock />
|
||||
)}
|
||||
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
||||
<ClientUpcomingStays
|
||||
initialUpcomingStays={initialUpcomingStays}
|
||||
lang={lang}
|
||||
/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { ChevronRightIcon , HouseIcon } from "@/components/Icons"
|
||||
import { ChevronRightIcon, HouseIcon } from "@/components/Icons"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||
|
||||
@@ -8,6 +8,9 @@ import styles from "./breadcrumbs.module.css"
|
||||
|
||||
export default async function Breadcrumbs() {
|
||||
const breadcrumbs = await serverClient().contentstack.breadcrumbs.get()
|
||||
if (!breadcrumbs) {
|
||||
return null
|
||||
}
|
||||
const homeBreadcrumb = breadcrumbs.shift()
|
||||
return (
|
||||
<nav className={styles.breadcrumbs}>
|
||||
|
||||
@@ -15,6 +15,9 @@ import type { LangParams } from "@/types/params"
|
||||
export default async function Sidebar({ lang }: LangParams) {
|
||||
const navigation = await serverClient().contentstack.myPages.navigation.get()
|
||||
const { formatMessage } = await getIntl()
|
||||
if (!navigation) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<aside className={styles.sidebar}>
|
||||
<nav className={styles.nav}>
|
||||
|
||||
Reference in New Issue
Block a user