From 619a461cef4b7b9af6a75966dcfc5f39c377db1c Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 3 Dec 2024 14:30:34 -0700 Subject: [PATCH 1/2] trim the zipcode --- src/Components/Steps/ZipcodeStep.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Components/Steps/ZipcodeStep.tsx b/src/Components/Steps/ZipcodeStep.tsx index bf67d2900..4e794e82a 100644 --- a/src/Components/Steps/ZipcodeStep.tsx +++ b/src/Components/Steps/ZipcodeStep.tsx @@ -26,6 +26,7 @@ export const ZipcodeStep = () => { const numberMustBeFiveDigitsLongRegex = /^\d{5}$/; const zipcodeSchema = z .string() + .trim() .regex(numberMustBeFiveDigitsLongRegex) .refine((data) => data in countiesByZipcode); @@ -50,7 +51,8 @@ export const ZipcodeStep = () => { }); const currentZipcodeValue = watch('zipcode'); - const shouldShowCountyInput = zipcodeSchema.safeParse(currentZipcodeValue).success; + const parsedZipCode = zipcodeSchema.safeParse(currentZipcodeValue); + const nextStep = useGoToNextStep('zipcode'); const formSubmitHandler = async (zipCodeAndCountyData: FormData) => { @@ -138,7 +140,7 @@ export const ZipcodeStep = () => { /> )} /> - {shouldShowCountyInput && ( + {parsedZipCode.success && (
@@ -164,7 +166,7 @@ export const ZipcodeStep = () => { id="questions.zipcode-a-disabledSelectMenuItemText" defaultMessage="Select a county" />, - countiesByZipcode[watch('zipcode')], + countiesByZipcode[parsedZipCode.data], )} {errors.county !== undefined && renderCountyHelperText()} From fff2c74cd5e087ba3a0ddf208aacd0c135a2d4e7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 3 Dec 2024 15:17:52 -0700 Subject: [PATCH 2/2] trim the expense amount and referrer text --- src/Components/Steps/Expenses/Expenses.tsx | 4 +-- src/Components/Steps/HouseholdSize.tsx | 4 +-- src/Components/Steps/Referrer.tsx | 2 +- src/Components/Steps/ZipcodeStep.tsx | 31 +++++++++++----------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Components/Steps/Expenses/Expenses.tsx b/src/Components/Steps/Expenses/Expenses.tsx index ba3c7345a..0e58e85d9 100644 --- a/src/Components/Steps/Expenses/Expenses.tsx +++ b/src/Components/Steps/Expenses/Expenses.tsx @@ -37,8 +37,6 @@ import './Expenses.css'; const Expenses = () => { const { formData, setFormData, locale } = useContext(Context); const { uuid, id } = useParams(); - const currentStepId = Number(id); - const navigate = useNavigate(); const intl = useIntl(); const translatedAriaLabel = intl.formatMessage({ id: 'questions.hasExpenses-ariaLabel', @@ -51,7 +49,7 @@ const Expenses = () => { const oneOrMoreDigitsButNotAllZero = /^(?!0+$)\d+$/; const expenseSourceSchema = z.object({ expenseSourceName: z.string().min(1), - expenseAmount: z.string().regex(oneOrMoreDigitsButNotAllZero), + expenseAmount: z.string().trim().regex(oneOrMoreDigitsButNotAllZero), }); const expenseSourcesSchema = z.array(expenseSourceSchema); const hasExpensesSchema = z.string().regex(/^true|false$/); diff --git a/src/Components/Steps/HouseholdSize.tsx b/src/Components/Steps/HouseholdSize.tsx index 06fc7f4e6..280be4a5c 100644 --- a/src/Components/Steps/HouseholdSize.tsx +++ b/src/Components/Steps/HouseholdSize.tsx @@ -47,7 +47,7 @@ const HouseholdSize = () => { }, }); - const formSubmitHandler: SubmitHandler> = async ({ householdSize }) => { + const formSubmitHandler: SubmitHandler> = ({ householdSize }) => { if (uuid) { const updatedFormData = { ...formData, @@ -55,7 +55,7 @@ const HouseholdSize = () => { householdData: formData.householdData.slice(0, householdSize), }; setFormData(updatedFormData); - await updateScreen(uuid, updatedFormData, locale); + updateScreen(uuid, updatedFormData, locale); nextStep(); } }; diff --git a/src/Components/Steps/Referrer.tsx b/src/Components/Steps/Referrer.tsx index a5935323d..4078fe149 100644 --- a/src/Components/Steps/Referrer.tsx +++ b/src/Components/Steps/Referrer.tsx @@ -42,7 +42,7 @@ export default function ReferralSourceStep() { defaultMessage: 'Please select a referral source.', }), ), - otherReferrer: z.string(), + otherReferrer: z.string().trim(), }) .refine((val) => val.referralSource !== 'other' || val.otherReferrer.length > 0, { message: formatMessage({ diff --git a/src/Components/Steps/ZipcodeStep.tsx b/src/Components/Steps/ZipcodeStep.tsx index 4e794e82a..e734cdc34 100644 --- a/src/Components/Steps/ZipcodeStep.tsx +++ b/src/Components/Steps/ZipcodeStep.tsx @@ -8,13 +8,13 @@ import { FormattedMessageType } from '../../Types/Questions'; import { FormData } from '../../Types/FormData'; import { Context } from '../Wrapper/Wrapper'; import { updateScreen } from '../../Assets/updateScreen'; -import ErrorMessageWrapper from '../ErrorMessage/ErrorMessageWrapper.tsx'; -import { useConfig } from '../Config/configHook.tsx'; +import ErrorMessageWrapper from '../ErrorMessage/ErrorMessageWrapper'; +import { useConfig } from '../Config/configHook'; import * as z from 'zod'; import QuestionHeader from '../QuestionComponents/QuestionHeader'; import QuestionLeadText from '../QuestionComponents/QuestionLeadText'; import QuestionQuestion from '../QuestionComponents/QuestionQuestion'; -import PrevAndContinueButtons from '../PrevAndContinueButtons/PrevAndContinueButtons.tsx'; +import PrevAndContinueButtons from '../PrevAndContinueButtons/PrevAndContinueButtons'; import { useDefaultBackNavigationFunction, useGoToNextStep } from '../QuestionComponents/questionHooks'; export const ZipcodeStep = () => { @@ -22,7 +22,17 @@ export const ZipcodeStep = () => { const { uuid } = useParams(); const backNavigationFunction = useDefaultBackNavigationFunction('zipcode'); - const countiesByZipcode = useConfig('counties_by_zipcode'); + const countiesByZipcode = useConfig<{ [key: string]: { [key: string]: string } }>('counties_by_zipcode'); + + const checkCountyIsValid = ({ zipcode, county }: { zipcode: string; county: string }) => { + const validCounties = countiesByZipcode[zipcode]; + + if (validCounties && county in validCounties) { + return true; + } + return false; + }; + const numberMustBeFiveDigitsLongRegex = /^\d{5}$/; const zipcodeSchema = z .string() @@ -55,24 +65,15 @@ export const ZipcodeStep = () => { const nextStep = useGoToNextStep('zipcode'); - const formSubmitHandler = async (zipCodeAndCountyData: FormData) => { + const formSubmitHandler = (zipCodeAndCountyData: FormData) => { if (uuid) { const updatedFormData = { ...formData, ...zipCodeAndCountyData }; setFormData(updatedFormData); - await updateScreen(uuid, updatedFormData, locale); + updateScreen(uuid, updatedFormData, locale); nextStep(); } }; - const checkCountyIsValid = ({ zipcode, county }) => { - const validCounties = countiesByZipcode[zipcode]; - - if (validCounties && county in validCounties) { - return true; - } - return false; - }; - const createMenuItems = (disabledSelectMenuItemText: FormattedMessageType, options: Record) => { const disabledSelectMenuItem = (