blob: 06704d7d49847d949f8f39323f4756649022e2ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* 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, { useState } from "react";
import "./../Form.scss";
import ClientInfoDisplay from "../../Display/ClientInfoDisplay";
const SelectClientForm = (props) => {
const [clientName, setClientName] = useState();
const [selectedClient, setSelectedClient] = useState({});
const enterValuePrompt = "start typing here";
const registerPrompt = "add new";
const formatter = (i) => `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.len < 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)
return (
<div className={"DocumentInfoChild"}>
<label>
Client Name:
<select
className={"selectInputBox"}
value={clientName}
onChange={
(event) => {
setClientName(event.target.value);
setItemInfo(event.target.value);
}
}>
<option key={enterValuePrompt}>{enterValuePrompt}</option>
{props.savedPeople === null || props.savedPeople.map(
(i) => <option key={i.ID}>{formatter(i)}</option>
)}
<option key={registerPrompt}>{registerPrompt}</option>
</select>
</label>
<ClientInfoDisplay client={selectedClient}/>
</div>
)
}
export default SelectClientForm;
|