aboutsummaryrefslogtreecommitdiff
path: root/src/components/editors/contact-editor.js
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-27 12:25:56 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-27 12:25:56 +0530
commitaf0ef4c190f3967d2def0c65cc3a1fce4511044e (patch)
treebba973c45ca5197ebf336d5e2f7f0f599b74bccd /src/components/editors/contact-editor.js
parent708862c94bd119ca7e86540fbc68595a6256c9e3 (diff)
added shipping address functionality to /manage/clients page
Diffstat (limited to 'src/components/editors/contact-editor.js')
-rw-r--r--src/components/editors/contact-editor.js35
1 files changed, 26 insertions, 9 deletions
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 (
<div className={"contact-editor"}>
@@ -35,28 +44,36 @@ const ContactEditor = (props) => {
Contact Name:
<input
type="text" name="name"
- value={name} onChange={(e) => setName(e.target.value)} />
+ value={props.contact.Name} onChange={(e) => handleInput("name", e)} />
</label>
<label>
Website:
<input
type="text" name="name"
- value={website} onChange={(e) => setWebsite(e.target.value)} />
+ value={props.contact.Website} onChange={(e) => handleInput("website", e)} />
</label>
<label>
Phone:
<textarea
type="text" name="name"
- value={phones} onChange={(e) => setPhones(e.target.value)} />
+ value={props.contact.Phones.length > 0
+ ? props.contact.Phones.forEach(i => i)
+ : ""
+ }
+ onChange={(e) => handleInput("phones", e)} />
</label>
<label>
E-mail:
<textarea
type="text" name="name"
- value={emails} onChange={(e) => setEmails(e.target.value)} />
+ value={props.contact.Emails.length > 0
+ ? props.contact.Emails.forEach(i => i)
+ : ""
+ }
+ onChange={(e) => handleInput("emails", e)} />
</label>
</div>
</div>