From af0ef4c190f3967d2def0c65cc3a1fce4511044e Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 27 Sep 2022 12:25:56 +0530 Subject: added shipping address functionality to /manage/clients page --- src/components/editors/contact-editor.js | 35 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/components/editors/contact-editor.js') diff --git a/src/components/editors/contact-editor.js b/src/components/editors/contact-editor.js index 325f4f4..3c9a1f9 100644 --- a/src/components/editors/contact-editor.js +++ b/src/components/editors/contact-editor.js @@ -18,13 +18,22 @@ import { Contact } from './../../classes/client'; import './scss/contact-editor.scss'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; const ContactEditor = (props) => { - const [name, setName] = useState(""); - const [phones, setPhones] = useState(""); - const [emails, setEmails] = useState(""); - const [website, setWebsite] = useState(""); + const handleInput = (field, event) => { + const c = new Contact(); + const val = event.target.value; + c.Name = field === "name" ? val : props.contact.Name; + c.Website = field === "website" ? val : props.contact.Website; + c.Phones = field === "phones" + ? (val.length === 0 ? [] : val.split("\n")) + : props.contact.Phones; + c.Emails = field === "emails" + ? (val.length === 0 ? [] : val.split("\n")) + : props.contact.Emails; + props.setContact(c); + } return (
@@ -35,28 +44,36 @@ const ContactEditor = (props) => { Contact Name: setName(e.target.value)} /> + value={props.contact.Name} onChange={(e) => handleInput("name", e)} />