From a8358de04a28e73f35e7f07dd27a9def66324dd1 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Mon, 31 Mar 2025 07:44:46 +0000 Subject: [PATCH] Merged in feat(SW-2084)-disable-options-modify-my-stay (pull request #1662) feat(SW-2084) logic to disable Manage stay options * feat(SW-2084) logic to disable Manage stay options * feat(SW-2084) cleanup logic for checks * feat(SW-2084) check if date has passed * feat(SW-2084) change to datetimeIsInThePast Approved-by: Niclas Edenvin --- .../MyStay/BookingSummary/index.tsx | 14 +- .../MyStay/GuestDetails/index.tsx | 6 +- .../Actions/AddToCalendarButton.tsx | 4 +- .../ActionPanel/actionPanel.module.css | 15 ++ .../MyStay/ManageStay/ActionPanel/index.tsx | 130 +++++++++++++----- .../MyStay/ManageStay/ActionPanel/utils.ts | 87 ++++++++++++ .../MyStay/ManageStay/index.tsx | 10 +- .../MyStay/ManageStay/manangeStay.module.css | 3 + .../MyStay/MultiRoom/ToggleSidePeek.tsx | 1 - .../MyStay/ReferenceCard/index.tsx | 28 ++-- .../MyStay/utils/mapRoomDetails.ts | 9 +- .../stores/my-stay/myStayRoomDetailsStore.ts | 5 +- 12 files changed, 239 insertions(+), 73 deletions(-) create mode 100644 apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/utils.ts create mode 100644 apps/scandic-web/components/HotelReservation/MyStay/ManageStay/manangeStay.module.css diff --git a/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx index 8ebaa7dee..983dcbf22 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx @@ -5,7 +5,6 @@ import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons" import { Typography } from "@scandic-hotels/design-system/Typography" -import { CancellationRuleEnum } from "@/constants/booking" import { dt } from "@/lib/dt" import { useMyStayRoomDetailsStore } from "@/stores/my-stay/myStayRoomDetailsStore" @@ -31,22 +30,15 @@ export default function BookingSummary({ hotel }: BookingSummaryProps) { const bookedRoom = useMyStayRoomDetailsStore((state) => state.bookedRoom) - const { - isCancelled, - createDateTime, - rateDefinition, - guaranteeInfo, - checkInDate, - } = bookedRoom + const { isCancelled, createDateTime, guaranteeInfo, checkInDate, isPrePaid } = + bookedRoom const directionsUrl = `https://www.google.com/maps/dir/?api=1&destination=${hotel.location.latitude},${hotel.location.longitude}` const bookingDate = dt(createDateTime).locale(lang).format("D MMMM YYYY") const isPaid = - rateDefinition.cancellationRule !== - CancellationRuleEnum.CancellableBefore6PM || - dt(checkInDate).startOf("day").isBefore(dt().startOf("day")) + isPrePaid || dt(checkInDate).startOf("day").isBefore(dt().startOf("day")) const paymentMethod = guaranteeInfo?.paymentMethodDescription ?.toLocaleLowerCase() diff --git a/apps/scandic-web/components/HotelReservation/MyStay/GuestDetails/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/GuestDetails/index.tsx index 74c33c388..0c3afb29f 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/GuestDetails/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/GuestDetails/index.tsx @@ -220,7 +220,11 @@ export default function GuestDetails({ > diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/AddToCalendarButton.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/AddToCalendarButton.tsx index 83cd00fc6..2d8ff432f 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/AddToCalendarButton.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/AddToCalendarButton.tsx @@ -11,8 +11,10 @@ import styles from "../actionPanel.module.css" export default function AddToCalendarButton({ onPress, + disabled, }: { onPress: () => void + disabled?: boolean }) { const intl = useIntl() @@ -25,9 +27,9 @@ export default function AddToCalendarButton({ - {showGuaranteeButton && ( - - )} + + + } + renderButton={(onPress) => ( + + )} /> - - {intl.formatMessage({ id: "Download invoice" })} - - - {showCancelStayButton && ( - + {intl.formatMessage({ id: "Download invoice" })} + + + ) : ( +
+ +

{intl.formatMessage({ id: "Download invoice" })}

+
+ + +
)} + +
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/utils.ts b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/utils.ts new file mode 100644 index 000000000..e3fc04ad0 --- /dev/null +++ b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/utils.ts @@ -0,0 +1,87 @@ +import { CancellationRuleEnum } from "@/constants/booking" + +import type { Room } from "@/stores/my-stay/myStayRoomDetailsStore" + +interface ModificationConditions { + canModify: boolean + isNotPast: boolean + isNotCancelled: boolean + isNotPrePaid: boolean +} + +interface GuaranteeConditions { + isCancellableBefore6PM: boolean + hasNoGuaranteeInfo: boolean + isNotCancelled: boolean + isNotPast: boolean +} + +export function isDatetimePast(date: Date): boolean { + return new Date(date) < new Date() +} + +export function checkDateModifiable({ + canChangeDate, + datetimeIsInThePast, + isCancelled, + isPrePaid, +}: { + canChangeDate: boolean + datetimeIsInThePast: boolean + isCancelled: boolean + isPrePaid: boolean +}): boolean { + const conditions: ModificationConditions = { + canModify: canChangeDate, + isNotPast: !datetimeIsInThePast, + isNotCancelled: !isCancelled, + isNotPrePaid: !isPrePaid, + } + + return Object.values(conditions).every(Boolean) +} + +export function checkCancelable({ + bookedRoom, + linkedReservationRooms, + datetimeIsInThePast, +}: { + bookedRoom: Room + linkedReservationRooms: Room[] + datetimeIsInThePast: boolean +}): boolean { + const hasAnyCancelableRoom = + bookedRoom.isCancelable || + linkedReservationRooms.some((room) => room.isCancelable) + + return hasAnyCancelableRoom && !datetimeIsInThePast +} + +export function checkGuaranteeable({ + bookedRoom, + datetimeIsInThePast, +}: { + bookedRoom: Room + datetimeIsInThePast: boolean +}): boolean { + const conditions: GuaranteeConditions = { + isCancellableBefore6PM: + bookedRoom.rateDefinition.cancellationRule === + CancellationRuleEnum.CancellableBefore6PM, + hasNoGuaranteeInfo: !bookedRoom.guaranteeInfo, + isNotCancelled: !bookedRoom.isCancelled, + isNotPast: !datetimeIsInThePast, + } + + return Object.values(conditions).every(Boolean) +} + +export function checkCanDownloadInvoice({ + isCancelled, + isPrePaid, +}: { + isCancelled: boolean + isPrePaid: boolean +}): boolean { + return !isCancelled && isPrePaid +} diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/index.tsx index 28afced7e..ae19902fd 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/index.tsx @@ -15,6 +15,8 @@ import CancelStay from "./ActionPanel/Actions/CancelStay" import ModifyStay from "./ActionPanel/Actions/ModifyStay" import ActionPanel from "./ActionPanel" +import styles from "./manangeStay.module.css" + import type { Hotel } from "@/types/hotel" import { type CreditCard } from "@/types/user" @@ -73,9 +75,15 @@ export default function ManageStay({ onClick={() => setIsOpen(true)} size="small" disabled={allRoomsCancelled} + className={styles.manageStayButton} > {intl.formatMessage({ id: "Manage stay" })} - + {isOpen && ( )} - {isModifiable && ( - -

- {booking.rateDefinition.generalTerms.map((term) => ( - - {term} - {term.endsWith(".") ? " " : ". "} - - ))} -

-
- )} + + +

+ {booking.rateDefinition.generalTerms.map((term) => ( + + {term} + {term.endsWith(".") ? " " : ". "} + + ))} +

+
) } diff --git a/apps/scandic-web/components/HotelReservation/MyStay/utils/mapRoomDetails.ts b/apps/scandic-web/components/HotelReservation/MyStay/utils/mapRoomDetails.ts index 32a254d01..259e88f47 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/utils/mapRoomDetails.ts +++ b/apps/scandic-web/components/HotelReservation/MyStay/utils/mapRoomDetails.ts @@ -1,4 +1,4 @@ -import { BookingStatusEnum } from "@/constants/booking" +import { BookingStatusEnum, CancellationRuleEnum } from "@/constants/booking" import { dt } from "@/lib/dt" import { formatChildBedPreferences } from "../utils" @@ -71,6 +71,11 @@ export function mapRoomDetails({ booking.childBedPreferences ) + const isPrePaid = + !!booking.guaranteeInfo?.paymentMethodDescription || + booking.rateDefinition.cancellationRule !== + CancellationRuleEnum.CancellableBefore6PM + return { hotelId: booking.hotelId, roomTypeCode: booking.roomTypeCode, @@ -85,7 +90,6 @@ export function mapRoomDetails({ guaranteeInfo: booking.guaranteeInfo, linkedReservations: booking.linkedReservations, bookingCode: booking.bookingCode, - isModifiable: booking.isModifiable, isCancelable: booking.isCancelable, multiRoom: booking.multiRoom, canChangeDate: booking.canChangeDate, @@ -136,5 +140,6 @@ export function mapRoomDetails({ }, }, breakfast, + isPrePaid, } } diff --git a/apps/scandic-web/stores/my-stay/myStayRoomDetailsStore.ts b/apps/scandic-web/stores/my-stay/myStayRoomDetailsStore.ts index 5098d1f36..30e0b9db6 100644 --- a/apps/scandic-web/stores/my-stay/myStayRoomDetailsStore.ts +++ b/apps/scandic-web/stores/my-stay/myStayRoomDetailsStore.ts @@ -21,7 +21,6 @@ export type Room = Pick< | "confirmationNumber" | "cancellationNumber" | "bookingCode" - | "isModifiable" | "isCancelable" | "multiRoom" | "canChangeDate" @@ -41,6 +40,7 @@ export type Room = Pick< roomPrice: RoomPrice breakfast: BreakfastPackage | false mainRoom: boolean + isPrePaid: boolean } interface MyStayRoomDetailsState { @@ -85,7 +85,6 @@ export const useMyStayRoomDetailsStore = create( rateCode: "", title: null, }, - reservationStatus: "", roomPrice: { perNight: { requested: { @@ -129,7 +128,7 @@ export const useMyStayRoomDetailsStore = create( breakfast: false, linkedReservations: [], isCancelable: false, - isModifiable: false, + isPrePaid: false, }, linkedReservationRooms: [], actions: {