reuse customer
This commit is contained in:
30
quotes.json
30
quotes.json
@ -482,5 +482,35 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"shippingCost": 0
|
"shippingCost": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8071,
|
||||||
|
"date": "March 24, 2026",
|
||||||
|
"customer": {
|
||||||
|
"name": "LOCATION WINDSOR",
|
||||||
|
"address": "89 RUE PRINCIPALE S",
|
||||||
|
"city": "WINDSOR",
|
||||||
|
"province": "QC",
|
||||||
|
"postalCode": "J1S 2B9",
|
||||||
|
"phone": "819 845 7874",
|
||||||
|
"email": "martin.dion@locationwindsor.com"
|
||||||
|
},
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"Item ID": "4X36-SSS",
|
||||||
|
"Description": "Auger, Snap-on",
|
||||||
|
"Price": 383.36166000000003,
|
||||||
|
"quantity": 1,
|
||||||
|
"discount": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Item ID": "6X36-SSP",
|
||||||
|
"Description": "Auger, Snap-on, Pengo Style",
|
||||||
|
"Price": 577.8892350000001,
|
||||||
|
"quantity": 2,
|
||||||
|
"discount": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"shippingCost": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -189,7 +189,7 @@ function App() {
|
|||||||
|
|
||||||
{/* Customer Form */}
|
{/* Customer Form */}
|
||||||
<div className="no-print">
|
<div className="no-print">
|
||||||
<CustomerForm customer={customer} onChange={setCustomer} />
|
<CustomerForm customer={customer} onChange={setCustomer} savedQuotes={savedQuotes} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Item Selector */}
|
{/* Item Selector */}
|
||||||
|
|||||||
@ -1,14 +1,56 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export default function CustomerForm({ customer, onChange }) {
|
export default function CustomerForm({ customer, onChange, savedQuotes = [] }) {
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
onChange({ ...customer, [name]: value });
|
onChange({ ...customer, [name]: value });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uniqueCustomers = [];
|
||||||
|
const seenNames = new Set();
|
||||||
|
|
||||||
|
savedQuotes.forEach(quote => {
|
||||||
|
const c = quote.customer;
|
||||||
|
if (c && c.name && c.name.trim() !== '') {
|
||||||
|
const normalized = c.name.trim().toLowerCase();
|
||||||
|
if (!seenNames.has(normalized)) {
|
||||||
|
seenNames.add(normalized);
|
||||||
|
uniqueCustomers.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSelectExisting = (e) => {
|
||||||
|
if (e.target.value === "") return;
|
||||||
|
const selected = uniqueCustomers[parseInt(e.target.value, 10)];
|
||||||
|
if (selected) {
|
||||||
|
onChange({ ...customer, ...selected });
|
||||||
|
}
|
||||||
|
// reset the select back to default after choosing
|
||||||
|
e.target.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="glass-card">
|
<div className="glass-card">
|
||||||
<h2>Customer Information</h2>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '1.5rem', flexWrap: 'wrap', gap: '1rem' }}>
|
||||||
|
<h2 style={{ margin: 0 }}>Customer Information</h2>
|
||||||
|
{uniqueCustomers.length > 0 && (
|
||||||
|
<div className="form-group" style={{ flexDirection: 'row', alignItems: 'center', gap: '0.5rem', flex: '0 0 auto' }}>
|
||||||
|
<label htmlFor="existingCustomer" style={{ margin: 0 }}>Load Customer:</label>
|
||||||
|
<select
|
||||||
|
id="existingCustomer"
|
||||||
|
onChange={handleSelectExisting}
|
||||||
|
defaultValue=""
|
||||||
|
style={{ padding: '0.5rem', width: '220px' }}
|
||||||
|
>
|
||||||
|
<option value="">-- Select Existing --</option>
|
||||||
|
{uniqueCustomers.map((c, i) => (
|
||||||
|
<option key={i} value={i}>{c.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="form-grid">
|
<div className="form-grid">
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label htmlFor="name">Name</label>
|
<label htmlFor="name">Name</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user