diff --git a/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx b/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx index 38b582dae..09383e7a4 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx +++ b/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx @@ -2,6 +2,7 @@ import { useIntl } from "react-intl" +import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone" import { Divider } from "@scandic-hotels/design-system/Divider" import CountrySelect from "@scandic-hotels/design-system/Form/Country" import DateSelect from "@scandic-hotels/design-system/Form/Date" @@ -9,10 +10,7 @@ import Phone from "@scandic-hotels/design-system/Form/Phone" import { Select } from "@scandic-hotels/design-system/Select" import { Typography } from "@scandic-hotels/design-system/Typography" -import { - getDefaultCountryFromLang, - getLocalizedLanguageOptions, -} from "@/constants/languages" +import { getLocalizedLanguageOptions } from "@/constants/languages" import Input from "@/components/TempDesignSystem/Form/Input" import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput" diff --git a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx index 0d025f2ef..0e48e0fea 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx +++ b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx @@ -7,20 +7,22 @@ import { useIntl } from "react-intl" import { profile } from "@scandic-hotels/common/constants/routes/myPages" import { logger } from "@scandic-hotels/common/logger" +import { + formatPhoneNumber, + getDefaultCountryFromLang, +} from "@scandic-hotels/common/utils/phone" import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton" import Title from "@scandic-hotels/design-system/Title" import { toast } from "@scandic-hotels/design-system/Toast" import { trpc } from "@scandic-hotels/trpc/client" import { langToApiLang } from "@scandic-hotels/trpc/constants/apiLang" -import { getDefaultCountryFromLang } from "@/constants/languages" import { logout } from "@/constants/routes/handleAuth" import { editProfile } from "@/actions/editProfile" import Dialog from "@/components/Dialog" import ChangeNameDisclaimer from "@/components/MyPages/Profile/ChangeNameDisclaimer" import usePhoneNumberParsing from "@/hooks/usePhoneNumberParsing" -import { formatPhoneNumber } from "@/utils/phone" import FormContent from "./FormContent" import { type EditProfileSchema, editProfileSchema } from "./schema" diff --git a/apps/scandic-web/components/Forms/Signup/index.tsx b/apps/scandic-web/components/Forms/Signup/index.tsx index 6a8179a90..12f66c5db 100644 --- a/apps/scandic-web/components/Forms/Signup/index.tsx +++ b/apps/scandic-web/components/Forms/Signup/index.tsx @@ -7,6 +7,10 @@ import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" import { logger } from "@scandic-hotels/common/logger" +import { + formatPhoneNumber, + getDefaultCountryFromLang, +} from "@scandic-hotels/common/utils/phone" import { Button } from "@scandic-hotels/design-system/Button" import Checkbox from "@scandic-hotels/design-system/Form/Checkbox" import CountrySelect from "@scandic-hotels/design-system/Form/Country" @@ -22,7 +26,6 @@ import { signUpSchema, } from "@scandic-hotels/trpc/routers/user/schemas" -import { getDefaultCountryFromLang } from "@/constants/languages" import { membershipTermsAndConditions, privacyPolicy, @@ -34,7 +37,6 @@ import { useFormTracking } from "@/components/TrackingSDK/useFormTracking" import useLang from "@/hooks/useLang" import { getFormattedCountryList } from "@/utils/countries" import { getErrorMessage } from "@/utils/getErrorMessage" -import { formatPhoneNumber } from "@/utils/phone" // import { type SignUpSchema, signUpSchema } from "./schema" import styles from "./form.module.css" diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/Multiroom/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/Multiroom/index.tsx index a2bd21955..cc13ce37c 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/Multiroom/index.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/Multiroom/index.tsx @@ -4,11 +4,11 @@ import { useCallback, useEffect, useMemo } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" +import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone" import Footnote from "@scandic-hotels/design-system/Footnote" import CountrySelect from "@scandic-hotels/design-system/Form/Country" import Phone from "@scandic-hotels/design-system/Form/Phone" -import { getDefaultCountryFromLang } from "@/constants/languages" import { useEnterDetailsStore } from "@/stores/enter-details" import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests" diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx index 008c5db99..642fb8ea9 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx @@ -4,11 +4,11 @@ import { useCallback, useEffect } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" +import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone" import Footnote from "@scandic-hotels/design-system/Footnote" import CountrySelect from "@scandic-hotels/design-system/Form/Country" import Phone from "@scandic-hotels/design-system/Form/Phone" -import { getDefaultCountryFromLang } from "@/constants/languages" import { useEnterDetailsStore } from "@/stores/enter-details" import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests" diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx index 1c4e1f37c..182ddfb82 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx @@ -16,6 +16,7 @@ import { import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition" import { logger } from "@scandic-hotels/common/logger" import { trackEvent } from "@scandic-hotels/common/tracking/base" +import { formatPhoneNumber } from "@scandic-hotels/common/utils/phone" import Body from "@scandic-hotels/design-system/Body" import { Button } from "@scandic-hotels/design-system/Button" import Checkbox from "@scandic-hotels/design-system/Form/Checkbox" @@ -34,7 +35,6 @@ import PaymentOption from "@/components/HotelReservation/PaymentOption" import { useAvailablePaymentOptions } from "@/hooks/booking/useAvailablePaymentOptions" import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus" import useLang from "@/hooks/useLang" -import { formatPhoneNumber } from "@/utils/phone" import { trackPaymentEvent } from "@/utils/tracking" import { trackGlaSaveCardAttempt } from "@/utils/tracking/myStay" diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ModifyContact/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ModifyContact/index.tsx index 78b14170d..1699b82e2 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ModifyContact/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ModifyContact/index.tsx @@ -3,12 +3,11 @@ import { useEffect } from "react" import { useFormContext } from "react-hook-form" import { useIntl } from "react-intl" +import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone" import Body from "@scandic-hotels/design-system/Body" import CountrySelect from "@scandic-hotels/design-system/Form/Country" import Phone from "@scandic-hotels/design-system/Form/Phone" -import { getDefaultCountryFromLang } from "@/constants/languages" - import Input from "@/components/TempDesignSystem/Form/Input" import useLang from "@/hooks/useLang" import { getFormattedCountryList } from "@/utils/countries" diff --git a/apps/scandic-web/constants/languages.ts b/apps/scandic-web/constants/languages.ts index 6bd4bb05b..5398ee075 100644 --- a/apps/scandic-web/constants/languages.ts +++ b/apps/scandic-web/constants/languages.ts @@ -1,8 +1,6 @@ import { Lang } from "@scandic-hotels/common/constants/language" import { ApiLang } from "@scandic-hotels/trpc/constants/apiLang" -import type { CountryCode } from "libphonenumber-js" - export const languages: Record = { [Lang.da]: "Dansk", [Lang.de]: "Deutsch", @@ -81,15 +79,3 @@ export function getLocalizedLanguageOptions(currentLang: Lang) { } }) } - -export function getDefaultCountryFromLang(lang: Lang): Lowercase { - const countryMap: Record> = { - sv: "se", - da: "dk", - fi: "fi", - no: "no", - de: "de", - en: "se", // Default to Sweden for English - } - return countryMap[lang] || "se" -} diff --git a/apps/scandic-web/stores/enter-details/index.ts b/apps/scandic-web/stores/enter-details/index.ts index 3e3852ecb..6c3ebf255 100644 --- a/apps/scandic-web/stores/enter-details/index.ts +++ b/apps/scandic-web/stores/enter-details/index.ts @@ -4,8 +4,7 @@ import { useContext } from "react" import { create, useStore } from "zustand" import { dt } from "@scandic-hotels/common/dt" - -import { getDefaultCountryFromLang } from "@/constants/languages" +import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone" import { DetailsContext } from "@/contexts/Details" diff --git a/packages/common/package.json b/packages/common/package.json index d213a28df..982b86209 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -51,6 +51,7 @@ "./utils/rangeArray": "./utils/rangeArray.ts", "./utils/safeTry": "./utils/safeTry.ts", "./utils/url": "./utils/url.ts", + "./utils/phone": "./utils/phone.ts", "./utils/promiseWithTimeout": "./utils/promiseWithTimeout.ts", "./utils/zod/*": "./utils/zod/*.ts" }, @@ -60,6 +61,7 @@ "@t3-oss/env-nextjs": "^0.13.4", "deepmerge": "^4.3.1", "flat": "^6.0.1", + "libphonenumber-js": "^1.12.7", "lodash-es": "^4.17.21", "nanoid": "^5.1.5", "zod": "^3.24.4", diff --git a/apps/scandic-web/utils/phone.ts b/packages/common/utils/phone.ts similarity index 64% rename from apps/scandic-web/utils/phone.ts rename to packages/common/utils/phone.ts index 36a79bd38..e38e432b7 100644 --- a/apps/scandic-web/utils/phone.ts +++ b/packages/common/utils/phone.ts @@ -1,6 +1,8 @@ import parsePhoneNumberFromString, { type CountryCode } from "libphonenumber-js" -import { logger } from "@scandic-hotels/common/logger" +import { logger } from "../logger" + +import type { Lang } from "../constants/language" export function formatPhoneNumber( phoneNumber: string, @@ -26,3 +28,15 @@ export function formatPhoneNumber( return parsedPhonenumber?.number || normalized } + +export function getDefaultCountryFromLang(lang: Lang): Lowercase { + const countryMap: Record> = { + sv: "se", + da: "dk", + fi: "fi", + no: "no", + de: "de", + en: "se", // Default to Sweden for English + } + return countryMap[lang] || "se" +} diff --git a/yarn.lock b/yarn.lock index 418a82ca7..e09c3e83e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6160,6 +6160,7 @@ __metadata: eslint-plugin-import: "npm:^2.31.0" eslint-plugin-simple-import-sort: "npm:^12.1.1" flat: "npm:^6.0.1" + libphonenumber-js: "npm:^1.12.7" lodash-es: "npm:^4.17.21" nanoid: "npm:^5.1.5" typescript: "npm:5.8.3"