bar code imaghe is saved to DB
This commit is contained in:
@@ -25,22 +25,36 @@ export interface BillEditFormProps {
|
||||
|
||||
export const BillEditForm:FC<BillEditFormProps> = ({ location, bill }) => {
|
||||
|
||||
const { _id: billID, name, paid, attachment, notes, payedAmount } = bill ?? { _id:undefined, name:"", paid:false, notes:"" };
|
||||
const { _id: billID, name, paid, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, notes:"" };
|
||||
|
||||
const { yearMonth:{year: billYear, month: billMonth}, _id: locationID } = location;
|
||||
|
||||
const initialState = { message: null, errors: {} };
|
||||
|
||||
const handleAction = updateOrAddBillMiddleware.bind(null, locationID, billID, billYear, billMonth);
|
||||
const [ state, dispatch ] = useFormState(handleAction, initialState);
|
||||
|
||||
const [ state, dispatch ] = useFormState(handleAction, initialState);
|
||||
const [ isPaid, setIsPaid ] = React.useState<boolean>(paid);
|
||||
const [ payedAmount, setPayedAmount ] = React.useState<number>(initialPayedAmount ?? 0);
|
||||
const [ barcodeImage, setBarcodeImage ] = React.useState<string | undefined>(initialBarcodeImage);
|
||||
|
||||
const billPaid_handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setIsPaid(event.target.checked);
|
||||
}
|
||||
|
||||
const billAttachment_handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
findDecodePdf417(event).then(result => console.log(result));
|
||||
findDecodePdf417(event)
|
||||
.then(result => {
|
||||
if(result) {
|
||||
const {
|
||||
barcodeImage,
|
||||
billInfo
|
||||
} = result;
|
||||
|
||||
setPayedAmount(billInfo.amount);
|
||||
setBarcodeImage(barcodeImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return(
|
||||
@@ -99,7 +113,7 @@ export const BillEditForm:FC<BillEditFormProps> = ({ location, bill }) => {
|
||||
<div className="form-control p-1">
|
||||
<label className="cursor-pointer label p-0 flex">
|
||||
<span className="label-text flex-none w-[6.4em]">Amount</span>
|
||||
<input type="text" id="payedAmount" name="payedAmount" className="input input-bordered text-right w-full" placeholder="0.00" defaultValue={payedAmount === null || payedAmount === undefined ? undefined : payedAmount / 100}/>
|
||||
<input type="text" id="payedAmount" name="payedAmount" className="input input-bordered text-right w-full" placeholder="0.00" defaultValue={payedAmount/100}/>
|
||||
</label>
|
||||
</div>
|
||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
||||
@@ -113,6 +127,18 @@ export const BillEditForm:FC<BillEditFormProps> = ({ location, bill }) => {
|
||||
</>
|
||||
}
|
||||
|
||||
<input type="hidden" name="barcodeImage" value={barcodeImage} />
|
||||
{
|
||||
barcodeImage ?
|
||||
<div className="form-control w-[325px] p-1">
|
||||
<label className="cursor-pointer label p-0">
|
||||
<span>
|
||||
<img src={barcodeImage} style={{ maxWidth:"325px" }} />
|
||||
</span>
|
||||
</label>
|
||||
</div> : null
|
||||
}
|
||||
|
||||
<textarea id="billNotes" name="billNotes" className="textarea textarea-bordered my-2 max-w-lg w-full block" placeholder="Note" defaultValue={notes ?? ''}></textarea>
|
||||
<div id="status-error" aria-live="polite" aria-atomic="true">
|
||||
{state.errors?.billNotes &&
|
||||
|
||||
Reference in New Issue
Block a user