Feat/SW-1276 implement design * feat(SW-1276) UI implementation Desktop part 1 for MyStay * feat(SW-1276) UI implementation Desktop part 2 for MyStay * feat(SW-1276) UI implementation Mobile part 1 for MyStay * refactor: move files from MyStay/MyStay to MyStay * feat(SW-1276) Sidepeek implementation * feat(SW-1276): Refactoring * feat(SW-1276) UI implementation Mobile part 2 for MyStay * feat(SW-1276): translations * feat(SW-1276) fixed skeleton * feat(SW-1276): Added missing translations * feat(SW-1276): Removed console log * feat(SW-1276) fixed translations * feat(SW-1276): Added translations * feat(SW-1276) fix dynamic ID:s * feat(SW-1276) removed createElement * feat(SW-1276): Fixed build errors * feat(SW-1276): Updated label * feat(SW-1276): Rewrite SummaryCard Approved-by: Niclas Edenvin
121 lines
4.0 KiB
TypeScript
121 lines
4.0 KiB
TypeScript
"use client"
|
|
import { useState } from "react"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { Carousel } from "@/components/Carousel"
|
|
import { ChevronRightSmallIcon } from "@/components/Icons"
|
|
import Modal from "@/components/Modal"
|
|
import { AncillaryCard } from "@/components/TempDesignSystem/AncillaryCard"
|
|
import Button from "@/components/TempDesignSystem/Button"
|
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|
import Title from "@/components/TempDesignSystem/Text/Title"
|
|
|
|
import styles from "./ancillaries.module.css"
|
|
|
|
import type {
|
|
Ancillaries,
|
|
AncillariesProps,
|
|
Ancillary,
|
|
} from "@/types/components/myPages/myStay/ancillaries"
|
|
|
|
export function Ancillaries({ ancillaries }: AncillariesProps) {
|
|
const intl = useIntl()
|
|
const [selectedCategory, setSelectedCategory] = useState<string | null>(
|
|
() => {
|
|
return ancillaries?.[0]?.categoryName ?? null
|
|
}
|
|
)
|
|
|
|
if (!ancillaries?.length) {
|
|
return null
|
|
}
|
|
|
|
function mergeAncillaries(
|
|
ancillaries: Ancillaries
|
|
): Ancillary["ancillaryContent"] {
|
|
const uniqueAncillaries = new Map(
|
|
ancillaries
|
|
.flatMap((category) => category.ancillaryContent)
|
|
.map((ancillary) => [ancillary.id, ancillary])
|
|
)
|
|
return [...uniqueAncillaries.values()]
|
|
}
|
|
|
|
const allAncillaries = mergeAncillaries(ancillaries)
|
|
|
|
return (
|
|
<div className={styles.container}>
|
|
<div className={styles.title}>
|
|
<Title as="h5">{intl.formatMessage({ id: "Upgrade your stay" })}</Title>
|
|
<div className={styles.modal}>
|
|
<Modal
|
|
trigger={
|
|
<Button theme="base" variant="icon" intent="text" size="small">
|
|
{intl.formatMessage({ id: "View all" })}
|
|
<ChevronRightSmallIcon
|
|
width={20}
|
|
height={20}
|
|
color="baseButtonTextOnFillNormal"
|
|
/>
|
|
</Button>
|
|
}
|
|
title={intl.formatMessage({ id: "Upgrade your stay" })}
|
|
>
|
|
<div className={styles.modalContent}>
|
|
<div className={styles.tabs}>
|
|
{ancillaries.map((category) => (
|
|
<button
|
|
key={category.categoryName}
|
|
className={`${styles.chip} ${category.categoryName === selectedCategory ? styles.selected : ""}`}
|
|
onClick={() => setSelectedCategory(category.categoryName)}
|
|
>
|
|
<Caption
|
|
color={
|
|
category.categoryName === selectedCategory
|
|
? "pale"
|
|
: "baseTextHighContrast"
|
|
}
|
|
>
|
|
{category.categoryName}
|
|
</Caption>
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
<div className={styles.grid}>
|
|
{ancillaries
|
|
.find(
|
|
(category) => category.categoryName === selectedCategory
|
|
)
|
|
?.ancillaryContent.map(({ description, ...ancillary }) => (
|
|
<AncillaryCard key={ancillary.id} ancillary={ancillary} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={styles.ancillaries}>
|
|
{allAncillaries.slice(0, 4).map(({ description, ...ancillary }) => (
|
|
<AncillaryCard key={ancillary.id} ancillary={ancillary} />
|
|
))}
|
|
</div>
|
|
<div className={styles.mobileAncillaries}>
|
|
<Carousel>
|
|
<Carousel.Content className={styles.carouselContainer}>
|
|
{allAncillaries.map(({ description, ...ancillary }) => (
|
|
<Carousel.Item key={ancillary.id}>
|
|
<AncillaryCard key={ancillary.id} ancillary={ancillary} />
|
|
</Carousel.Item>
|
|
))}
|
|
</Carousel.Content>
|
|
<Carousel.Previous className={styles.navigationButton} />
|
|
<Carousel.Next className={styles.navigationButton} />
|
|
<Carousel.Dots />
|
|
</Carousel>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|