From ea88466fda6c719caa9daae5ea4698565fa84426 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Tue, 15 Jun 2021 12:25:46 +0530 Subject: fixed some errors in SelectClientForm --- server/database/people.go | 9 +++++---- server/filled.db | Bin 0 -> 57344 bytes src/components/Display/ClientInfoDisplay.js | 16 +++++++++++++--- src/components/Form/People/SelectClientForm.js | 18 ++++++++++-------- 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 server/filled.db diff --git a/server/database/people.go b/server/database/people.go index ac2affa..5fc3bf5 100644 --- a/server/database/people.go +++ b/server/database/people.go @@ -14,6 +14,7 @@ import ( _ "github.com/mattn/go-sqlite3" ) type Person struct { + ID string Name string Address string Phone string @@ -23,16 +24,16 @@ type Person struct { func GetAllPeople() []Person { var allPeople []Person rows, _ := myDatabase.Query( - `SELECT Name, Address, Phone, Email FROM People`, + `SELECT ID, Name, Address, Phone, Email FROM People`, ) var ( - name, address, phone, email string + id, name, address, phone, email string ) for rows.Next() { - rows.Scan(&name, &address, &phone, &email) - allPeople = append(allPeople, Person{name, address, phone, email}) + rows.Scan(&id, &name, &address, &phone, &email) + allPeople = append(allPeople, Person{id, name, address, phone, email}) } return allPeople diff --git a/server/filled.db b/server/filled.db new file mode 100644 index 0000000..d9258ed Binary files /dev/null and b/server/filled.db differ diff --git a/src/components/Display/ClientInfoDisplay.js b/src/components/Display/ClientInfoDisplay.js index 34f001b..7eb46d2 100644 --- a/src/components/Display/ClientInfoDisplay.js +++ b/src/components/Display/ClientInfoDisplay.js @@ -10,10 +10,20 @@ import React from "react"; import "./Display.scss"; const ClientInfoDisplay = (props) => { + //console.log(props.client) return ( -
- Client Name: {props.client.Name} -
+ + + + + + + + + + + +
Client Name:{props.client.Name}
Client Address:{props.client.Address}
); } diff --git a/src/components/Form/People/SelectClientForm.js b/src/components/Form/People/SelectClientForm.js index 4c1e056..49aa4ed 100644 --- a/src/components/Form/People/SelectClientForm.js +++ b/src/components/Form/People/SelectClientForm.js @@ -12,33 +12,35 @@ 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"; + // TODO: make it use email if no address found, shorten the name too + // in short, make formatter flexible const formatter = (i) => { return `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.length < 20 ? "" : "")}`; } + // TODO: if no client found at least clear the display + // do this in other components too // check the client name value and do stuff accordingly - const setClientInfo = (clientName) => - (props.savedPeople === null || clientName === registerPrompt) + const setClientInfo = (e) => + (props.savedPeople === null || e === registerPrompt) ? alert("coming soon") // toggle registerPersonPrompt visibility - : props.savedPeople.some((i) => - clientName === formatter(i) && setSelectedClient(i)) - + : props.savedPeople.some((i) => + e === formatter(i) && setSelectedClient(i)) + return (