Skip to content

Commit

Permalink
adjust schemas, imports and rethrow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmadeveloper108 committed Apr 23, 2024
1 parent 1986dea commit d042978
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
14 changes: 5 additions & 9 deletions src/PortingEmbed/features/AccountHolder/AccountHolderForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/PortingEmbed/features/Address/AddressForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'),
}),
})

Expand Down Expand Up @@ -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
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions src/PortingEmbed/features/CarrierDetails/CarrierDetailsForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit d042978

Please sign in to comment.