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