From a29f2b94a7fc4173565f163b76f7dee2afa19892 Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Tue, 17 Jun 2025 11:56:58 +0000 Subject: [PATCH] Merged in fix/signup-phone-validation (pull request #2378) fix/editprofile-phonenumber-validation * fix/editprofile-phonenumber-validation Approved-by: Christian Andolf --- apps/scandic-web/components/Forms/Edit/Profile/schema.ts | 2 +- apps/scandic-web/utils/phone.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/scandic-web/components/Forms/Edit/Profile/schema.ts b/apps/scandic-web/components/Forms/Edit/Profile/schema.ts index 798ddb43f..a0d4bcd43 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/schema.ts +++ b/apps/scandic-web/components/Forms/Edit/Profile/schema.ts @@ -38,7 +38,7 @@ export const editProfileSchema = z editProfileErrors.PHONE_REQUIRED, editProfileErrors.PHONE_REQUESTED ), - phoneNumberCC: z.string(), + phoneNumberCC: z.string().nullish(), password: z.string().optional(), newPassword: z.literal("").optional().or(passwordValidator()), diff --git a/apps/scandic-web/utils/phone.ts b/apps/scandic-web/utils/phone.ts index 351a1425b..b7c19ea88 100644 --- a/apps/scandic-web/utils/phone.ts +++ b/apps/scandic-web/utils/phone.ts @@ -1,7 +1,10 @@ import parsePhoneNumberFromString, { type CountryCode } from "libphonenumber-js" -export function formatPhoneNumber(phoneNumber: string, phoneNumberCC: string) { - const parsedPhonenumber = phoneNumberCC.length +export function formatPhoneNumber( + phoneNumber: string, + phoneNumberCC?: string | null +): string { + const parsedPhonenumber = phoneNumberCC?.length ? parsePhoneNumberFromString( phoneNumber, phoneNumberCC.toUpperCase() as CountryCode