From 7b76e351d9525c91a023f2e0bfc9df93ca9556f7 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Wed, 16 Apr 2025 10:23:57 +0200 Subject: [PATCH] fix(SW-2210): Removed isUserLoggedIn from RatesStore --- .../RoomsContainer/RateSummary/index.tsx | 7 +- .../SelectedRoomPanel/index.tsx | 23 +++--- .../Rates/BreakfastMessage/index.tsx | 7 +- .../RoomsList/RoomListItem/Rates/Regular.tsx | 71 ++++++++++--------- .../RoomsList/RoomListItem/Rates/index.tsx | 7 +- .../SelectRate/RoomsContainer/index.tsx | 4 +- .../HotelReservation/SelectRate/index.tsx | 6 -- apps/scandic-web/providers/RatesProvider.tsx | 2 - apps/scandic-web/stores/select-rate/index.ts | 4 +- .../selectRate/rateSummary.ts | 6 +- .../selectRate/roomsContainer.ts | 1 - apps/scandic-web/types/providers/rates.ts | 1 - apps/scandic-web/types/stores/rates.ts | 4 +- 13 files changed, 68 insertions(+), 75 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/RateSummary/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/RateSummary/index.tsx index b53628fc6..e853f1ecd 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/RateSummary/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/RateSummary/index.tsx @@ -1,5 +1,6 @@ "use client" import { useRouter } from "next/navigation" +import { useSession } from "next-auth/react" import { useState, useTransition } from "react" import { useIntl } from "react-intl" @@ -13,6 +14,7 @@ import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import Footnote from "@/components/TempDesignSystem/Text/Footnote" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" +import { isValidClientSession } from "@/utils/clientSession" import { formatPrice } from "@/utils/numberFormatting" import MobileSummary from "./MobileSummary" @@ -20,11 +22,10 @@ import { getTotalPrice } from "./utils" import styles from "./rateSummary.module.css" -import type { RateSummaryProps } from "@/types/components/hotelReservation/selectRate/rateSummary" import { RateEnum } from "@/types/enums/rate" import { RateTypeEnum } from "@/types/enums/rateType" -export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) { +export default function RateSummary() { const { bookingCode, bookingRooms, @@ -45,6 +46,8 @@ export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) { roomsAvailability: state.roomsAvailability, searchParams: state.searchParams, })) + const { data: session } = useSession() + const isUserLoggedIn = isValidClientSession(session) const [isSubmitting, setIsSubmitting] = useState(false) const intl = useIntl() diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/MultiRoomWrapper/SelectedRoomPanel/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/MultiRoomWrapper/SelectedRoomPanel/index.tsx index ce1e2ce90..7b0bdb130 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/MultiRoomWrapper/SelectedRoomPanel/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/MultiRoomWrapper/SelectedRoomPanel/index.tsx @@ -1,4 +1,5 @@ "use client" +import { useSession } from "next-auth/react" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" @@ -13,6 +14,7 @@ import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import { useRoomContext } from "@/contexts/SelectRate/Room" +import { isValidClientSession } from "@/utils/clientSession" import styles from "./selectedRoomPanel.module.css" @@ -21,17 +23,16 @@ import { RateEnum } from "@/types/enums/rate" export default function SelectedRoomPanel() { const intl = useIntl() - const { dates, isUserLoggedIn, roomCategories, rooms } = useRatesStore( - (state) => ({ - dates: { - from: state.booking.fromDate, - to: state.booking.toDate, - }, - isUserLoggedIn: state.isUserLoggedIn, - roomCategories: state.roomCategories, - rooms: state.rooms, - }) - ) + const { dates, roomCategories, rooms } = useRatesStore((state) => ({ + dates: { + from: state.booking.fromDate, + to: state.booking.toDate, + }, + roomCategories: state.roomCategories, + rooms: state.rooms, + })) + const { data: session } = useSession() + const isUserLoggedIn = isValidClientSession(session) const { actions: { modifyRate }, isMainRoom, diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/BreakfastMessage/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/BreakfastMessage/index.tsx index d8f56d552..ebfea3267 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/BreakfastMessage/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/BreakfastMessage/index.tsx @@ -1,10 +1,12 @@ "use client" +import { useSession } from "next-auth/react" import { useIntl } from "react-intl" import { useRatesStore } from "@/stores/select-rate" import Caption from "@/components/TempDesignSystem/Text/Caption" import { useRoomContext } from "@/contexts/SelectRate/Room" +import { isValidClientSession } from "@/utils/clientSession" import { getBreakfastMessage } from "./getBreakfastMessage" @@ -22,10 +24,11 @@ export default function BreakfastMessage({ const intl = useIntl() const { roomNr, selectedFilter } = useRoomContext() - const { hotelType, isUserLoggedIn } = useRatesStore((state) => ({ + const { hotelType } = useRatesStore((state) => ({ hotelType: state.hotelType, - isUserLoggedIn: state.isUserLoggedIn, })) + const { data: session } = useSession() + const isUserLoggedIn = isValidClientSession(session) const breakfastMessages = { included: intl.formatMessage({ diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/Regular.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/Regular.tsx index dd0f18e65..b5ab4c373 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/Regular.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/Rooms/RoomsList/RoomListItem/Rates/Regular.tsx @@ -1,17 +1,17 @@ "use client" +import { useSession } from "next-auth/react" import { useIntl } from "react-intl" import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard" import RegularRateCard from "@scandic-hotels/design-system/RegularRateCard" -import { useRatesStore } from "@/stores/select-rate" - import { sumPackages, sumPackagesRequestedPrice, } from "@/components/HotelReservation/utils" import { useRoomContext } from "@/contexts/SelectRate/Room" import useRateTitles from "@/hooks/booking/useRateTitles" +import { isValidClientSession } from "@/utils/clientSession" import { isSelectedPriceProduct } from "./isSelected" import { calculatePricePerNightPriceProduct } from "./totalPricePerNight" @@ -45,7 +45,8 @@ export default function Regular({ const rateTitles = useRateTitles() const { isMainRoom, roomNr, selectedFilter, selectedPackages, selectedRate } = useRoomContext() - const isUserLoggedIn = useRatesStore((state) => state.isUserLoggedIn) + const { data: session } = useSession() + const isUserLoggedIn = isValidClientSession(session) if (selectedFilter === BookingCodeFilterEnum.Discounted) { return null @@ -87,21 +88,21 @@ export default function Regular({ const memberPricePerNight = member ? calculatePricePerNightPriceProduct( - member.localPrice.pricePerNight, - member.requestedPrice?.pricePerNight, - nights, - pkgsSum.price, - pkgsSumRequested.price - ) + member.localPrice.pricePerNight, + member.requestedPrice?.pricePerNight, + nights, + pkgsSum.price, + pkgsSumRequested.price + ) : undefined const standardPricePerNight = standard ? calculatePricePerNightPriceProduct( - standard.localPrice.pricePerNight, - standard.requestedPrice?.pricePerNight, - nights, - pkgsSum.price, - pkgsSumRequested.price - ) + standard.localPrice.pricePerNight, + standard.requestedPrice?.pricePerNight, + nights, + pkgsSum.price, + pkgsSumRequested.price + ) : undefined let approximateMemberRatePrice = null @@ -149,12 +150,12 @@ export default function Regular({ const approximateRate = approximatePrice && requestedCurrency ? { - label: intl.formatMessage({ - defaultMessage: "Approx.", - }), - price: approximatePrice, - unit: requestedCurrency, - } + label: intl.formatMessage({ + defaultMessage: "Approx.", + }), + price: approximatePrice, + unit: requestedCurrency, + } : undefined const isSelected = isSelectedPriceProduct( @@ -165,21 +166,21 @@ export default function Regular({ const rateTermDetails = product.rateDefinitionMember ? [ - { - title: product.rateDefinition.title, - terms: product.rateDefinition.generalTerms, - }, - { - title: product.rateDefinitionMember.title, - terms: product.rateDefinition.generalTerms, - }, - ] + { + title: product.rateDefinition.title, + terms: product.rateDefinition.generalTerms, + }, + { + title: product.rateDefinitionMember.title, + terms: product.rateDefinition.generalTerms, + }, + ] : [ - { - title: product.rateDefinition.title, - terms: product.rateDefinition.generalTerms, - }, - ] + { + title: product.rateDefinition.title, + terms: product.rateDefinition.generalTerms, + }, + ] return ( dt(state.booking.toDate).diff(state.booking.fromDate, "days") ) + const { data: session } = useSession() + const isUserLoggedIn = isValidClientSession(session) function handleSelectRate(product: Product) { - selectRate({ features, product, roomType, roomTypeCode }) + selectRate({ features, product, roomType, roomTypeCode }, isUserLoggedIn) } const sharedProps = { diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx index e540ce7c8..46fe36ec2 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx @@ -14,7 +14,6 @@ import type { RoomsContainerProps } from "@/types/components/hotelReservation/se export function RoomsContainer({ booking, hotelType, - isUserLoggedIn, roomCategories, vat, }: RoomsContainerProps) { @@ -36,13 +35,12 @@ export function RoomsContainer({ - + ) } diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx index 6ea8f6a9b..ac63d5361 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx @@ -5,13 +5,11 @@ import { Suspense } from "react" import { REDEMPTION } from "@/constants/booking" import { getHotel } from "@/lib/trpc/memoizedRequests" -import { auth } from "@/auth" import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard" import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer" import TrackingSDK from "@/components/TrackingSDK" import { setLang } from "@/i18n/serverContext" import { getHotelSearchDetails } from "@/utils/hotelSearchDetails" -import { isValidSession } from "@/utils/session" import { convertSearchParamsToObj } from "@/utils/url" import { getValidDates } from "./getValidDates" @@ -53,9 +51,6 @@ export default async function SelectRatePage({ selectHotelParams.toDate ) - const session = await auth() - const isUserLoggedIn = isValidSession(session) - const arrivalDate = fromDate.toDate() const departureDate = toDate.toDate() @@ -85,7 +80,6 @@ export default async function SelectRatePage({ diff --git a/apps/scandic-web/providers/RatesProvider.tsx b/apps/scandic-web/providers/RatesProvider.tsx index 13b621adb..56185fe2d 100644 --- a/apps/scandic-web/providers/RatesProvider.tsx +++ b/apps/scandic-web/providers/RatesProvider.tsx @@ -14,7 +14,6 @@ export default function RatesProvider({ booking, children, hotelType, - isUserLoggedIn, roomCategories, roomsAvailability, vat, @@ -28,7 +27,6 @@ export default function RatesProvider({ storeRef.current = createRatesStore({ booking, hotelType, - isUserLoggedIn, labels: { accessibilityRoom: intl.formatMessage({ defaultMessage: "Accessibility room", diff --git a/apps/scandic-web/stores/select-rate/index.ts b/apps/scandic-web/stores/select-rate/index.ts index 6ac82a208..473da4451 100644 --- a/apps/scandic-web/stores/select-rate/index.ts +++ b/apps/scandic-web/stores/select-rate/index.ts @@ -22,7 +22,6 @@ import type { PriceProduct } from "@/types/trpc/routers/hotel/roomAvailability" export function createRatesStore({ booking, hotelType, - isUserLoggedIn, labels, pathname, roomCategories, @@ -126,7 +125,6 @@ export function createRatesStore({ packageOptions, hotelType, isRedemptionBooking, - isUserLoggedIn, pathname, rateSummary, roomConfigurations, @@ -307,7 +305,7 @@ export function createRatesStore({ }) ) }, - selectRate(selectedRate) { + selectRate(selectedRate, isUserLoggedIn) { return set( produce((state: RatesState) => { if (!selectedRate.product) { diff --git a/apps/scandic-web/types/components/hotelReservation/selectRate/rateSummary.ts b/apps/scandic-web/types/components/hotelReservation/selectRate/rateSummary.ts index ef4dee4fe..2c8a370d0 100644 --- a/apps/scandic-web/types/components/hotelReservation/selectRate/rateSummary.ts +++ b/apps/scandic-web/types/components/hotelReservation/selectRate/rateSummary.ts @@ -1,10 +1,6 @@ import type { Price } from "../price" -export interface RateSummaryProps { - isUserLoggedIn: boolean -} - -export interface MobileSummaryProps extends RateSummaryProps { +export interface MobileSummaryProps { isAllRoomsSelected: boolean isUserLoggedIn: boolean totalPriceToShow: Price diff --git a/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts b/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts index 0e48f376f..b0907141b 100644 --- a/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts +++ b/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts @@ -5,5 +5,4 @@ export interface RoomsContainerProps extends Pick, Pick { booking: SelectRateSearchParams - isUserLoggedIn: boolean } diff --git a/apps/scandic-web/types/providers/rates.ts b/apps/scandic-web/types/providers/rates.ts index 00643398e..50381ec09 100644 --- a/apps/scandic-web/types/providers/rates.ts +++ b/apps/scandic-web/types/providers/rates.ts @@ -6,7 +6,6 @@ import type { AvailabilityError } from "../stores/rates" export interface RatesProviderProps extends React.PropsWithChildren { booking: SelectRateSearchParams hotelType: string | undefined - isUserLoggedIn: boolean roomCategories: Room[] roomsAvailability: (RoomsAvailability | AvailabilityError)[] | undefined vat: number diff --git a/apps/scandic-web/types/stores/rates.ts b/apps/scandic-web/types/stores/rates.ts index 44a4e43c3..c7baeac12 100644 --- a/apps/scandic-web/types/stores/rates.ts +++ b/apps/scandic-web/types/stores/rates.ts @@ -28,7 +28,7 @@ interface Actions { removeSelectedPackages: VoidFunction selectFilter: (filter: BookingCodeFilterEnum) => void selectPackages: (codes: PackageEnum[]) => void - selectRate: (rate: SelectedRate) => void + selectRate: (rate: SelectedRate, isUserLoggedIn: boolean) => void updateRooms: (rooms: RoomConfiguration[] | undefined) => void } @@ -55,7 +55,6 @@ export interface RatesState { booking: SelectRateSearchParams hotelType: string | undefined isRedemptionBooking: boolean - isUserLoggedIn: boolean packageOptions: DefaultFilterOptions[] pathname: string rateSummary: Array @@ -73,7 +72,6 @@ export interface InitialState RatesState, | "booking" | "hotelType" - | "isUserLoggedIn" | "pathname" | "roomCategories" | "roomsAvailability"