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/Document/DocumentInfoForm.tsx | 19 +++ src/components/Form/People/RegisterPersonForm.tsx | 149 +++++++++++++++------- src/components/Form/People/SelectClientForm.tsx | 16 +-- src/components/Pages/BillingPage.tsx | 15 +-- src/interfaces.ts | 12 +- 5 files changed, 148 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/components/Form/Document/DocumentInfoForm.tsx b/src/components/Form/Document/DocumentInfoForm.tsx index 6135b33..2d7dcd9 100644 --- a/src/components/Form/Document/DocumentInfoForm.tsx +++ b/src/components/Form/Document/DocumentInfoForm.tsx @@ -25,12 +25,31 @@ interface Props { } const DocumentInfoForm: React.FC = (props) => { + const dummyPerson: Person = { + Name: "", + Address: "", + Phone: "", + Email: "", + + BillAddress: { + AddressLine: "", + City: "", + State: "", + PINCode: "", + Country: "India" // TODO: Get default from server + } + } + const [invoiceNumber, setInvoiceNumber] = useState(props.invoiceNumber); const [invoiceDate, setInvoiceDate] = useState(new Date()); + const [selectedClient, setSelectedClient] = useState(dummyPerson); + return (
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: - +
) } diff --git a/src/components/Pages/BillingPage.tsx b/src/components/Pages/BillingPage.tsx index 58fdd40..9dcb485 100644 --- a/src/components/Pages/BillingPage.tsx +++ b/src/components/Pages/BillingPage.tsx @@ -56,13 +56,6 @@ const BillingPage: React.FC = () => { // update the items from AddNewItemForm const getItems = (item: Item) => setItems([...items, item]); - const handleSubmit = () => { - setShowSubmitMenu(true); - axios.post(`/api/invoices/preview`, {ID: 1010, Items: items, Transporter: transporter}) - .then(() => alert("yay")) - .catch(() => alert("nay")); - } - return ( <> {registerItemFormVisibility && @@ -83,8 +76,8 @@ const BillingPage: React.FC = () => { {showTransportForm && } @@ -119,8 +112,12 @@ const BillingPage: React.FC = () => { + + + -
); diff --git a/src/interfaces.ts b/src/interfaces.ts index 3500c2b..b2f354c 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -34,12 +34,22 @@ export interface NewItem { // category and brand } +export interface Address { + AddressLine: string + City: string + State: string + PINCode: string + Country: string +} + export interface Person { ID?: number Name: string - Address: string Phone?: string Email?: string + BillAddress: Address + ShipAddress?: Address + Address?: string // to be removed } export interface Invoice { -- cgit v1.2.3