From d17e3387bacbd3bf18c49e4d71dad9bda193b4fe Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Tue, 30 Apr 2024 18:35:15 -0700 Subject: [PATCH 01/17] fixed existing html error regarding form ids and labeling --- package-lock.json | 6 +- src/app/addNewClient/page.tsx | 268 +++++++++++++++++----------------- 2 files changed, 141 insertions(+), 133 deletions(-) diff --git a/package-lock.json b/package-lock.json index 999b91b..9edaff0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -829,9 +829,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001551", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001551.tgz", - "integrity": "sha512-vtBAez47BoGMMzlbYhfXrMV1kvRF2WP/lqiMuDu1Sb4EE4LKEgjopFDSRtZfdVnslNRpOqV/woE+Xgrwj6VQlg==", + "version": "1.0.30001611", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001611.tgz", + "integrity": "sha512-19NuN1/3PjA3QI8Eki55N8my4LzfkMCRLgCVfrl/slbSAchQfV0+GwjPrK3rq37As4UCLlM/DHajbKkAqbv92Q==", "funding": [ { "type": "opencollective", diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index fc951a2..11685d7 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -1,23 +1,20 @@ "use client"; import Navbar from "../components/Navbar"; -import styles from "./addNewClient.module.css" -import { useState } from 'react'; +import styles from "./addNewClient.module.css"; +import { useState } from "react"; export default function AddNewClient() { -const [ - selectedValue, - setSelectedValue, -] = useState("option1"); + const [selectedValue, setSelectedValue] = useState("option1"); -const handleRadioChange = (value: any) => { - setSelectedValue(value); -}; + const handleRadioChange = (value: any) => { + setSelectedValue(value); + }; -const [category, setCategory] = useState(''); -const handleCategoryChange = (category: any) => { - setCategory(category); - console.log(category); -} + const [category, setCategory] = useState(""); + const handleCategoryChange = (category: any) => { + setCategory(category); + console.log(category); + }; return ( <> @@ -25,137 +22,148 @@ const handleCategoryChange = (category: any) => {

Add New Client

Head of Household Information

-
-
- - - -
-
- - - -
+
+
+
-
+
+
+ +

Household Information

Household Size

-
- - -
-
- - -
-
-

Adult 1

-
-
- - - -
-
- - - -
-
- - - -
+
+ +
-

Child 1

- - - -
+ + +
+

Adult 1

-

Additional Information

-
- - handleRadioChange("option1") - } - /> - {/* for now, the button is set to being checked always */} +
+
-

Authorized pick-up

- - - -
-
- - - -
-
- - - -
-
- + +
+
+ +
+
+

Child 1

+
+ +
+
+ +
+
+ +
+ +
+

Additional Information

+
+ handleRadioChange("option1")} + /> + {" "} + {/* for now, the button is set to being checked always */} +
+

Authorized pick-up

+
+ +
+
+ +
+
+ +
+
+ ); } From beb2e06a58f64dd9928d3bbb9708e01741ce5d09 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Tue, 30 Apr 2024 19:11:55 -0700 Subject: [PATCH 02/17] refactored name and age input fields --- src/app/addNewClient/addNewClient.module.css | 126 +++++++++---------- src/app/addNewClient/page.tsx | 84 ++----------- src/app/components/NewClientFields.css | 28 +++++ src/app/components/NewClientFields.tsx | 45 +++++++ 4 files changed, 143 insertions(+), 140 deletions(-) create mode 100644 src/app/components/NewClientFields.css create mode 100644 src/app/components/NewClientFields.tsx diff --git a/src/app/addNewClient/addNewClient.module.css b/src/app/addNewClient/addNewClient.module.css index 6f44459..71188d4 100644 --- a/src/app/addNewClient/addNewClient.module.css +++ b/src/app/addNewClient/addNewClient.module.css @@ -1,71 +1,71 @@ .header { - font-family: "Avenir"; - color: #000000; - } - - .subheader { - font-family: "Avenir"; - color: rgb(103, 109, 78) - } + font-family: "Avenir"; + color: #000000; +} - .insideSubheader { - font-family: "Avenir"; - color: black - } +.subheader { + font-family: "Avenir"; + color: rgb(103, 109, 78); +} - /* for boxes to appear side by side */ - .inputGroup { - display: inline-block; - margin-bottom: 5px; - padding: 5px; - } +.insideSubheader { + font-family: "Avenir"; + color: black; +} - /* entire input field with labels and input box */ - .inputContainer { - display: flex; - flex-direction: row; - } +/* for boxes to appear side by side */ +.inputGroup { + display: inline-block; + margin-bottom: 5px; + padding: 5px; +} - .inputBar { - flex: 1; - - margin-bottom: 20px; - padding-top: 15px; - padding-bottom: 15px; - padding-left: 60px; - padding-right: 60px; - font-family: "Avenir", sans-serif; - background-color: white; - border-width: 1px; - border-color: rgb(94, 161, 94); - border-radius: 3%; - } +/* entire input field with labels and input box */ +.inputContainer { + display: flex; + flex-direction: row; +} - .inputLabel { - display: block; - text-align: left; - margin-bottom: 3px; - font-size: 15px; - font-family: "Avenir", sans-serif; - } +.inputBar { + flex: 1; - .radioButton { - display: flex; - flex-direction: row; - margin-bottom: 5px; - } + margin-bottom: 20px; + padding-top: 15px; + padding-bottom: 15px; + padding-left: 60px; + padding-right: 60px; + font-family: "Avenir", sans-serif; + background-color: white; + border-width: 1px; + border-color: rgb(94, 161, 94); + border-radius: 3%; +} - .radioLabel { - font-family: "Avenir", sans-serif; - color: black; - } - - .addButton { - border: 2px; - color: white; - border-radius: 3px; - font-family: "Avenir", sans-serif; - background: rgb(103, 109, 78); - width: 8em; - height: 3em; - } \ No newline at end of file +.inputLabel { + display: block; + text-align: left; + margin-bottom: 3px; + font-size: 15px; + font-family: "Avenir", sans-serif; +} + +.radioButton { + display: flex; + flex-direction: row; + margin-bottom: 5px; +} + +.radioLabel { + font-family: "Avenir", sans-serif; + color: black; +} + +.addButton { + border: 2px; + color: white; + border-radius: 3px; + font-family: "Avenir", sans-serif; + background: rgb(103, 109, 78); + width: 8em; + height: 3em; +} diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index 11685d7..9194db1 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -1,5 +1,6 @@ "use client"; -import Navbar from "../components/Navbar"; +import Navbar from "@components/Navbar"; +import NewClientFields from "@components/NewClientFields"; import styles from "./addNewClient.module.css"; import { useState } from "react"; @@ -22,26 +23,8 @@ export default function AddNewClient() {

Add New Client

Head of Household Information

-
-
- -
-
- -
-
-
- -
+ +

Household Information

@@ -88,45 +71,9 @@ export default function AddNewClient() {

Adult 1

-
-
- -
-
- -
-
- -
-
+

Child 1

-
- -
-
- -
-
- -
+

Additional Information

@@ -144,24 +91,7 @@ export default function AddNewClient() { {/* for now, the button is set to being checked always */}

Authorized pick-up

-
- -
-
- -
-
- -
+ diff --git a/src/app/components/NewClientFields.css b/src/app/components/NewClientFields.css new file mode 100644 index 0000000..15294b4 --- /dev/null +++ b/src/app/components/NewClientFields.css @@ -0,0 +1,28 @@ +.inputGroup { + display: inline-block; + margin-bottom: 5px; + padding: 5px; +} + +.inputBar { + flex: 1; + + margin-bottom: 20px; + padding-top: 15px; + padding-bottom: 15px; + padding-left: 60px; + padding-right: 60px; + font-family: "Avenir", sans-serif; + background-color: white; + border-width: 1px; + border-color: rgb(94, 161, 94); + border-radius: 3%; +} + +.inputLabel { + display: block; + text-align: left; + margin-bottom: 3px; + font-size: 15px; + font-family: "Avenir", sans-serif; +} diff --git a/src/app/components/NewClientFields.tsx b/src/app/components/NewClientFields.tsx new file mode 100644 index 0000000..440180f --- /dev/null +++ b/src/app/components/NewClientFields.tsx @@ -0,0 +1,45 @@ +import React from "react"; +import "./NewClientFields.css"; + +interface Props { + isSelf: boolean +} + +const NewClientFields = (props: Props) => { + return ( +
+
+ +
+
+ +
+
+ +
+
+ ); +}; + +export default NewClientFields; From b280270a03e7a450661090517973e06c04bf246e Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Tue, 30 Apr 2024 19:39:42 -0700 Subject: [PATCH 03/17] authorized button is unclicked by default --- src/app/addNewClient/page.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index 9194db1..46657ff 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -5,10 +5,10 @@ import styles from "./addNewClient.module.css"; import { useState } from "react"; export default function AddNewClient() { - const [selectedValue, setSelectedValue] = useState("option1"); + const [selectedValue, setSelectedValue] = useState(false); - const handleRadioChange = (value: any) => { - setSelectedValue(value); + const handleRadioChange = () => { + setSelectedValue(!selectedValue); }; const [category, setCategory] = useState(""); @@ -82,13 +82,14 @@ export default function AddNewClient() { type="radio" id="option1" value="option1" - checked={selectedValue === "option1"} - onChange={() => handleRadioChange("option1")} + checked={selectedValue} + onClick={handleRadioChange} /> + {" "} - {/* for now, the button is set to being checked always */} + {/* for now, the button is set to being checked always */}

Authorized pick-up

From a9d2d5161a2f37c000e934cb71165991529dc9e4 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Tue, 30 Apr 2024 19:53:25 -0700 Subject: [PATCH 04/17] bug fix --- src/app/addNewClient/page.tsx | 13 +++++++------ src/app/components/NewClientFields.tsx | 7 ++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index 46657ff..dd4646f 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -23,7 +23,7 @@ export default function AddNewClient() {

Add New Client

Head of Household Information

- +
@@ -71,9 +71,9 @@ export default function AddNewClient() {

Adult 1

- +

Child 1

- +

Additional Information

@@ -83,16 +83,17 @@ export default function AddNewClient() { id="option1" value="option1" checked={selectedValue} - onClick={handleRadioChange} + onClick={handleRadioChange} // handle state with onClick (as opposed to onChange) so users can unclick if they change their minds + onChange={() => {}} // no-op onChange field to keep react happy - react expects this when checked is controlled /> {" "} {/* for now, the button is set to being checked always */}

Authorized pick-up

- + diff --git a/src/app/components/NewClientFields.tsx b/src/app/components/NewClientFields.tsx index 440180f..9635990 100644 --- a/src/app/components/NewClientFields.tsx +++ b/src/app/components/NewClientFields.tsx @@ -1,11 +1,8 @@ import React from "react"; import "./NewClientFields.css"; -interface Props { - isSelf: boolean -} -const NewClientFields = (props: Props) => { +const NewClientFields = () => { return (
@@ -30,7 +27,7 @@ const NewClientFields = (props: Props) => {

Household Information

@@ -38,15 +69,14 @@ export default function AddNewClient() { id="numAdults" className={styles.inputBar} name="category" - value={category} - onChange={(event) => handleCategoryChange(event.target.value)} + onChange={(event) => handleParentChange(event.target.value)} > - - - - - - {" "} + + + + + + {" "} {/* drop down menu for num of adults */}
@@ -57,23 +87,21 @@ export default function AddNewClient() {
-

Adult 1

- -

Child 1

- + {adultFields} + {childFields}

Additional Information

@@ -86,14 +114,14 @@ export default function AddNewClient() { onClick={handleRadioChange} // handle state with onClick (as opposed to onChange) so users can unclick if they change their minds onChange={() => {}} // no-op onChange field to keep react happy - react expects this when checked is controlled /> - + {" "} - {/* for now, the button is set to being checked always */} + + {/* for now, the button is set to being checked always */}

Authorized pick-up

- + From a49cd4c754a8d269a64da14280e1a9e359218861 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Tue, 30 Apr 2024 23:37:16 -0700 Subject: [PATCH 06/17] authorize input only appears when selected + added left margin --- src/app/addNewClient/addNewClient.module.css | 7 +- src/app/addNewClient/page.tsx | 139 ++++++++++--------- 2 files changed, 79 insertions(+), 67 deletions(-) diff --git a/src/app/addNewClient/addNewClient.module.css b/src/app/addNewClient/addNewClient.module.css index 71188d4..8156500 100644 --- a/src/app/addNewClient/addNewClient.module.css +++ b/src/app/addNewClient/addNewClient.module.css @@ -1,3 +1,7 @@ +.container { + margin-left: 30px; +} + .header { font-family: "Avenir"; color: #000000; @@ -52,12 +56,13 @@ .radioButton { display: flex; flex-direction: row; - margin-bottom: 5px; + margin-bottom: 30px; } .radioLabel { font-family: "Avenir", sans-serif; color: black; + } .addButton { diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index fba48cc..358ded2 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -52,78 +52,85 @@ export default function AddNewClient() { return ( <> -
-

Add New Client

-

Head of Household Information

- -
-
-

Household Information

-

Household Size

+
-
- - -
-
- - +

Add New Client

+

Head of Household Information

+ +
+
+

Household Information

+

Household Size

+
+
+ + +
+
+ + +
+ {adultFields} + {childFields}
- {adultFields} - {childFields} -
-
-

Additional Information

-
- {}} // no-op onChange field to keep react happy - react expects this when checked is controlled - /> +
+

Additional Information

+
+ {}} // no-op onChange field to keep react happy - react expects this when checked is controlled + /> - - {/* for now, the button is set to being checked always */} + +
+ {selectedValue ? ( + <> +

Authorized pick-up

+ + + ) : ( + "" + )}
-

Authorized pick-up

- +
- ); } From d6f4359ba6753b0c8a0f0df545892b63fb06f68a Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Sat, 4 May 2024 12:41:53 -0700 Subject: [PATCH 07/17] optimized useEffect, dynamic form handling, state managemeny --- src/app/addNewClient/page.tsx | 144 +++++++++++++++++-------- src/app/components/NewClientFields.tsx | 18 +++- src/database/householdMemberSchema.ts | 2 +- 3 files changed, 118 insertions(+), 46 deletions(-) diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index 358ded2..bf4fd4b 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -2,61 +2,95 @@ import Navbar from "@components/Navbar"; import NewClientFields from "@components/NewClientFields"; import styles from "./addNewClient.module.css"; -import { useEffect, useState } from "react"; +import { useEffect, useState, ChangeEvent } from "react"; + +export interface Member { + firstName: string; + lastName: string; + birthDate: string; + isAdult: boolean; +} export default function AddNewClient() { + const [selectedValue, setSelectedValue] = useState(false); const [numChildren, setNumChildren] = useState(0); const [numAdults, setNumAdults] = useState(1); - const [childFields, setChildFields] = useState([]); - const [adultFields, setAdultFields] = useState([]); + const [householdMem, setHouseholdMem] = useState([]); - useEffect(() => { - let fields = []; - for (let i = 0; i < numChildren; i++) { - fields.push( -
-

Child {i + 1}

- -
- ); - } - setChildFields(fields); - - fields = []; - for (let i = 1; i < numAdults; i++) { - fields.push( -
-

Adult {i + 1}

- -
- ); - } - setAdultFields(fields); - }, [numChildren, numAdults]); + const [formData, setFormData] = useState({ + firstName: "", + lastName: "", + birthDate: "", + entryDates: [], + authMem: [], + householdMem: [], + phoneNumber: "", + email: "", + address: "", + }); - const handleRadioChange = () => { - setSelectedValue(!selectedValue); + const handleChange = (e: ChangeEvent) => { + const value = e.target.value; + setFormData({ ...formData, [e.target.name]: value }); + console.log(formData); }; - const handleChildrenChange = (value: any) => { - setNumChildren(value); - //console.log(value); + const handleMemChange = (e: ChangeEvent, index: number, isAdult: boolean) => { + const { name, value} = e.target; + setHouseholdMem(prev => prev.map((mem, idx) => { + if (mem.isAdult === isAdult && idx === index) { + return { ...mem, [name]: value }; + } + return mem; + })); + + console.log(householdMem); +}; + + useEffect(() => { + setHouseholdMem((prev) => { + let children = prev.filter((mem) => !mem.isAdult).slice(0, numChildren); + let adults = prev.filter((mem) => mem.isAdult).slice(0, numAdults); + + while (children.length < numChildren) { + children.push({ + firstName: "", + lastName: "", + birthDate: "", + isAdult: false, + }); + } + while (adults.length < numAdults - 1) { + adults.push({ + firstName: "", + lastName: "", + birthDate: "", + isAdult: true, + }); + } + + return [...children, ...adults]; + }); + + }, [numChildren, numAdults]); + + const handleSubmit = () => { + console.log(formData); }; - const handleParentChange = (value: any) => { - setNumAdults(value); - //console.log(value); + const handleRadioChange = () => { + setSelectedValue(!selectedValue); }; return ( <> -
+

Add New Client

Head of Household Information

- +

Household Information

@@ -70,7 +104,7 @@ export default function AddNewClient() { id="numAdults" className={styles.inputBar} name="category" - onChange={(event) => handleParentChange(event.target.value)} + onChange={(e) => setNumAdults(parseInt(e.target.value))} > @@ -88,7 +122,9 @@ export default function AddNewClient() {
- {adultFields} - {childFields} + {householdMem + .filter((mem) => mem.isAdult) + .map((member, index) => ( +
+

Adult {index + 2}

+ handleMemChange(e, index, true)} + /> +
+ ))} + + {householdMem + .filter((mem) => !mem.isAdult) + .map((member, index) => ( +
+

Child {index + 1}

+ handleMemChange(e, index, false)} + /> +
+ ))}

Additional Information

@@ -123,14 +178,17 @@ export default function AddNewClient() { {selectedValue ? ( <>

Authorized pick-up

- + ) : ( "" )}
- -
+ + ); } diff --git a/src/app/components/NewClientFields.tsx b/src/app/components/NewClientFields.tsx index 9635990..d8d7c9f 100644 --- a/src/app/components/NewClientFields.tsx +++ b/src/app/components/NewClientFields.tsx @@ -1,8 +1,13 @@ -import React from "react"; +import React, {ChangeEvent} from "react"; import "./NewClientFields.css"; +import { Member } from "app/addNewClient/page"; +interface Props { + onAction: (e: ChangeEvent) => void; + +} -const NewClientFields = () => { +const NewClientFields = ({onAction}: Props) => { return (
@@ -10,7 +15,10 @@ const NewClientFields = () => { First Name

onAction(e)} required /> @@ -20,7 +28,10 @@ const NewClientFields = () => { Last Name

onAction(e)} required /> @@ -30,7 +41,10 @@ const NewClientFields = () => { Birth Date

onAction(e)} required /> diff --git a/src/database/householdMemberSchema.ts b/src/database/householdMemberSchema.ts index f0d390a..02241da 100644 --- a/src/database/householdMemberSchema.ts +++ b/src/database/householdMemberSchema.ts @@ -1,6 +1,6 @@ import mongoose, { Schema, Types } from "mongoose"; -interface IHouseholdMember extends Document { +export interface IHouseholdMember extends Document { firstName: string; lastName: string; birthDate: Date; From 839b0958b8e6950fa4b1e1cb44979340aa74b936 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Sun, 5 May 2024 12:41:35 -0700 Subject: [PATCH 08/17] householdMembers api endpoint --- src/app/api/householdMembers/route.ts | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/app/api/householdMembers/route.ts diff --git a/src/app/api/householdMembers/route.ts b/src/app/api/householdMembers/route.ts new file mode 100644 index 0000000..cdd7ca8 --- /dev/null +++ b/src/app/api/householdMembers/route.ts @@ -0,0 +1,73 @@ +import { NextRequest, NextResponse } from "next/server"; +import connectDB from "../../../database/db"; +import HouseholdMember, {IHouseholdMember} from "../../../database/householdMemberSchema"; + +export async function GET(req: NextRequest) { + try { + // Establishing database connection + await connectDB(); + + // Fetching clients + const members = await HouseholdMember.find(); + + // Checking if clients are found + if (members.length === 0) { + return NextResponse.json( + { message: "No clients found." }, + { status: 200 } + ); + } + + // Returning clients if found + return NextResponse.json(members); + } catch (err) { + console.error("Error fetching members:", err); + return NextResponse.json( + { error: "Error fetching members." }, + { status: 500 } + ); + } +} + +export async function POST(req: NextRequest) { + await connectDB(); + + try { + const { members } = await req.json(); + if (!Array.isArray(members)) { + return NextResponse.json( + { message: "Expected array of household members." }, + { status: 400 } + ); + } + + const result = await HouseholdMember.insertMany(members); + + return NextResponse.json( + { message: "Successfully added members."}, + {status: 200} + + ) + + + // const newMemberData = await req.json(); + + // //create a new client using the data in body + // const newMember = new IHouseholdMember(newMemberData); + // console.log(newMember); + + // //save the new client to the database + // await newMember.save(); + // return NextResponse.json( + // { message: "Operation successful" }, + // { status: 200 } + // ); + } catch (err) { + //if unable to add client, return error + console.log("Error adding members:", err); + return NextResponse.json( + { error: "Error adding members." }, + { status: 500 } + ); + } +} From 1680df9b647aff239a79f35beb33d540de0b44a2 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Sun, 5 May 2024 12:42:32 -0700 Subject: [PATCH 09/17] added email and address fields for the client --- src/app/components/NewClientFields.tsx | 40 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/app/components/NewClientFields.tsx b/src/app/components/NewClientFields.tsx index d8d7c9f..86cdec0 100644 --- a/src/app/components/NewClientFields.tsx +++ b/src/app/components/NewClientFields.tsx @@ -1,13 +1,12 @@ -import React, {ChangeEvent} from "react"; +import React, { ChangeEvent } from "react"; import "./NewClientFields.css"; -import { Member } from "app/addNewClient/page"; interface Props { - onAction: (e: ChangeEvent) => void; - + onAction: (e: ChangeEvent) => void; + isClient: boolean; } -const NewClientFields = ({onAction}: Props) => { +const NewClientFields = ({ onAction, isClient }: Props) => { return (
@@ -16,7 +15,6 @@ const NewClientFields = ({onAction}: Props) => { onAction(e)} required @@ -49,6 +47,36 @@ const NewClientFields = ({onAction}: Props) => { />
+ {isClient ? ( +
+
+ +
+
+ +
+
+ ) : ( + "" + )}
); }; From 896c8b32e23306d4a4468fdaee5350fb3813f281 Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Sun, 5 May 2024 12:43:29 -0700 Subject: [PATCH 10/17] handle submit makes fetch req to householdMems --- src/app/addNewClient/page.tsx | 68 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/src/app/addNewClient/page.tsx b/src/app/addNewClient/page.tsx index bf4fd4b..cdd2697 100644 --- a/src/app/addNewClient/page.tsx +++ b/src/app/addNewClient/page.tsx @@ -4,19 +4,32 @@ import NewClientFields from "@components/NewClientFields"; import styles from "./addNewClient.module.css"; import { useEffect, useState, ChangeEvent } from "react"; -export interface Member { +interface Member { firstName: string; lastName: string; birthDate: string; isAdult: boolean; + headHousehold: string; } -export default function AddNewClient() { +interface AuthMem { + firstName: string; + lastName: string; + birthDate: string; + client: string; +} +export default function AddNewClient() { const [selectedValue, setSelectedValue] = useState(false); const [numChildren, setNumChildren] = useState(0); const [numAdults, setNumAdults] = useState(1); const [householdMem, setHouseholdMem] = useState([]); + const [authMem, setAuthMem] = useState({ + firstName: "", + lastName: "", + birthDate: "", + client: "", + }); const [formData, setFormData] = useState({ firstName: "", @@ -36,17 +49,29 @@ export default function AddNewClient() { console.log(formData); }; - const handleMemChange = (e: ChangeEvent, index: number, isAdult: boolean) => { - const { name, value} = e.target; - setHouseholdMem(prev => prev.map((mem, idx) => { + const handleMemChange = ( + e: ChangeEvent, + index: number, + isAdult: boolean + ) => { + const { name, value } = e.target; + setHouseholdMem((prev) => + prev.map((mem, idx) => { if (mem.isAdult === isAdult && idx === index) { - return { ...mem, [name]: value }; + return { ...mem, [name]: value }; } return mem; - })); + }) + ); console.log(householdMem); -}; + }; + + const handleAuthMem = (e: ChangeEvent) => { + const { value, name } = e.target; + setAuthMem({ ...authMem, [name]: value }); + console.log(authMem); + }; useEffect(() => { setHouseholdMem((prev) => { @@ -59,6 +84,7 @@ export default function AddNewClient() { lastName: "", birthDate: "", isAdult: false, + headHousehold: "", }); } while (adults.length < numAdults - 1) { @@ -67,16 +93,30 @@ export default function AddNewClient() { lastName: "", birthDate: "", isAdult: true, + headHousehold: "", }); } return [...children, ...adults]; }); - }, [numChildren, numAdults]); - const handleSubmit = () => { - console.log(formData); + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + // TODO: save client and retrieve client id + + // save household members to household mem database + fetch("/api/householdMembers", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ members: householdMem }), + }) + .then((response) => console.log(response)) + .catch((err) => console.log(err)); + + //console.log(formData); }; const handleRadioChange = () => { @@ -90,7 +130,7 @@ export default function AddNewClient() {

Add New Client

Head of Household Information

- +

Household Information

@@ -143,6 +183,7 @@ export default function AddNewClient() {

Adult {index + 2}

handleMemChange(e, index, true)} />
@@ -154,6 +195,7 @@ export default function AddNewClient() {

Child {index + 1}

handleMemChange(e, index, false)} />
@@ -178,7 +220,7 @@ export default function AddNewClient() { {selectedValue ? ( <>

Authorized pick-up

- + ) : ( "" From 1d7c338458932d139edab02929c1cee4b5fe1b1d Mon Sep 17 00:00:00 2001 From: Melika Dabiri Date: Sun, 5 May 2024 12:50:33 -0700 Subject: [PATCH 11/17] added phone number ffield for the client --- src/app/components/NewClientFields.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/app/components/NewClientFields.tsx b/src/app/components/NewClientFields.tsx index 86cdec0..0d5ee30 100644 --- a/src/app/components/NewClientFields.tsx +++ b/src/app/components/NewClientFields.tsx @@ -61,6 +61,18 @@ const NewClientFields = ({ onAction, isClient }: Props) => { />
+
+ +