From 671c3a765ffc53575f517cef715dc16be5aa43c5 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Fri, 11 Jun 2021 17:17:26 +0530 Subject: cleaned up some code and fixed formatter for the client name/address --- src/components/Form/Document/DocumentInfoForm.js | 22 ++-------------------- src/components/Form/Items/AddNewItemForm.js | 3 ++- src/components/Form/People/SelectClientForm.js | 20 +++++++++----------- 3 files changed, 13 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/components/Form/Document/DocumentInfoForm.js b/src/components/Form/Document/DocumentInfoForm.js index 367d4f2..09bb9c6 100644 --- a/src/components/Form/Document/DocumentInfoForm.js +++ b/src/components/Form/Document/DocumentInfoForm.js @@ -12,29 +12,11 @@ import "./../Form.scss"; import SelectClientForm from "./../People/SelectClientForm"; -const DocumentInfoForm = (/*props*/) => { - const savedPeople = [ - { - ID: 1, - Name: "one", - Address: "Address Line 1" - }, - { - ID: 2, - Name: "two", - Address: "Address Line 1 Line2 Lelfjdlfj" - }, - { - ID: 3, - Name: "three", - Address: "ALinldfjlasjfe 1asdjflajdslfjsalkdjfdslkfjslkdfjlksjdflkjsdlkfjdlfjslkjfdlkadsflj" - }, - ] - +const DocumentInfoForm = (props) => { return (
); diff --git a/src/components/Form/Items/AddNewItemForm.js b/src/components/Form/Items/AddNewItemForm.js index a4710f9..37167fd 100644 --- a/src/components/Form/Items/AddNewItemForm.js +++ b/src/components/Form/Items/AddNewItemForm.js @@ -39,7 +39,8 @@ const AddNewItemForm = (props) => { const setItemInfo = (itemName) => (props.savedItems === null || itemName === registerItemPrompt) ? props.registerItemFormVisibility(true) - : props.savedItems.some((i) => itemName === i.Model.toLowerCase() && applyItemInfo(i)) + : props.savedItems.some((i) => + itemName === i.Model.toLowerCase() && applyItemInfo(i)) const resetAllValues = () => { setItemNameValue(""); diff --git a/src/components/Form/People/SelectClientForm.js b/src/components/Form/People/SelectClientForm.js index 06704d7..4c1e056 100644 --- a/src/components/Form/People/SelectClientForm.js +++ b/src/components/Form/People/SelectClientForm.js @@ -18,18 +18,16 @@ const SelectClientForm = (props) => { const enterValuePrompt = "start typing here"; const registerPrompt = "add new"; - const formatter = (i) => `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.len < 20 ? "" : "...")}`; + const formatter = (i) => { + return `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.length < 20 ? "" : "")}`; + } // check the client name value and do stuff accordingly - const setItemInfo = (clientName) => - props.savedPeople.some( - (i) => clientName === formatter(i) - ? setSelectedClient(i) - : clientName === registerPrompt - && alert("coming soon") - ) - - console.log(selectedClient) + const setClientInfo = (clientName) => + (props.savedPeople === null || clientName === registerPrompt) + ? alert("coming soon") // toggle registerPersonPrompt visibility + : props.savedPeople.some((i) => + clientName === formatter(i) && setSelectedClient(i)) return (
@@ -41,7 +39,7 @@ const SelectClientForm = (props) => { onChange={ (event) => { setClientName(event.target.value); - setItemInfo(event.target.value); + setClientInfo(event.target.value); } }> -- cgit v1.2.3