fix(SW-2210): Removed isUserLoggedIn from RatesStore
This commit is contained in:
committed by
Michael Zetterberg
parent
5323a8e46e
commit
7b76e351d9
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 (
|
||||
<RegularRateCard
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
"use client"
|
||||
|
||||
import { useSession } from "next-auth/react"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
import { useRatesStore } from "@/stores/select-rate"
|
||||
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import Divider from "@/components/TempDesignSystem/Divider"
|
||||
import { useRoomContext } from "@/contexts/SelectRate/Room"
|
||||
import { isValidClientSession } from "@/utils/clientSession"
|
||||
|
||||
import BreakfastMessage from "./BreakfastMessage"
|
||||
import Campaign from "./Campaign"
|
||||
@@ -38,8 +41,10 @@ export default function Rates({
|
||||
const nights = useRatesStore((state) =>
|
||||
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 = {
|
||||
|
||||
@@ -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({
|
||||
<RatesProvider
|
||||
booking={booking}
|
||||
hotelType={hotelType}
|
||||
isUserLoggedIn={isUserLoggedIn}
|
||||
roomCategories={roomCategories}
|
||||
roomsAvailability={roomsAvailability.data}
|
||||
vat={vat}
|
||||
>
|
||||
<Rooms />
|
||||
<RateSummary isUserLoggedIn={isUserLoggedIn} />
|
||||
<RateSummary />
|
||||
</RatesProvider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
<RoomsContainer
|
||||
booking={booking}
|
||||
hotelType={hotelData.hotel.hotelType}
|
||||
isUserLoggedIn={isUserLoggedIn}
|
||||
roomCategories={hotelData.roomCategories}
|
||||
vat={hotelData.hotel.vat}
|
||||
/>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,5 +5,4 @@ export interface RoomsContainerProps
|
||||
extends Pick<HotelData, "roomCategories">,
|
||||
Pick<HotelData["hotel"], "hotelType" | "vat"> {
|
||||
booking: SelectRateSearchParams
|
||||
isUserLoggedIn: boolean
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Rate | null>
|
||||
@@ -73,7 +72,6 @@ export interface InitialState
|
||||
RatesState,
|
||||
| "booking"
|
||||
| "hotelType"
|
||||
| "isUserLoggedIn"
|
||||
| "pathname"
|
||||
| "roomCategories"
|
||||
| "roomsAvailability"
|
||||
|
||||
Reference in New Issue
Block a user