From 92b6da1d37da9232f1f40ac2526b189289049534 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Mon, 13 Sep 2021 17:25:51 +0530 Subject: created new new address component for unlimited addresses --- src/components/Form/Address/NewAddressPane.tsx | 69 +++++++++++ src/components/Form/People/RegisterPersonForm.tsx | 132 +++------------------- 2 files changed, 86 insertions(+), 115 deletions(-) create mode 100644 src/components/Form/Address/NewAddressPane.tsx (limited to 'src/components') diff --git a/src/components/Form/Address/NewAddressPane.tsx b/src/components/Form/Address/NewAddressPane.tsx new file mode 100644 index 0000000..4dd3788 --- /dev/null +++ b/src/components/Form/Address/NewAddressPane.tsx @@ -0,0 +1,69 @@ +/* + * OpenBills - Self hosted browser app to generate and keep track of simple invoices + * Version - 0 + * Licensed under the MIT license - https://opensource.org/licenses/MIT + * + * Copyright (c) 2021 Vidhu Kant Sharma +*/ + +import React, { Dispatch, SetStateAction, useState } from "react"; +import "./../Form.scss"; +import { Address } from "./../../../Interfaces/interfaces" + +interface Props { + heading: string + address: Address + setAddress: Dispatch> +} + +const NewAddressPane: React.FC = (props) => { + const address = props.address; + +return ( +
+

{props.heading}

+ + + + + + + + + + +
+ ); +} + +export default NewAddressPane; diff --git a/src/components/Form/People/RegisterPersonForm.tsx b/src/components/Form/People/RegisterPersonForm.tsx index 3fc8b32..9c8752d 100644 --- a/src/components/Form/People/RegisterPersonForm.tsx +++ b/src/components/Form/People/RegisterPersonForm.tsx @@ -7,9 +7,10 @@ */ import React, { useState } from "react"; -import "./../Form.scss"; -import { Person } from "./../../../interfaces" +import NewAddressPane from "./../Address/NewAddressPane" +import { Person, Address } from "./../../../Interfaces/interfaces" import axios from "axios"; +import "./../Form.scss"; interface props { setVisibility: any // this component's visibility @@ -23,12 +24,13 @@ const RegisterPersonForm: React.FC = (props) => { const [shipToBillAddress, setShipToBillAddress] = useState(true); - const [newPersonBillAddressLine, setNewPersonBillAddressLine] = useState(""); - const [newPersonBillCity, setNewPersonBillCity] = useState(""); - const [newPersonBillState, setNewPersonBillState] = useState(""); - const [newPersonBillPINCode, setNewPersonBillPINCode] = useState(""); - const [newPersonBillCountry, setNewPersonBillCountry] = useState(""); - + const [newPersonBillAddress, setNewPersonBillAddress] = useState
({ + AddressLine: "", + City: "", + State: "", + PINCode: "", + Country: "" + }) const hideSelf = () => props.setVisibility(false); @@ -43,26 +45,15 @@ const RegisterPersonForm: React.FC = (props) => { Phone: newPersonPhone, 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 - }, + BillAddress: newPersonBillAddress, + ShipAddress: shipToBillAddress + ? newPersonBillAddress + // TODO: use shipping address(es) instead + : newPersonBillAddress, } // TODO: show confirmation before being invisible - // TODO: Implement override protection + // TODO: Implement overwrite protection axios.post("/api/people/register", newClient) .then((res) => { console.log(res); @@ -111,96 +102,7 @@ const RegisterPersonForm: React.FC = (props) => { -
-

Billing Address

- - - - - - - - - - -
- - {shipToBillAddress || // TODO: Make it store different data - // TODO: maybe move it to its own prop -
-

Shipping Address

- - - - - - - - - - -
- } +