adding search in credit_destination on update transaction fee

This commit is contained in:
bagusajisaputroo
2025-04-15 01:04:53 +07:00
parent f407780355
commit 83593db7ac

View File

@ -343,13 +343,19 @@ const EditFeeDialog = () => {
hasFetchedRef.current = false; hasFetchedRef.current = false;
} }
}, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]); }, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]);
const handleCloseDialog = () => { const handleCloseDialog = () => {
setFormField(initialState); setFormField(initialState);
setAlert({ show: false, message: '' }); setAlert({ show: false, message: '' });
setCustomerSearchTerm('');
setOpen(false);
handleEditFeeDialog(false, null); handleEditFeeDialog(false, null);
}; };
useEffect(() => {
if (!showEditFeeDialog) {
setCustomerSearchTerm('');
setOpen(false);
}
}, [showEditFeeDialog]);
const renderSelectWithLoading = ( const renderSelectWithLoading = (
value: string, value: string,
onChangeHandler: (value: string) => void, onChangeHandler: (value: string) => void,
@ -668,36 +674,51 @@ const EditFeeDialog = () => {
</Select> </Select>
</div> </div>
{formField.credit_to === 'I' && ( {formField.credit_to === 'I' && (
<div className="w-full"> <div className="w-full">
<label className="form-label"> <label className="form-label">
Credit Destination <span className="text-red-500">*</span> Credit Destination <span className="text-red-500">*</span>
</label> </label>
<Popover open={open} onOpenChange={setOpen}> <div className="relative">
<PopoverTrigger asChild> <div
<button className="flex w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 cursor-pointer"
type="button" onClick={() => setOpen(!open)}
className="input w-full text-left" >
> <span className="truncate">
{customers.find( {customers.find(customer => customer.id === formField.credit_destination)?.username || 'Search customer...'}
(customer) => customer.id === formField.credit_destination </span>
)?.username || 'Select Customer'} <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="h-4 w-4 opacity-50">
</button> <path d="m6 9 6 6 6-6"></path>
</PopoverTrigger> </svg>
<PopoverContent className="w-full p-0"> </div>
<Command className="w-full">
<CommandInput {open && (
placeholder="Search Customer..." <div className="absolute left-0 right-0 top-full z-50 mt-1 max-h-52 overflow-auto rounded-md border border-gray-200 bg-white shadow-lg">
className="w-full border-none px-3 py-2" <div className="sticky top-0 bg-white p-2 border-b">
/> <Input
<CommandList className="max-h-[250px] overflow-y-auto"> className="h-8 text-sm"
<CommandEmpty>No Customer found.</CommandEmpty> type="text"
<CommandGroup> placeholder="Search customer..."
{customers.map((customer) => ( value={customerSearchTerm}
<CommandItem onChange={(e) => setCustomerSearchTerm(e.target.value)}
key={customer.id} autoComplete="off"
value={customer.username} // Prevent clicks from closing the dropdown
onSelect={() => { onClick={(e) => e.stopPropagation()}
// Auto focus the input when opened
autoFocus
/>
</div>
<div>
{customers
.filter(customer =>
customer.username.toLowerCase().includes(customerSearchTerm.toLowerCase()) ||
customer.msisdn.includes(customerSearchTerm)
)
.map(customer => (
<div
key={customer.id}
className="cursor-pointer px-3 py-1.5 text-sm hover:bg-gray-100"
onClick={() => {
setFormField({ setFormField({
...formField, ...formField,
credit_destination: customer.id credit_destination: customer.id
@ -706,17 +727,23 @@ const EditFeeDialog = () => {
}} }}
> >
{customer.username} {customer.username}
</CommandItem> </div>
))} ))}
</CommandGroup> {customers.filter(customer =>
</CommandList> customer.username.toLowerCase().includes(customerSearchTerm.toLowerCase()) ||
</Command> customer.msisdn.includes(customerSearchTerm)
</PopoverContent> ).length === 0 && (
</Popover> <div className="px-3 py-2 text-sm text-gray-500">No customer found</div>
)}
</div>
</div>
)}
</div>
</div> </div>
)} )}
<div className="w-full"> <div className="w-full">
<label className="form-label"> <label className="form-label">