update provider

This commit is contained in:
Wikzyy
2025-03-25 13:58:05 +07:00
parent 50bd7980b2
commit 20421f2d00
3 changed files with 45 additions and 44 deletions

View File

@ -33,6 +33,7 @@ import {
} from '@/components/ui/command';
export interface CustomerProps {
id: string;
msisdn: string;
email: string;
fullname: string;
@ -86,7 +87,7 @@ const AddDialog = () => {
const response = await PostData(`${API_URL_MASTERDATA}/provider/create`, formField);
if (response?.status) {
resetForm();
// resetForm();
handleAddDialog(false);
toast.success('Success Create Provider');
reload();
@ -116,6 +117,41 @@ const AddDialog = () => {
setAlert({ show: false, message: '' });
};
const getTransactionTypeList = async (sorting: any) => {
try {
const response = await GetData(`${API_URL_TRANSACTION}/transactiontype/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('TRANSACTION TYPE: ', response?.data);
setTransactions(response?.data.list);
} catch (error) {
console.error('Error fetching transaction type', error);
}
};
const getCustomerList = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('CUSTOMER: ', response?.data);
setCustomers(response?.data.list);
} catch (error) {
console.error('Error fetching customer', error);
}
};
useEffect(() => {
if (showAddDialog) {
setFormField({
@ -127,42 +163,7 @@ const AddDialog = () => {
}, [formattedTime]);
useEffect(() => {
const getCustomerList = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('CUSTOMER: ', response?.data);
setCustomers(response?.data.list);
} catch (error) {
console.error('Error fetching customer', error);
}
};
const getTransactionTypeList = async (sorting: any) => {
try {
const response = await GetData(`${API_URL_TRANSACTION}/transactiontype/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('TRANSACTION TYPE: ', response?.data);
setTransactions(response?.data.list);
} catch (error) {
console.error('Error fetching transaction type', error);
}
};
getCustomerList([{ id: 'msisdn', desc: false }]);
getCustomerList([{ id: 'id', desc: false }]);
getTransactionTypeList([{ id: 'name', desc: false }]);
}, []);
@ -290,7 +291,7 @@ const AddDialog = () => {
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<button type="button" className="input col-span-5 text-left">
{customers.find((customer) => customer.msisdn === formField.agent)
{customers.find((customer) => customer.id === formField.agent)
?.fullname || 'Select Agent'}
</button>
</PopoverTrigger>
@ -302,12 +303,12 @@ const AddDialog = () => {
<CommandGroup>
{customers.map((customer) => (
<CommandItem
key={customer.msisdn}
value={customer.fullname}
key={customer.id}
value={customer.id}
onSelect={() => {
setFormField({
...formField,
agent: customer.msisdn
agent: customer.id
});
setOpen(false);
}}