-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add input validation & error messages for editing VSR
- Loading branch information
1 parent
ede5260
commit 0e8bb2f
Showing
15 changed files
with
311 additions
and
152 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Common types for the VSR form (create & edit) input fields. | ||
*/ | ||
|
||
import { FurnitureInput } from "@/api/VSRs"; | ||
|
||
export interface IVSRFormInput { | ||
name: string; | ||
maritalStatus: string; | ||
gender: string; | ||
spouseName: string; | ||
age: number; | ||
ethnicity: string[]; | ||
other_ethnicity: string; | ||
employment_status: string; | ||
income_level: string; | ||
size_of_home: string; | ||
num_boys: number; | ||
num_girls: number; | ||
agesOfBoys: number[]; | ||
agesOfGirls: number[]; | ||
|
||
streetAddress: string; | ||
city: string; | ||
state: string; | ||
zipCode: number; | ||
phoneNumber: string; | ||
email: string; | ||
branch: string[]; | ||
conflicts: string[]; | ||
other_conflicts: string; | ||
dischargeStatus: string; | ||
serviceConnected: boolean; | ||
lastRank: string; | ||
militaryID: number; | ||
petCompanion: boolean; | ||
hearFrom: string; | ||
other_hearFrom: string; | ||
|
||
selectedFurnitureItems: Record<string, FurnitureInput>; | ||
additionalItems: string; | ||
} | ||
|
||
export interface ICreateVSRFormInput extends IVSRFormInput { | ||
confirmEmail: string; | ||
} | ||
|
||
export type IEditVSRFormInput = IVSRFormInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import emailValidator from "email-validator"; | ||
import { RegisterOptions } from "react-hook-form"; | ||
import { IVSRFormInput } from "@/components/VSRForm/VSRFormTypes"; | ||
|
||
/** | ||
* Defines common validators for the VSR form inputs. | ||
*/ | ||
export const vsrInputFieldValidators: Partial< | ||
Record<keyof IVSRFormInput, RegisterOptions<IVSRFormInput, keyof IVSRFormInput>> | ||
> = { | ||
name: { required: "Name is required" }, | ||
gender: { required: "Gender is required" }, | ||
age: { | ||
required: "Age is required", | ||
pattern: { | ||
// Only allow up to 2 digits | ||
value: /^[0-9]+$/, | ||
message: "This field must be a positive number", | ||
}, | ||
}, | ||
maritalStatus: { required: "Marital status is required" }, | ||
spouseName: { | ||
required: "Spouse's Name is required", | ||
}, | ||
ethnicity: { required: "Ethnicity is required" }, | ||
employment_status: { required: "Employment status is required" }, | ||
income_level: { required: "Income level is required" }, | ||
size_of_home: { required: "Size of home is required" }, | ||
streetAddress: { required: "Street address is required" }, | ||
city: { required: "City is required" }, | ||
state: { required: "State is required" }, | ||
zipCode: { | ||
required: "Zip Code is required", | ||
pattern: { | ||
// Must be 5 digits | ||
value: /^\d{5}$/, | ||
message: "This field must be a 5 digit number", | ||
}, | ||
}, | ||
phoneNumber: { | ||
required: "Phone Number is required", | ||
pattern: { | ||
value: /^\d{10}$/, | ||
message: "This field must be a 10 digit number", | ||
}, | ||
}, | ||
email: { | ||
required: "Email Address is required", | ||
validate: { | ||
validate: (emailAddress) => | ||
emailValidator.validate(emailAddress as string) || | ||
"This field must be a valid email address", | ||
}, | ||
}, | ||
branch: { required: "Military Branch is required" }, | ||
conflicts: { required: "Military Conflicts is required" }, | ||
dischargeStatus: { required: "Discharge status is required" }, | ||
serviceConnected: { | ||
validate: (value) => | ||
[true, false].includes(value as boolean) || "Service connected is required", | ||
}, | ||
lastRank: { required: "Last rank is required" }, | ||
militaryID: { | ||
required: "Last rank is required", | ||
pattern: { | ||
value: /^\d{4}$/, | ||
message: "This field must be a 4 digit number", | ||
}, | ||
}, | ||
petCompanion: { | ||
validate: (value) => | ||
[true, false].includes(value as boolean) || "Companionship animal is required", | ||
}, | ||
hearFrom: { required: "Referral source is required" }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.