From 8c906c98b2a2994286731357831ca8005ef0d73f Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Sun, 8 Aug 2021 16:11:08 +0530 Subject: Added better support for saving client data --- src/components/Form/People/RegisterPersonForm.tsx | 149 +++++++++++++++------- src/components/Form/People/SelectClientForm.tsx | 16 +-- 2 files changed, 112 insertions(+), 53 deletions(-) (limited to 'src/components/Form/People') diff --git a/src/components/Form/People/RegisterPersonForm.tsx b/src/components/Form/People/RegisterPersonForm.tsx index 9e3b155..3922975 100644 --- a/src/components/Form/People/RegisterPersonForm.tsx +++ b/src/components/Form/People/RegisterPersonForm.tsx @@ -8,7 +8,7 @@ import React, { useState } from "react"; import "./../Form.scss"; -import { Person } from "./../../../interfaces" +import { Person, Address } from "./../../../interfaces" import axios from "axios"; interface props { @@ -18,9 +18,14 @@ interface props { const RegisterPersonForm: React.FC = (props) => { const [newPersonName, setNewPersonName] = useState(""); - const [newPersonAddress, setNewPersonAddress] = useState(""); - const [newPersonEmail, setNewPersonEmail] = useState(""); const [newPersonPhone, setNewPersonPhone] = useState(""); + const [newPersonEmail, setNewPersonEmail] = useState(""); + + const [newPersonBillAddressLine, setNewPersonBillAddressLine] = useState(""); + const [newPersonBillCity, setNewPersonBillCity] = useState(""); + const [newPersonBillState, setNewPersonBillState] = useState(""); + const [newPersonBillPINCode, setNewPersonBillPINCode] = useState(""); + const [newPersonBillCountry, setNewPersonBillCountry] = useState(""); const hideSelf = () => props.setVisibility(false); @@ -32,9 +37,25 @@ const RegisterPersonForm: React.FC = (props) => { const newClient: Person = { Name: newPersonName, - Address: newPersonAddress, Phone: newPersonPhone, - Email: newPersonEmail + Email: newPersonEmail, + + BillAddress: { + AddressLine: newPersonBillAddressLine, + City: newPersonBillCity, + State: newPersonBillState, + PINCode: newPersonBillPINCode, + Country: newPersonBillCountry + }, + + // currently same as BillAddress + ShipAddress: { + AddressLine: newPersonBillAddressLine, + City: newPersonBillCity, + State: newPersonBillState, + PINCode: newPersonBillPINCode, + Country: newPersonBillCountry + }, } // TODO: show confirmation before being invisible @@ -57,46 +78,84 @@ const RegisterPersonForm: React.FC = (props) => {
-
- - - - - - - -
- -
- hideSelf()} /> - - +
+
+ + + + + +
+ +
+

Billing Address

+ + + + + + + + + + +
+ +
+ hideSelf()} /> + + +
diff --git a/src/components/Form/People/SelectClientForm.tsx b/src/components/Form/People/SelectClientForm.tsx index f91bf41..ca984ca 100644 --- a/src/components/Form/People/SelectClientForm.tsx +++ b/src/components/Form/People/SelectClientForm.tsx @@ -6,7 +6,7 @@ * Copyright (c) 2021 Vidhu Kant Sharma */ -import React, { useState } from "react"; +import React, { Dispatch, SetStateAction } from "react"; import { Person } from "./../../../interfaces"; import "./../Form.scss"; @@ -14,19 +14,19 @@ import ClientInfoDisplay from "../../Display/ClientInfoDisplay"; interface Props { savedPeople: Person[] + selectedClient: Person + setSelectedClient: Dispatch> } const SelectClientForm: React.FC = (props) => { - // TODO: fix the default selectedClient - const [selectedClient, setSelectedClient] = useState({Name: "", Address: ""}); - const enterValuePrompt = "start typing here"; const registerPrompt = "add new"; // TODO: make it use email if no address found, shorten the name too // in short, make formatter flexible const formatter = (i: Person): string => - `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.length < 20 ? "" : "")}`; + // TODO: this shit is ugly + `${i.Name} - ${i.BillAddress.AddressLine.slice(0, 20).concat(i.BillAddress.AddressLine.length < 20 ? "" : "")}`; // TODO: if no client found at least clear the display // do this in other components too @@ -35,7 +35,7 @@ const SelectClientForm: React.FC = (props) => { (props.savedPeople === null || e === registerPrompt) ? alert("coming soon") // toggle registerPersonPrompt visibility : props.savedPeople.some((i) => - e === formatter(i) && setSelectedClient(i)) + e === formatter(i) && props.setSelectedClient(i)) return (
@@ -43,7 +43,7 @@ const SelectClientForm: React.FC = (props) => { Client Name: - +
) } -- cgit v1.2.3