Merged in feat/sw3370-move-phone-utils (pull request #2743)
feat(SW-3370): Move phone utils to common * Move phone utils to common * Update lock file Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone"
|
||||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||||
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
||||||
import DateSelect from "@scandic-hotels/design-system/Form/Date"
|
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 { Select } from "@scandic-hotels/design-system/Select"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
import {
|
import { getLocalizedLanguageOptions } from "@/constants/languages"
|
||||||
getDefaultCountryFromLang,
|
|
||||||
getLocalizedLanguageOptions,
|
|
||||||
} from "@/constants/languages"
|
|
||||||
|
|
||||||
import Input from "@/components/TempDesignSystem/Form/Input"
|
import Input from "@/components/TempDesignSystem/Form/Input"
|
||||||
import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput"
|
import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput"
|
||||||
|
|||||||
@@ -7,20 +7,22 @@ import { useIntl } from "react-intl"
|
|||||||
|
|
||||||
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
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 { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton"
|
||||||
import Title from "@scandic-hotels/design-system/Title"
|
import Title from "@scandic-hotels/design-system/Title"
|
||||||
import { toast } from "@scandic-hotels/design-system/Toast"
|
import { toast } from "@scandic-hotels/design-system/Toast"
|
||||||
import { trpc } from "@scandic-hotels/trpc/client"
|
import { trpc } from "@scandic-hotels/trpc/client"
|
||||||
import { langToApiLang } from "@scandic-hotels/trpc/constants/apiLang"
|
import { langToApiLang } from "@scandic-hotels/trpc/constants/apiLang"
|
||||||
|
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
import { logout } from "@/constants/routes/handleAuth"
|
import { logout } from "@/constants/routes/handleAuth"
|
||||||
|
|
||||||
import { editProfile } from "@/actions/editProfile"
|
import { editProfile } from "@/actions/editProfile"
|
||||||
import Dialog from "@/components/Dialog"
|
import Dialog from "@/components/Dialog"
|
||||||
import ChangeNameDisclaimer from "@/components/MyPages/Profile/ChangeNameDisclaimer"
|
import ChangeNameDisclaimer from "@/components/MyPages/Profile/ChangeNameDisclaimer"
|
||||||
import usePhoneNumberParsing from "@/hooks/usePhoneNumberParsing"
|
import usePhoneNumberParsing from "@/hooks/usePhoneNumberParsing"
|
||||||
import { formatPhoneNumber } from "@/utils/phone"
|
|
||||||
|
|
||||||
import FormContent from "./FormContent"
|
import FormContent from "./FormContent"
|
||||||
import { type EditProfileSchema, editProfileSchema } from "./schema"
|
import { type EditProfileSchema, editProfileSchema } from "./schema"
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import { FormProvider, useForm } from "react-hook-form"
|
|||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
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 { Button } from "@scandic-hotels/design-system/Button"
|
||||||
import Checkbox from "@scandic-hotels/design-system/Form/Checkbox"
|
import Checkbox from "@scandic-hotels/design-system/Form/Checkbox"
|
||||||
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
||||||
@@ -22,7 +26,6 @@ import {
|
|||||||
signUpSchema,
|
signUpSchema,
|
||||||
} from "@scandic-hotels/trpc/routers/user/schemas"
|
} from "@scandic-hotels/trpc/routers/user/schemas"
|
||||||
|
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
import {
|
import {
|
||||||
membershipTermsAndConditions,
|
membershipTermsAndConditions,
|
||||||
privacyPolicy,
|
privacyPolicy,
|
||||||
@@ -34,7 +37,6 @@ import { useFormTracking } from "@/components/TrackingSDK/useFormTracking"
|
|||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
import { getFormattedCountryList } from "@/utils/countries"
|
import { getFormattedCountryList } from "@/utils/countries"
|
||||||
import { getErrorMessage } from "@/utils/getErrorMessage"
|
import { getErrorMessage } from "@/utils/getErrorMessage"
|
||||||
import { formatPhoneNumber } from "@/utils/phone"
|
|
||||||
|
|
||||||
// import { type SignUpSchema, signUpSchema } from "./schema"
|
// import { type SignUpSchema, signUpSchema } from "./schema"
|
||||||
import styles from "./form.module.css"
|
import styles from "./form.module.css"
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { useCallback, useEffect, useMemo } from "react"
|
|||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone"
|
||||||
import Footnote from "@scandic-hotels/design-system/Footnote"
|
import Footnote from "@scandic-hotels/design-system/Footnote"
|
||||||
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
||||||
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
||||||
|
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
|
|
||||||
import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests"
|
import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests"
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { useCallback, useEffect } from "react"
|
|||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone"
|
||||||
import Footnote from "@scandic-hotels/design-system/Footnote"
|
import Footnote from "@scandic-hotels/design-system/Footnote"
|
||||||
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
||||||
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
||||||
|
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
|
|
||||||
import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests"
|
import SpecialRequests from "@/components/HotelReservation/EnterDetails/Details/SpecialRequests"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
|
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
import { trackEvent } from "@scandic-hotels/common/tracking/base"
|
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 Body from "@scandic-hotels/design-system/Body"
|
||||||
import { Button } from "@scandic-hotels/design-system/Button"
|
import { Button } from "@scandic-hotels/design-system/Button"
|
||||||
import Checkbox from "@scandic-hotels/design-system/Form/Checkbox"
|
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 { useAvailablePaymentOptions } from "@/hooks/booking/useAvailablePaymentOptions"
|
||||||
import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus"
|
import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus"
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
import { formatPhoneNumber } from "@/utils/phone"
|
|
||||||
import { trackPaymentEvent } from "@/utils/tracking"
|
import { trackPaymentEvent } from "@/utils/tracking"
|
||||||
import { trackGlaSaveCardAttempt } from "@/utils/tracking/myStay"
|
import { trackGlaSaveCardAttempt } from "@/utils/tracking/myStay"
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ import { useEffect } from "react"
|
|||||||
import { useFormContext } from "react-hook-form"
|
import { useFormContext } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone"
|
||||||
import Body from "@scandic-hotels/design-system/Body"
|
import Body from "@scandic-hotels/design-system/Body"
|
||||||
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
import CountrySelect from "@scandic-hotels/design-system/Form/Country"
|
||||||
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
import Phone from "@scandic-hotels/design-system/Form/Phone"
|
||||||
|
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
|
|
||||||
import Input from "@/components/TempDesignSystem/Form/Input"
|
import Input from "@/components/TempDesignSystem/Form/Input"
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
import { getFormattedCountryList } from "@/utils/countries"
|
import { getFormattedCountryList } from "@/utils/countries"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import { ApiLang } from "@scandic-hotels/trpc/constants/apiLang"
|
import { ApiLang } from "@scandic-hotels/trpc/constants/apiLang"
|
||||||
|
|
||||||
import type { CountryCode } from "libphonenumber-js"
|
|
||||||
|
|
||||||
export const languages: Record<Lang, string> = {
|
export const languages: Record<Lang, string> = {
|
||||||
[Lang.da]: "Dansk",
|
[Lang.da]: "Dansk",
|
||||||
[Lang.de]: "Deutsch",
|
[Lang.de]: "Deutsch",
|
||||||
@@ -81,15 +79,3 @@ export function getLocalizedLanguageOptions(currentLang: Lang) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultCountryFromLang(lang: Lang): Lowercase<CountryCode> {
|
|
||||||
const countryMap: Record<Lang, Lowercase<CountryCode>> = {
|
|
||||||
sv: "se",
|
|
||||||
da: "dk",
|
|
||||||
fi: "fi",
|
|
||||||
no: "no",
|
|
||||||
de: "de",
|
|
||||||
en: "se", // Default to Sweden for English
|
|
||||||
}
|
|
||||||
return countryMap[lang] || "se"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import { useContext } from "react"
|
|||||||
import { create, useStore } from "zustand"
|
import { create, useStore } from "zustand"
|
||||||
|
|
||||||
import { dt } from "@scandic-hotels/common/dt"
|
import { dt } from "@scandic-hotels/common/dt"
|
||||||
|
import { getDefaultCountryFromLang } from "@scandic-hotels/common/utils/phone"
|
||||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
|
||||||
|
|
||||||
import { DetailsContext } from "@/contexts/Details"
|
import { DetailsContext } from "@/contexts/Details"
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
"./utils/rangeArray": "./utils/rangeArray.ts",
|
"./utils/rangeArray": "./utils/rangeArray.ts",
|
||||||
"./utils/safeTry": "./utils/safeTry.ts",
|
"./utils/safeTry": "./utils/safeTry.ts",
|
||||||
"./utils/url": "./utils/url.ts",
|
"./utils/url": "./utils/url.ts",
|
||||||
|
"./utils/phone": "./utils/phone.ts",
|
||||||
"./utils/promiseWithTimeout": "./utils/promiseWithTimeout.ts",
|
"./utils/promiseWithTimeout": "./utils/promiseWithTimeout.ts",
|
||||||
"./utils/zod/*": "./utils/zod/*.ts"
|
"./utils/zod/*": "./utils/zod/*.ts"
|
||||||
},
|
},
|
||||||
@@ -60,6 +61,7 @@
|
|||||||
"@t3-oss/env-nextjs": "^0.13.4",
|
"@t3-oss/env-nextjs": "^0.13.4",
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
"flat": "^6.0.1",
|
"flat": "^6.0.1",
|
||||||
|
"libphonenumber-js": "^1.12.7",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"nanoid": "^5.1.5",
|
"nanoid": "^5.1.5",
|
||||||
"zod": "^3.24.4",
|
"zod": "^3.24.4",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import parsePhoneNumberFromString, { type CountryCode } from "libphonenumber-js"
|
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(
|
export function formatPhoneNumber(
|
||||||
phoneNumber: string,
|
phoneNumber: string,
|
||||||
@@ -26,3 +28,15 @@ export function formatPhoneNumber(
|
|||||||
|
|
||||||
return parsedPhonenumber?.number || normalized
|
return parsedPhonenumber?.number || normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getDefaultCountryFromLang(lang: Lang): Lowercase<CountryCode> {
|
||||||
|
const countryMap: Record<Lang, Lowercase<CountryCode>> = {
|
||||||
|
sv: "se",
|
||||||
|
da: "dk",
|
||||||
|
fi: "fi",
|
||||||
|
no: "no",
|
||||||
|
de: "de",
|
||||||
|
en: "se", // Default to Sweden for English
|
||||||
|
}
|
||||||
|
return countryMap[lang] || "se"
|
||||||
|
}
|
||||||
@@ -6160,6 +6160,7 @@ __metadata:
|
|||||||
eslint-plugin-import: "npm:^2.31.0"
|
eslint-plugin-import: "npm:^2.31.0"
|
||||||
eslint-plugin-simple-import-sort: "npm:^12.1.1"
|
eslint-plugin-simple-import-sort: "npm:^12.1.1"
|
||||||
flat: "npm:^6.0.1"
|
flat: "npm:^6.0.1"
|
||||||
|
libphonenumber-js: "npm:^1.12.7"
|
||||||
lodash-es: "npm:^4.17.21"
|
lodash-es: "npm:^4.17.21"
|
||||||
nanoid: "npm:^5.1.5"
|
nanoid: "npm:^5.1.5"
|
||||||
typescript: "npm:5.8.3"
|
typescript: "npm:5.8.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user