Merged in fix/sw-2091-remove-breakfast (pull request #1689)
fix(SW-2091): remove breakfast ancillaries * fix(SW-2091): remove breakfast ancillaries * Send array in correct format * Break out function Approved-by: Bianca Widstam
This commit is contained in:
@@ -11,12 +11,12 @@ import useLang from "@/hooks/useLang"
|
|||||||
|
|
||||||
export default function RemoveButton({
|
export default function RemoveButton({
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
code,
|
codes,
|
||||||
title,
|
title,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}: {
|
}: {
|
||||||
confirmationNumber: string
|
confirmationNumber: string
|
||||||
code: string
|
codes: string[]
|
||||||
title?: string
|
title?: string
|
||||||
onSuccess: () => void
|
onSuccess: () => void
|
||||||
}) {
|
}) {
|
||||||
@@ -44,7 +44,7 @@ export default function RemoveButton({
|
|||||||
{
|
{
|
||||||
language: lang,
|
language: lang,
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
codes: [code],
|
codes,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useMemo } from "react"
|
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons"
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons"
|
||||||
@@ -18,7 +17,10 @@ import styles from "./addedAncillaries.module.css"
|
|||||||
|
|
||||||
import type { AddedAncillariesProps } from "@/types/components/myPages/myStay/ancillaries"
|
import type { AddedAncillariesProps } from "@/types/components/myPages/myStay/ancillaries"
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
import type { PackageSchema } from "@/types/trpc/routers/booking/confirmation"
|
import type {
|
||||||
|
BookingConfirmation,
|
||||||
|
PackageSchema,
|
||||||
|
} from "@/types/trpc/routers/booking/confirmation"
|
||||||
|
|
||||||
export function AddedAncillaries({
|
export function AddedAncillaries({
|
||||||
ancillaries,
|
ancillaries,
|
||||||
@@ -27,42 +29,11 @@ export function AddedAncillaries({
|
|||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
/**
|
const addedBreakfastPackages = getBreakfastPackagesFromAncillaryFlow(
|
||||||
* All ancillaries that are added to the booking
|
booking.packages
|
||||||
*
|
)
|
||||||
* Adding a special ancillary for breakfast, calculated from
|
|
||||||
* all breakfast packages that has been added as ancillaries,
|
|
||||||
* not in the booking flow.
|
|
||||||
*/
|
|
||||||
const addedAncillaries = useMemo(() => {
|
|
||||||
const addedBreakfastPackages = getBreakfastPackagesFromAncillaryFlow(
|
|
||||||
booking.packages
|
|
||||||
)
|
|
||||||
if (!addedBreakfastPackages?.length) {
|
|
||||||
return booking.ancillaries
|
|
||||||
}
|
|
||||||
|
|
||||||
const combinedBreakfastPackageAsAncillary: PackageSchema = {
|
const addedAncillaries = getAddedAncillaries(booking, addedBreakfastPackages)
|
||||||
code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
|
|
||||||
unitPrice: 0,
|
|
||||||
points: 0,
|
|
||||||
currency: addedBreakfastPackages[0].currency,
|
|
||||||
type: addedBreakfastPackages[0].type,
|
|
||||||
description: addedBreakfastPackages[0].description,
|
|
||||||
comment: addedBreakfastPackages[0].comment,
|
|
||||||
totalPrice: addedBreakfastPackages.reduce(
|
|
||||||
(acc, curr) => acc + curr.totalPrice,
|
|
||||||
0
|
|
||||||
),
|
|
||||||
unit: addedBreakfastPackages.reduce((acc, curr) => acc + curr.unit, 0),
|
|
||||||
totalUnit: addedBreakfastPackages.reduce(
|
|
||||||
(acc, curr) => acc + curr.totalUnit,
|
|
||||||
0
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
return [combinedBreakfastPackageAsAncillary, ...booking.ancillaries]
|
|
||||||
}, [booking.ancillaries, booking.packages])
|
|
||||||
|
|
||||||
if (addedAncillaries.length === 0) {
|
if (addedAncillaries.length === 0) {
|
||||||
return null
|
return null
|
||||||
@@ -133,7 +104,12 @@ export function AddedAncillaries({
|
|||||||
<div className={styles.actions}>
|
<div className={styles.actions}>
|
||||||
<RemoveButton
|
<RemoveButton
|
||||||
confirmationNumber={booking.confirmationNumber}
|
confirmationNumber={booking.confirmationNumber}
|
||||||
code={ancillary.code}
|
codes={
|
||||||
|
ancillary.code ===
|
||||||
|
BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
|
||||||
|
? addedBreakfastPackages!.map((p) => p.code)
|
||||||
|
: [ancillary.code]
|
||||||
|
}
|
||||||
title={ancillaryTitle}
|
title={ancillaryTitle}
|
||||||
onSuccess={router.refresh}
|
onSuccess={router.refresh}
|
||||||
/>
|
/>
|
||||||
@@ -179,7 +155,12 @@ export function AddedAncillaries({
|
|||||||
<div className={styles.actions}>
|
<div className={styles.actions}>
|
||||||
<RemoveButton
|
<RemoveButton
|
||||||
confirmationNumber={booking.confirmationNumber}
|
confirmationNumber={booking.confirmationNumber}
|
||||||
code={ancillary.code}
|
codes={
|
||||||
|
ancillary.code ===
|
||||||
|
BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
|
||||||
|
? addedBreakfastPackages!.map((p) => p.code)
|
||||||
|
: [ancillary.code]
|
||||||
|
}
|
||||||
title={ancillaryTitle}
|
title={ancillaryTitle}
|
||||||
onSuccess={() => {
|
onSuccess={() => {
|
||||||
trackRemoveAncillary(
|
trackRemoveAncillary(
|
||||||
@@ -200,3 +181,40 @@ export function AddedAncillaries({
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All ancillaries that are added to the booking
|
||||||
|
*
|
||||||
|
* Adding a special ancillary for breakfast, calculated from
|
||||||
|
* all breakfast packages that has been added as ancillaries,
|
||||||
|
* not in the booking flow.
|
||||||
|
*/
|
||||||
|
function getAddedAncillaries(
|
||||||
|
booking: BookingConfirmation["booking"],
|
||||||
|
addedBreakfastPackages: PackageSchema[] | undefined
|
||||||
|
) {
|
||||||
|
if (!addedBreakfastPackages?.length) {
|
||||||
|
return booking.ancillaries
|
||||||
|
}
|
||||||
|
|
||||||
|
const combinedBreakfastPackageAsAncillary: PackageSchema = {
|
||||||
|
code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
|
||||||
|
unitPrice: 0,
|
||||||
|
points: 0,
|
||||||
|
currency: addedBreakfastPackages[0].currency,
|
||||||
|
type: addedBreakfastPackages[0].type,
|
||||||
|
description: addedBreakfastPackages[0].description,
|
||||||
|
comment: addedBreakfastPackages[0].comment,
|
||||||
|
totalPrice: addedBreakfastPackages.reduce(
|
||||||
|
(acc, curr) => acc + curr.totalPrice,
|
||||||
|
0
|
||||||
|
),
|
||||||
|
unit: addedBreakfastPackages.reduce((acc, curr) => acc + curr.unit, 0),
|
||||||
|
totalUnit: addedBreakfastPackages.reduce(
|
||||||
|
(acc, curr) => acc + curr.totalUnit,
|
||||||
|
0
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
return [combinedBreakfastPackageAsAncillary, ...booking.ancillaries]
|
||||||
|
}
|
||||||
|
|||||||
@@ -576,7 +576,7 @@ export const bookingMutationRouter = router({
|
|||||||
{
|
{
|
||||||
headers,
|
headers,
|
||||||
} as RequestInit,
|
} as RequestInit,
|
||||||
{ language, codes }
|
[["language", language], ...codes.map((code) => ["codes", code])]
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user