fix: avoid localizing currencies and default missing value to N/A
This commit is contained in:
@@ -16,7 +16,6 @@ import {
|
|||||||
type TrackingSDKPageData,
|
type TrackingSDKPageData,
|
||||||
type TrackingSDKPaymentInfo,
|
type TrackingSDKPaymentInfo,
|
||||||
} from "@/types/components/tracking"
|
} from "@/types/components/tracking"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
|
|
||||||
export default async function BookingConfirmation({
|
export default async function BookingConfirmation({
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
@@ -60,7 +59,7 @@ export default async function BookingConfirmation({
|
|||||||
rateCodeName: booking.rateDefinition.rateCode ?? undefined,
|
rateCodeName: booking.rateDefinition.rateCode ?? undefined,
|
||||||
rateCodeCancellationRule:
|
rateCodeCancellationRule:
|
||||||
booking.rateDefinition?.cancellationText ?? undefined,
|
booking.rateDefinition?.cancellationText ?? undefined,
|
||||||
revenueCurrencyCode: CurrencyEnum[booking.currencyCode],
|
revenueCurrencyCode: booking.currencyCode,
|
||||||
breakfastOption: booking.rateDefinition.breakfastIncluded
|
breakfastOption: booking.rateDefinition.breakfastIncluded
|
||||||
? "breakfast buffet"
|
? "breakfast buffet"
|
||||||
: "no breakfast",
|
: "no breakfast",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function getHotelPins(hotels: HotelData[]): HotelPin[] {
|
|||||||
currency:
|
currency:
|
||||||
hotel.price?.public?.localPrice.currency ||
|
hotel.price?.public?.localPrice.currency ||
|
||||||
hotel.price?.member?.localPrice.currency ||
|
hotel.price?.member?.localPrice.currency ||
|
||||||
null,
|
"N/A",
|
||||||
images: [
|
images: [
|
||||||
hotel.hotelData.hotelContent.images,
|
hotel.hotelData.hotelContent.images,
|
||||||
...(hotel.hotelData.gallery?.heroImages ?? []),
|
...(hotel.hotelData.gallery?.heroImages ?? []),
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import { ChildBedTypeEnum } from "@/constants/booking"
|
|||||||
|
|
||||||
import { phoneValidator } from "@/utils/phoneValidator"
|
import { phoneValidator } from "@/utils/phoneValidator"
|
||||||
|
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
|
|
||||||
// MUTATION
|
// MUTATION
|
||||||
export const createBookingSchema = z
|
export const createBookingSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -80,7 +78,7 @@ const guestSchema = z.object({
|
|||||||
|
|
||||||
const packageSchema = z.object({
|
const packageSchema = z.object({
|
||||||
code: z.string().nullable().default(""),
|
code: z.string().nullable().default(""),
|
||||||
currency: z.nativeEnum(CurrencyEnum),
|
currency: z.string(),
|
||||||
quantity: z.number().int(),
|
quantity: z.number().int(),
|
||||||
totalPrice: z.number(),
|
totalPrice: z.number(),
|
||||||
totalQuantity: z.number().int(),
|
totalQuantity: z.number().int(),
|
||||||
@@ -110,7 +108,7 @@ export const bookingConfirmationSchema = z
|
|||||||
extraBedTypes: z.array(extraBedTypesSchema).default([]),
|
extraBedTypes: z.array(extraBedTypesSchema).default([]),
|
||||||
computedReservationStatus: z.string().nullable().default(""),
|
computedReservationStatus: z.string().nullable().default(""),
|
||||||
confirmationNumber: z.string().nullable().default(""),
|
confirmationNumber: z.string().nullable().default(""),
|
||||||
currencyCode: z.nativeEnum(CurrencyEnum),
|
currencyCode: z.string(),
|
||||||
guest: guestSchema,
|
guest: guestSchema,
|
||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
packages: z.array(packageSchema).default([]),
|
packages: z.array(packageSchema).default([]),
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { specialAlertsSchema } from "./schemas/specialAlerts"
|
|||||||
import { getPoiGroupByCategoryName } from "./utils"
|
import { getPoiGroupByCategoryName } from "./utils"
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
import { FacilityEnum } from "@/types/enums/facilities"
|
import { FacilityEnum } from "@/types/enums/facilities"
|
||||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||||
import type { RestaurantData, RoomData } from "@/types/hotel"
|
import type { RestaurantData, RoomData } from "@/types/hotel"
|
||||||
@@ -219,7 +218,7 @@ const parkingPricingSchema = z.object({
|
|||||||
freeParking: z.boolean(),
|
freeParking: z.boolean(),
|
||||||
paymentType: z.string().optional(),
|
paymentType: z.string().optional(),
|
||||||
localCurrency: z.object({
|
localCurrency: z.object({
|
||||||
currency: z.string().optional(),
|
currency: z.string().default("N/A"),
|
||||||
range: z.object({
|
range: z.object({
|
||||||
min: z.number().optional(),
|
min: z.number().optional(),
|
||||||
max: z.number().optional(),
|
max: z.number().optional(),
|
||||||
@@ -247,7 +246,7 @@ const parkingPricingSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
requestedCurrency: z
|
requestedCurrency: z
|
||||||
.object({
|
.object({
|
||||||
currency: z.string().optional(),
|
currency: z.string().default("N/A"),
|
||||||
range: z
|
range: z
|
||||||
.object({
|
.object({
|
||||||
min: z.number().optional(),
|
min: z.number().optional(),
|
||||||
@@ -493,7 +492,7 @@ const linksSchema = z.object({
|
|||||||
export const priceSchema = z.object({
|
export const priceSchema = z.object({
|
||||||
pricePerNight: z.coerce.number(),
|
pricePerNight: z.coerce.number(),
|
||||||
pricePerStay: z.coerce.number(),
|
pricePerStay: z.coerce.number(),
|
||||||
currency: z.nativeEnum(CurrencyEnum),
|
currency: z.string().default("N/A"),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const productTypePriceSchema = z.object({
|
export const productTypePriceSchema = z.object({
|
||||||
@@ -509,7 +508,7 @@ const productSchema = z.object({
|
|||||||
rateCode: "",
|
rateCode: "",
|
||||||
rateType: "",
|
rateType: "",
|
||||||
localPrice: {
|
localPrice: {
|
||||||
currency: CurrencyEnum.SEK,
|
currency: "N/A",
|
||||||
pricePerNight: 0,
|
pricePerNight: 0,
|
||||||
pricePerStay: 0,
|
pricePerStay: 0,
|
||||||
},
|
},
|
||||||
@@ -666,7 +665,7 @@ export const apiCountriesSchema = z.object({
|
|||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
attributes: z.object({
|
attributes: z.object({
|
||||||
currency: z.string().optional(),
|
currency: z.string().default("N/A"),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
}),
|
}),
|
||||||
hotelInformationSystemId: z.number().optional(),
|
hotelInformationSystemId: z.number().optional(),
|
||||||
@@ -813,7 +812,7 @@ export const apiLocationsSchema = z.object({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const packagePriceSchema = z.object({
|
export const packagePriceSchema = z.object({
|
||||||
currency: z.nativeEnum(CurrencyEnum),
|
currency: z.string().default("N/A"),
|
||||||
price: z.string(),
|
price: z.string(),
|
||||||
totalPrice: z.string(),
|
totalPrice: z.string(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
|
|
||||||
export const getRoomPackagesInputSchema = z.object({
|
export const getRoomPackagesInputSchema = z.object({
|
||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
@@ -14,13 +13,13 @@ export const getRoomPackagesInputSchema = z.object({
|
|||||||
|
|
||||||
export const packagePriceSchema = z
|
export const packagePriceSchema = z
|
||||||
.object({
|
.object({
|
||||||
currency: z.nativeEnum(CurrencyEnum),
|
currency: z.string().default("N/A"),
|
||||||
price: z.string(),
|
price: z.string(),
|
||||||
totalPrice: z.string(),
|
totalPrice: z.string(),
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.default({
|
.default({
|
||||||
currency: CurrencyEnum.SEK,
|
currency: "N/A",
|
||||||
price: "0",
|
price: "0",
|
||||||
totalPrice: "0",
|
totalPrice: "0",
|
||||||
}) // TODO: Remove optional and default when the API change has been deployed
|
}) // TODO: Remove optional and default when the API change has been deployed
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import deepmerge from "deepmerge"
|
import deepmerge from "deepmerge"
|
||||||
import isEqual from "fast-deep-equal"
|
import isEqual from "fast-deep-equal"
|
||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
|
||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
|
||||||
import { arrayMerge } from "@/utils/merge"
|
import { arrayMerge } from "@/utils/merge"
|
||||||
|
|
||||||
import { detailsStorageName } from "."
|
import { detailsStorageName } from "."
|
||||||
|
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
import type { StepEnum } from "@/types/enums/step"
|
import type { StepEnum } from "@/types/enums/step"
|
||||||
import type {
|
import type {
|
||||||
DetailsState,
|
DetailsState,
|
||||||
@@ -19,24 +15,6 @@ import type {
|
|||||||
} from "@/types/stores/enter-details"
|
} from "@/types/stores/enter-details"
|
||||||
import type { SafeUser } from "@/types/user"
|
import type { SafeUser } from "@/types/user"
|
||||||
|
|
||||||
export function langToCurrency() {
|
|
||||||
const lang = getLang()
|
|
||||||
switch (lang) {
|
|
||||||
case Lang.da:
|
|
||||||
return CurrencyEnum.DKK
|
|
||||||
case Lang.de:
|
|
||||||
case Lang.en:
|
|
||||||
case Lang.fi:
|
|
||||||
return CurrencyEnum.EUR
|
|
||||||
case Lang.no:
|
|
||||||
return CurrencyEnum.NOK
|
|
||||||
case Lang.sv:
|
|
||||||
return CurrencyEnum.SEK
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected lang: ${lang}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function extractGuestFromUser(user: NonNullable<SafeUser>) {
|
export function extractGuestFromUser(user: NonNullable<SafeUser>) {
|
||||||
return {
|
return {
|
||||||
countryCode: user.address.countryCode?.toString(),
|
countryCode: user.address.countryCode?.toString(),
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
extractGuestFromUser,
|
extractGuestFromUser,
|
||||||
getInitialRoomPrice,
|
getInitialRoomPrice,
|
||||||
getInitialTotalPrice,
|
getInitialTotalPrice,
|
||||||
langToCurrency,
|
|
||||||
navigate,
|
navigate,
|
||||||
writeToSessionStorage,
|
writeToSessionStorage,
|
||||||
} from "./helpers"
|
} from "./helpers"
|
||||||
@@ -233,7 +232,7 @@ export function createDetailsStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (subtractFromTotalPrice) {
|
if (subtractFromTotalPrice) {
|
||||||
let currency = state.totalPrice.local.currency ?? langToCurrency()
|
let currency = state.totalPrice.local.currency
|
||||||
let currentBreakfastTotalPrice = 0
|
let currentBreakfastTotalPrice = 0
|
||||||
let currentBreakfastTotalRequestedPrice = 0
|
let currentBreakfastTotalRequestedPrice = 0
|
||||||
if (state.breakfast) {
|
if (state.breakfast) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import EnterDetailsProvider from "@/providers/EnterDetailsProvider"
|
|||||||
import { detailsStorageName, useEnterDetailsStore } from "."
|
import { detailsStorageName, useEnterDetailsStore } from "."
|
||||||
|
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||||
import { StepEnum } from "@/types/enums/step"
|
import { StepEnum } from "@/types/enums/step"
|
||||||
import type { PersistedState } from "@/types/stores/enter-details"
|
import type { PersistedState } from "@/types/stores/enter-details"
|
||||||
@@ -84,12 +83,12 @@ const breakfastPackages = [
|
|||||||
code: BreakfastPackageEnum.REGULAR_BREAKFAST,
|
code: BreakfastPackageEnum.REGULAR_BREAKFAST,
|
||||||
description: "Breakfast with reservation",
|
description: "Breakfast with reservation",
|
||||||
localPrice: {
|
localPrice: {
|
||||||
currency: CurrencyEnum.SEK,
|
currency: "SEK",
|
||||||
price: "99",
|
price: "99",
|
||||||
totalPrice: "99",
|
totalPrice: "99",
|
||||||
},
|
},
|
||||||
requestedPrice: {
|
requestedPrice: {
|
||||||
currency: CurrencyEnum.EUR,
|
currency: "EUR",
|
||||||
price: "9",
|
price: "9",
|
||||||
totalPrice: "9",
|
totalPrice: "9",
|
||||||
},
|
},
|
||||||
@@ -108,7 +107,7 @@ function Wrapper({ children }: PropsWithChildren) {
|
|||||||
memberRate: {
|
memberRate: {
|
||||||
rateCode: "PLSA2BEU",
|
rateCode: "PLSA2BEU",
|
||||||
localPrice: {
|
localPrice: {
|
||||||
currency: CurrencyEnum.EUR,
|
currency: "EUR",
|
||||||
pricePerNight: 100,
|
pricePerNight: 100,
|
||||||
pricePerStay: 200,
|
pricePerStay: 200,
|
||||||
},
|
},
|
||||||
@@ -116,7 +115,7 @@ function Wrapper({ children }: PropsWithChildren) {
|
|||||||
publicRate: {
|
publicRate: {
|
||||||
rateCode: "SAVEEU",
|
rateCode: "SAVEEU",
|
||||||
localPrice: {
|
localPrice: {
|
||||||
currency: CurrencyEnum.EUR,
|
currency: "EUR",
|
||||||
pricePerNight: 100,
|
pricePerNight: 100,
|
||||||
pricePerStay: 200,
|
pricePerStay: 200,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export type HotelPin = {
|
|||||||
coordinates: Coordinates
|
coordinates: Coordinates
|
||||||
publicPrice: number | null
|
publicPrice: number | null
|
||||||
memberPrice: number | null
|
memberPrice: number | null
|
||||||
currency: string | null
|
currency: string
|
||||||
images: {
|
images: {
|
||||||
imageSizes: ImageSizes
|
imageSizes: ImageSizes
|
||||||
metaData: ImageMetaData
|
metaData: ImageMetaData
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import type { CurrencyEnum } from "@/types/enums/currency"
|
|
||||||
|
|
||||||
export interface SignupPromoProps {
|
export interface SignupPromoProps {
|
||||||
memberPrice: {
|
memberPrice: {
|
||||||
amount: number
|
amount: number
|
||||||
currency: CurrencyEnum
|
currency: string
|
||||||
}
|
}
|
||||||
badgeContent?: string
|
badgeContent?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export enum CurrencyEnum {
|
|
||||||
DKK = "DKK",
|
|
||||||
EUR = "EUR",
|
|
||||||
NOK = "NOK",
|
|
||||||
PLN = "PLN",
|
|
||||||
SEK = "SEK",
|
|
||||||
}
|
|
||||||
@@ -16,17 +16,9 @@ export function getSingleDecimal(n: Number | string) {
|
|||||||
* @param currency - currency code
|
* @param currency - currency code
|
||||||
* @returns localized and formatted number in string type with currency
|
* @returns localized and formatted number in string type with currency
|
||||||
*/
|
*/
|
||||||
export function formatPrice(
|
export function formatPrice(intl: IntlShape, price: number, currency: string) {
|
||||||
intl: IntlShape,
|
const localizedPrice = intl.formatNumber(price, {
|
||||||
price: number,
|
|
||||||
currency?: string | null
|
|
||||||
) {
|
|
||||||
if (!currency) {
|
|
||||||
return intl.formatNumber(price)
|
|
||||||
}
|
|
||||||
return intl.formatNumber(price, {
|
|
||||||
style: "currency",
|
|
||||||
currency,
|
|
||||||
minimumFractionDigits: 0,
|
minimumFractionDigits: 0,
|
||||||
})
|
})
|
||||||
|
return `${localizedPrice} ${currency}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user