reuse customer
This commit is contained in:
@ -189,7 +189,7 @@ function App() {
|
||||
|
||||
{/* Customer Form */}
|
||||
<div className="no-print">
|
||||
<CustomerForm customer={customer} onChange={setCustomer} />
|
||||
<CustomerForm customer={customer} onChange={setCustomer} savedQuotes={savedQuotes} />
|
||||
</div>
|
||||
|
||||
{/* Item Selector */}
|
||||
|
||||
@ -1,14 +1,56 @@
|
||||
import React from 'react';
|
||||
|
||||
export default function CustomerForm({ customer, onChange }) {
|
||||
export default function CustomerForm({ customer, onChange, savedQuotes = [] }) {
|
||||
const handleChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
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 (
|
||||
<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-group">
|
||||
<label htmlFor="name">Name</label>
|
||||
|
||||
Reference in New Issue
Block a user