From 7912676d31a15bd1926048a8be4a980ccc9a6554 Mon Sep 17 00:00:00 2001 From: kathyychenn Date: Tue, 21 May 2024 15:39:35 -0700 Subject: [PATCH 1/4] contexts for step1 and step4 --- frontend/src/components/Dropdown.tsx | 7 +- frontend/src/components/Step1.tsx | 91 ++++++++++++++----- frontend/src/components/Step4.tsx | 126 +++++++++++++------------- frontend/src/contexts/FormContext.tsx | 2 + 4 files changed, 137 insertions(+), 89 deletions(-) diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index acfd1d1..e264614 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import styles from "./Dropdown.module.css"; @@ -6,10 +6,15 @@ export function Dropdown(props: { options: string[]; onSelect: (value: string) => void; required?: boolean; + defaultValue?: string; }) { const [selected, setSelected] = useState("Select One"); const [isActive, setIsActive] = useState(false); + useEffect(() => { + setSelected(props.defaultValue ?? "Select One"); + }, [props.defaultValue]); + const handleOptionClick = (option: string) => { setSelected(option); setIsActive(false); diff --git a/frontend/src/components/Step1.tsx b/frontend/src/components/Step1.tsx index c83dc16..a3a3bfe 100644 --- a/frontend/src/components/Step1.tsx +++ b/frontend/src/components/Step1.tsx @@ -1,7 +1,8 @@ -import { useState } from "react"; +import { useContext } from "react"; import devices from "../constants/devices.json"; import genders from "../constants/genders.json"; +import { FormContext } from "../contexts/FormContext.tsx"; import styles from "./Steps.module.css"; import { Dropdown } from "./index.ts"; @@ -11,22 +12,36 @@ type Step1Props = { }; export function Step1({ onSubmit }: Step1Props) { - const [email, setEmail] = useState(""); - const [confirmEmail, setConfirmEmail] = useState(""); - const [gender, setGender] = useState(""); - const [phoneType, setPhoneType] = useState(""); + const { formData, setFormData } = useContext(FormContext); + + const handleInputChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData((prevFormData) => ({ + ...prevFormData, + [name]: value, + })); + }; const handleGenderSelect = (option: string) => { - setGender(option); + setFormData((prevFormData) => ({ + ...prevFormData, + gender: option, + })); }; const handlePhoneSelect = (option: string) => { - setPhoneType(option); + setFormData((prevFormData) => ({ + ...prevFormData, + deviceType: option, + })); }; const handleConfirmEmailChange = (e: React.ChangeEvent) => { - setConfirmEmail(e.target.value); - e.target.setCustomValidity(""); // Reset custom validity on input change + setFormData((prevFormData) => ({ + ...prevFormData, + confirmEmail: e.target.value, + })); + e.target.setCustomValidity(""); }; const handleInvalid = (event: React.InvalidEvent) => { @@ -103,6 +118,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter First Name Here" name="firstName" + value={formData.firstName} + onChange={handleInputChange} required /> @@ -115,6 +132,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter Middle Name Here" name="middleName" + onChange={handleInputChange} + value={formData.middleName} /> @@ -126,6 +145,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter Last Name Here" name="lastName" + onChange={handleInputChange} + value={formData.lastName} required /> @@ -138,19 +159,26 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter 2nd Last Name Here" name="maidenName" + onChange={handleInputChange} + value={formData.maidenName} />
@@ -172,10 +200,8 @@ export function Step1({ onSubmit }: Step1Props) { className={styles.inputText} type="email" name="email" - value={email} - onChange={(e) => { - setEmail(e.target.value); - }} + value={formData.email} + onChange={handleInputChange} placeholder="Enter Email Address" autoComplete="email" required @@ -183,15 +209,20 @@ export function Step1({ onSubmit }: Step1Props) {
- @@ -221,8 +252,10 @@ export function Step1({ onSubmit }: Step1Props) { placeholder="Enter Phone Number" pattern="^\d+$" autoComplete="tel" + value={formData.phoneNumber} required - name="phone" + onChange={handleInputChange} + name="phoneNumber" />
@@ -246,6 +279,8 @@ export function Step1({ onSubmit }: Step1Props) { required name="address" autoComplete="street-address" + onChange={handleInputChange} + value={formData.address} /> @@ -258,6 +293,8 @@ export function Step1({ onSubmit }: Step1Props) { placeholder="Enter City" name="city" required + onChange={handleInputChange} + value={formData.city} /> @@ -269,6 +306,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter State" name="state" + value={formData.state} + onChange={handleInputChange} required /> @@ -281,7 +320,9 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter Country" name="country" + value={formData.country} required + onChange={handleInputChange} autoComplete="country" /> @@ -294,6 +335,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter County" name="county" + onChange={handleInputChange} + value={formData.county} /> @@ -305,6 +348,8 @@ export function Step1({ onSubmit }: Step1Props) { type="text" placeholder="Enter Zip Code" name="zip" + onChange={handleInputChange} + value={formData.zip} /> diff --git a/frontend/src/components/Step4.tsx b/frontend/src/components/Step4.tsx index fbad106..2664190 100644 --- a/frontend/src/components/Step4.tsx +++ b/frontend/src/components/Step4.tsx @@ -1,32 +1,34 @@ -import { useState } from "react"; +import { useContext } from "react"; import upload from "../assets/uploadIcon.svg"; +import { FormContext } from "../contexts/FormContext.tsx"; import styles from "./Step4.module.css"; import { Dropdown } from "./index.ts"; -// Pass in Application's next function export type StepProps = { next: () => void; }; export const Step4: React.FC = ({ next }: StepProps) => { - const [certified, setCertified] = useState(""); - const [licenseNumber, setLicenseNumber] = useState(""); - const [state, setState] = useState(""); - const [licenseExpiration, setLicenseExpiration] = useState(""); - const [certificationExam, setCertificationExam] = useState(""); - const [selectedFelonyCharge, setSelectedFelonyCharge] = useState(""); - const [dateOfCertificationExam, setDateOfCertificationExam] = useState(""); - const [eplanation, setExplanation] = useState(""); - - // Stores the Selected Option Value + const { formData, setFormData } = useContext(FormContext); + + const handleInputChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData((prevFormData) => ({ + ...prevFormData, + [name]: value, + })); + }; + const handleSelect = (option: string) => { - setSelectedFelonyCharge(option); - console.log({ selectedFelonyCharge }); + setFormData((prevFormData) => ({ + ...prevFormData, + convictedOfFelony: option, + })); + console.log(formData.convictedOfFelony); }; - // Checks if all Required Inputs are filled before moving on to next step const onSubmit = (event: React.FormEvent) => { event.preventDefault(); @@ -47,17 +49,15 @@ export const Step4: React.FC = ({ next }: StepProps) => {
-
-
-
-
-
-
diff --git a/frontend/src/contexts/FormContext.tsx b/frontend/src/contexts/FormContext.tsx index 1fee584..a55fb1c 100644 --- a/frontend/src/contexts/FormContext.tsx +++ b/frontend/src/contexts/FormContext.tsx @@ -51,6 +51,7 @@ type FormData = { maidenName: string; gender: string; email: string; + confirmEmail: string; deviceType: string; phoneNumber: string; address: string; @@ -96,6 +97,7 @@ const initialFormData: FormData = { maidenName: "", gender: "", email: "", + confirmEmail: "", deviceType: "", phoneNumber: "", address: "", From 08d369179b4cd69f54f800d4f6fac406b2d469fa Mon Sep 17 00:00:00 2001 From: kathyychenn Date: Tue, 21 May 2024 16:08:19 -0700 Subject: [PATCH 2/4] save if rules read to context step4 --- frontend/src/components/Step4.tsx | 27 +++++++++++++++++++++------ frontend/src/contexts/FormContext.tsx | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/Step4.tsx b/frontend/src/components/Step4.tsx index 2664190..8d0ca3e 100644 --- a/frontend/src/components/Step4.tsx +++ b/frontend/src/components/Step4.tsx @@ -14,11 +14,18 @@ export const Step4: React.FC = ({ next }: StepProps) => { const { formData, setFormData } = useContext(FormContext); const handleInputChange = (e: React.ChangeEvent) => { - const { name, value } = e.target; - setFormData((prevFormData) => ({ - ...prevFormData, - [name]: value, - })); + const { name, value, type, checked } = e.target; + if (type === "checkbox") { + setFormData((prevFormData) => ({ + ...prevFormData, + [name]: checked, + })); + } else { + setFormData((prevFormData) => ({ + ...prevFormData, + [name]: value, + })); + } }; const handleSelect = (option: string) => { @@ -199,7 +206,15 @@ export const Step4: React.FC = ({ next }: StepProps) => {

-
-
-
-
- -
- -
- -
- -
-
-
-
+
+ +
@@ -237,10 +216,57 @@ export const Step4: React.FC = ({ next }: StepProps) => {

+
+
+
+

+ Payment Information* +

+
+ +

+ After submitting your application, you will be navigated to pay via{" "} + credit card through the Payment Portal
+ Please Note: In the required “Invoice” field, please enter: IDEX - Candidates + Name +

+ +

+ To mail checks, please send them to: CCIDC, Inc. - 365 + W. Second Ave, Suite 221, Escondido, CA 92025 +

+ +

+ Total Fees due with application (Includes Application Fee + IDEX Exam Fee + Testing + Center Fee)**: $700 Total* +

+ +

+ *Fee is nonrefundable +
+ **Application fees must be submitted with + application. +

+ + +