feat: add initial mobile layout for earn and burn

This commit is contained in:
Arvid Norlin
2024-05-22 16:41:37 +02:00
parent 90bd302715
commit 672b1176d6
5 changed files with 159 additions and 83 deletions

View File

@@ -35,13 +35,13 @@ function DynamicComponent({ component, props }: AccountPageContentProps) {
case DynamicContentComponents.next_benefits: case DynamicContentComponents.next_benefits:
return <NextLevelBenefitsBlock {...props} /> return <NextLevelBenefitsBlock {...props} />
case DynamicContentComponents.my_points: case DynamicContentComponents.my_points:
return <CurrentPointsBalance /> return <CurrentPointsBalance {...props} />
case DynamicContentComponents.expiring_points: case DynamicContentComponents.expiring_points:
// TODO: Add once available // TODO: Add once available
// return <ExpiringPoints /> // return <ExpiringPoints />
return null return null
case DynamicContentComponents.earn_and_burn: case DynamicContentComponents.earn_and_burn:
return <EarnAndBurn lang={props.lang} /> return <EarnAndBurn {...props} />
default: default:
return null return null
} }

View File

@@ -1,14 +1,14 @@
.card { .card {
background-color: var(--Base-Fill-Normal); background-color: var(--Main-Grey-10);
border-radius: 16px; border-radius: var(--Corner-radius-xLarge);
color: var(--Theme-Primary-Light-On-Surface-Text); color: var(--Main-Brand-Burgundy);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 16px; gap: var(--Spacing-x2);
} }
.points { .points {
font-size: var(--typography-Title2-Desktop-fontSize); font-size: var(--typography-Title-2-Desktop-fontSize);
margin: 0; margin: 0;
} }

View File

@@ -1,19 +1,32 @@
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import { serverClient } from "@/lib/trpc/server" import { serverClient } from "@/lib/trpc/server"
import Header from "@/components/MyPages/Blocks/Header"
import styles from "./currentPointsBalance.module.css" import styles from "./currentPointsBalance.module.css"
async function CurrentPointsBalance() { import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
async function CurrentPointsBalance({
title,
subtitle,
link,
lang,
}: AccountPageComponentProps) {
const user = await serverClient().user.get() const user = await serverClient().user.get()
return ( return (
<div className={styles.card}> <div>
<h2>{`${_("Total points")}*`}</h2> <Header title={title} link={link} subtitle={subtitle} />
<p
className={styles.points} <div className={styles.card}>
>{`${_("Points")}: ${user.membership?.currentPoints || "N/A"}`}</p> <h2>{`${_("Total points")}*`}</h2>
<p className={styles.disclaimer}> <p
{`*${_("Points may take up to 10 days to be displayed.")}`} className={styles.points}
</p> >{`${_("Points")}: ${user.membership?.currentPoints || "N/A"}`}</p>
<p className={styles.disclaimer}>
{`*${_("Points may take up to 10 days to be displayed.")}`}
</p>
</div>
</div> </div>
) )
} }

View File

@@ -1,8 +1,29 @@
.container { .container {
display: flex; display: grid;
flex-direction: column; gap: var(--Spacing-x3);
gap: 16px; }
overflow-x: auto;
.mobileTable {
border-spacing: 0;
width: 100%;
}
.mobileThead {
background-color: var(--Main-Grey-10);
}
.mobileTh {
padding: var(--Spacing-x2);
}
.mobilePlaceholder {
text-align: center;
padding: var(--Spacing-x4);
border: 1px solid var(--Main-Grey-10);
}
.tableContainer {
display: none;
} }
.table { .table {
@@ -12,9 +33,9 @@
} }
.thead { .thead {
background-color: var(--Base-Fill-Normal); background-color: var(--Main-Grey-10);
border-left: 1px solid var(--Base-Fill-Normal); border-left: 1px solid var(--Main-Grey-10);
border-right: 1px solid var(--Base-Fill-Normal); border-right: 1px solid var(--Main-Grey-10);
} }
.tr { .tr {
@@ -35,5 +56,18 @@
width: 100%; width: 100%;
padding: 24px; padding: 24px;
text-align: center; text-align: center;
border: 1px solid var(--Base-Fill-Normal); border: 1px solid var(--Main-Grey-10);
}
@media screen and (min-width: 950px) {
.mobileTableContainer {
display: none;
}
.tableContainer {
display: flex;
flex-direction: column;
gap: 16px;
overflow-x: auto;
}
} }

View File

@@ -4,15 +4,13 @@ import { dt } from "@/lib/dt"
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import { trpc } from "@/lib/trpc/client" import { trpc } from "@/lib/trpc/client"
import Header from "@/components/MyPages/Blocks/Header"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
import styles from "./earnAndBurn.module.css" import styles from "./earnAndBurn.module.css"
import { import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
EarnAndBurnProps, import { Page, RowProps } from "@/types/components/myPages/myPage/earnAndBurn"
Page,
RowProps,
} from "@/types/components/myPages/myPage/earnAndBurn"
const tableHeadings = [ const tableHeadings = [
_("Arrival date"), _("Arrival date"),
@@ -22,7 +20,12 @@ const tableHeadings = [
_("Points"), _("Points"),
] ]
function EarnAndBurn({ lang }: EarnAndBurnProps) { function EarnAndBurn({
lang,
title,
subtitle,
link,
}: AccountPageComponentProps) {
const { data, hasNextPage, isFetching, fetchNextPage } = const { data, hasNextPage, isFetching, fetchNextPage } =
trpc.user.transaction.friendTransactions.useInfiniteQuery( trpc.user.transaction.friendTransactions.useInfiniteQuery(
{ limit: 5 }, { limit: 5 },
@@ -38,59 +41,85 @@ function EarnAndBurn({ lang }: EarnAndBurnProps) {
} }
const transactions = data?.pages.flatMap((page) => page.data) ?? [] const transactions = data?.pages.flatMap((page) => page.data) ?? []
return transactions.length ? ( return (
<div className={styles.container}> <div>
<table className={styles.table}> <Header title={title} link={link} subtitle={subtitle} />
<thead className={styles.thead}>
<tr> <div className={styles.mobileTableContainer}>
{tableHeadings.map((heading) => ( <table className={styles.mobileTable}>
<th key={heading} className={styles.th}> <thead className={styles.mobileThead}>
{heading} <th className={styles.mobileTh}>{_("Transactions")}</th>
</th> <th className={styles.mobileTh}>{_("Points")}</th>
))} </thead>
</tr> <tbody>
</thead> {transactions.length ? (
<tbody> transactions.map((transaction) => (
{transactions.map((transaction) => ( <tr key={transaction.confirmationNumber}>
<Row <td>{transaction.hotelName}</td>
lang={lang} <td>{transaction.awardPoints}</td>
key={transaction.confirmationNumber} </tr>
transaction={transaction} ))
/> ) : (
))} <tr>
</tbody> <td className={styles.mobilePlaceholder} colSpan={2}>
</table> Empty
{/* TODO: add once pagination is available through API */} </td>
{/* <Button </tr>
disabled={isFetching} )}
intent="primary" </tbody>
bgcolor="white" </table>
type="button" </div>
onClick={loadMoreData} <div className={styles.tableContainer}>
> {transactions.length ? (
{_("See more transactions")} <table className={styles.table}>
</Button> */} <thead className={styles.thead}>
</div> <tr>
) : ( {tableHeadings.map((heading) => (
<div className={styles.container}> <th key={heading} className={styles.th}>
<table className={styles.table}> {heading}
<thead className={styles.thead}> </th>
<tr> ))}
{tableHeadings.map((heading) => ( </tr>
<th key={heading} className={styles.th}> </thead>
{heading} <tbody>
</th> {transactions.map((transaction) => (
))} <Row
</tr> lang={lang}
</thead> key={transaction.confirmationNumber}
<tbody> transaction={transaction}
<tr> />
<td colSpan={tableHeadings.length} className={styles.placeholder}> ))}
{_("No transactions available")} </tbody>
</td> </table>
</tr> ) : (
</tbody> // TODO: add once pagination is available through API
</table> // <Button
// disabled={isFetching}
// intent="primary"
// bgcolor="white"
// type="button"
// onClick={loadMoreData}
// >
// {_("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>
<tr>
<td colSpan={tableHeadings.length} className={styles.placeholder}>
{_("No transactions available")}
</td>
</tr>
</table>
)}
</div>
</div> </div>
) )
} }