From d042978c1c58fee709464d6c01fb213b5bb16f22 Mon Sep 17 00:00:00 2001 From: Kamala Date: Tue, 23 Apr 2024 11:38:17 +0200 Subject: [PATCH] adjust schemas, imports and rethrow errors --- .../AccountHolder/AccountHolderForm.tsx | 14 +++++--------- .../features/Address/AddressForm.tsx | 17 +++++++---------- .../CarrierDetails/CarrierDetailsForm.tsx | 17 +++++------------ 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/PortingEmbed/features/AccountHolder/AccountHolderForm.tsx b/src/PortingEmbed/features/AccountHolder/AccountHolderForm.tsx index c24f1ab..a0fc2de 100644 --- a/src/PortingEmbed/features/AccountHolder/AccountHolderForm.tsx +++ b/src/PortingEmbed/features/AccountHolder/AccountHolderForm.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react' import { View } from 'react-native' -import { z } from 'zod' -import { ZodError } from 'zod' +import { z, ZodError } from 'zod' import { Porting } from '../../../../types/porting' import { AlertBanner } from '../../../components/AlertBanner' @@ -12,13 +11,8 @@ const schema = z.object({ firstName: z .string() .trim() - .min(1, 'Account Holder’s First Name is required') - .optional(), - lastName: z - .string() - .trim() - .min(1, 'Account Holder’s Last Name is required') - .optional(), + .min(1, 'Account Holder’s First Name is required'), + lastName: z.string().trim().min(1, 'Account Holder’s Last Name is required'), birthday: z .string() .trim() @@ -59,6 +53,8 @@ export function AccountHolderForm({ if (err instanceof ZodError) { const errorsToDisplay = err.errors.map((e) => e.message) setValidationErrors(`${errorsToDisplay.join('. ')}.`) + } else { + throw err } } } diff --git a/src/PortingEmbed/features/Address/AddressForm.tsx b/src/PortingEmbed/features/Address/AddressForm.tsx index 525a27d..42eba83 100644 --- a/src/PortingEmbed/features/Address/AddressForm.tsx +++ b/src/PortingEmbed/features/Address/AddressForm.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react' import { View } from 'react-native' -import { z } from 'zod' -import { ZodError } from 'zod' +import { z, ZodError } from 'zod' import { Porting } from '../../../../types/porting' import { AlertBanner } from '../../../components/AlertBanner' @@ -15,19 +14,17 @@ const schema = z.object({ .string() .trim() .min(1, 'Line 1 is required') - .max(35, 'Line 1 must not exceed 35 characters') - .optional(), + .max(35, 'Line 1 must not exceed 35 characters'), line2: z .string() .trim() - .max(35, 'Must not exceed 35 characters') + .max(35, 'Line 2 must not exceed 35 characters') .optional() - .transform((line2) => line2 || null) .nullable(), - city: z.string().trim().min(1, 'City is required').optional(), + city: z.string().trim().min(1, 'City is required'), postalCode: z.string().trim().optional(), state: z.string().nullable().optional(), - country: z.string().trim().min(1, 'Country is required').optional(), + country: z.string().trim().min(1, 'Country is required'), }), }) @@ -73,9 +70,9 @@ export function AddressForm({ } catch (err) { if (err instanceof ZodError) { const errorsToDisplay = err.errors.map((e) => e.message) - console.log(err) - setValidationErrors(`${errorsToDisplay.join('. ')}.`) + } else { + throw err } } } diff --git a/src/PortingEmbed/features/CarrierDetails/CarrierDetailsForm.tsx b/src/PortingEmbed/features/CarrierDetails/CarrierDetailsForm.tsx index 5fc3c09..7ec0bf2 100644 --- a/src/PortingEmbed/features/CarrierDetails/CarrierDetailsForm.tsx +++ b/src/PortingEmbed/features/CarrierDetails/CarrierDetailsForm.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react' import { View } from 'react-native' -import { z } from 'zod' -import { ZodError } from 'zod' +import { z, ZodError } from 'zod' import { Porting } from '../../../../types/porting' import { AlertBanner } from '../../../components/AlertBanner' @@ -10,16 +9,8 @@ import { declinedPortingRequiresCarrierInfo } from '../../util/portingUtils' import { CarrierDetailsInfo } from './CarrierDetailsInfo' const schema = z.object({ - accountNumber: z - .string() - .trim() - .min(1, 'Account Number is required') - .optional(), - accountPin: z - .string() - .trim() - .min(1, 'Number Transfer PIN is required') - .optional(), + accountNumber: z.string().trim().min(1, 'Account Number is required'), + accountPin: z.string().trim().min(1, 'Number Transfer PIN is required'), }) type CarrierInfoFormProps = { @@ -50,6 +41,8 @@ export function CarrierInfoForm({ if (err instanceof ZodError) { const errorsToDisplay = err.errors.map((e) => e.message) setValidationErrors(`${errorsToDisplay.join('. ')}.`) + } else { + throw err } } }