butuh install packagee react number format
This commit is contained in:
411
src/pages/transfer/transferfee/blocks/AddDialog.tsx
Normal file
411
src/pages/transfer/transferfee/blocks/AddDialog.tsx
Normal file
@ -0,0 +1,411 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
|
||||
import { NumericFormat } from 'react-number-format';
|
||||
import {
|
||||
Alert,
|
||||
Container,
|
||||
DataGridColumnHeader,
|
||||
DataGridInner,
|
||||
KeenIcon,
|
||||
useDataGrid
|
||||
} from '@/components';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { toast } from 'sonner';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
import { getAuth } from '@/auth';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCaption,
|
||||
TableCell,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow
|
||||
} from '@/components/ui/table';
|
||||
import { ManageTransferFeeContext } from '../hooks/ManageTransferFeeContext';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { ManageTransferFeeContextProvider } from '../../transferfee/hooks/ManageTransferFeeContext';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { get } from 'http';
|
||||
|
||||
interface TransactionTypeProps {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const AddFeeDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { reload } = useDataGrid();
|
||||
const { PostData, PutData, GetData } = useCallApi();
|
||||
const { showAddFeeDialog, handleAddFeeDialog, handleEditFeeDialog, selectedTransferFee } =
|
||||
useManageTransferFeeContext();
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
const [transactionTypes, setTransactionTypes] = useState<TransactionTypeProps[]>([]);
|
||||
|
||||
const initialState = {
|
||||
name: '',
|
||||
description: '',
|
||||
transaction_type: '',
|
||||
minimum_amount: 0,
|
||||
maximum_amount: 0,
|
||||
period_start: '',
|
||||
period_end: '',
|
||||
deduct_amount: 0,
|
||||
deduct_percentage: 0,
|
||||
priority: false,
|
||||
status: '',
|
||||
status_include: '',
|
||||
created_by: '',
|
||||
created_at: ''
|
||||
};
|
||||
|
||||
const [formField, setFormField] = useState(initialState);
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(initialState);
|
||||
};
|
||||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [showTransactionFeeDialog, setShowTransactionFeeDialog] = useState(false);
|
||||
const parsedUser = getAuth()?.user;
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
// setIsSubmitting(true);
|
||||
const payload = {
|
||||
name: formField.name,
|
||||
description: formField.description,
|
||||
period_start: formField.period_start,
|
||||
period_end: formField.period_end,
|
||||
minimum_amount: formField.minimum_amount,
|
||||
maximum_amount: formField.maximum_amount,
|
||||
deduct_amount: formField.deduct_amount,
|
||||
deduct_percentage: formField.deduct_percentage,
|
||||
priority: formField.priority,
|
||||
transaction_type: formField.transaction_type,
|
||||
status: formField.status,
|
||||
status_include: formField.status_include
|
||||
};
|
||||
console.log(payload);
|
||||
};
|
||||
useEffect(() => {
|
||||
const created_time = new Date();
|
||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
if (showAddFeeDialog) {
|
||||
setFormField({
|
||||
...formField,
|
||||
created_by: parsedUser?.username,
|
||||
created_at: formattedTime
|
||||
});
|
||||
}
|
||||
}, [showAddFeeDialog]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAddFeeDialog) return;
|
||||
|
||||
const getTransactionTypeList = async (sorting: any) => {
|
||||
try {
|
||||
sorting = sorting.length === 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
const response = await GetData(`${API_URL}/transactiontype/list`, {
|
||||
limit: 100,
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||
});
|
||||
console.log('TRANSACTION TYPE LIST: ', response?.data?.list);
|
||||
|
||||
setTransactionTypes(response?.data.list || []);
|
||||
} catch (error) {
|
||||
console.error('Error fetching customer', error);
|
||||
}
|
||||
};
|
||||
|
||||
getTransactionTypeList([{ id: 'id', desc: false }]);
|
||||
}, [showAddFeeDialog]);
|
||||
|
||||
const doCreateTransferType = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
console.log(formField);
|
||||
for (const key in formField) {
|
||||
if (
|
||||
formField[key as keyof typeof formField] === '' ||
|
||||
formField[key as keyof typeof formField] === 0
|
||||
) {
|
||||
setAlert({ show: true, message: 'All fields must be filled out' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setAlert({ show: false, message: '' });
|
||||
const response = await PostData(`${API_URL}/transactionfees/create`, {
|
||||
...formField,
|
||||
priority: formField.priority ? 'Y' : 'N'
|
||||
});
|
||||
// console.log("coba coba:",response);
|
||||
|
||||
if (response?.status) {
|
||||
toast.success('Success Create Transfer Fee');
|
||||
reload();
|
||||
resetForm();
|
||||
handleAddFeeDialog(false);
|
||||
} else {
|
||||
setAlert({ show: true, message: response?.message || 'Failed to create transfer fee' });
|
||||
}
|
||||
console.log(response);
|
||||
},
|
||||
[formField]
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog open={showAddFeeDialog} onOpenChange={(open) => handleAddFeeDialog(open)}>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogTitle></DialogTitle>
|
||||
<DialogDescription></DialogDescription>
|
||||
<DialogHeader className="p-5 border-0">
|
||||
<div className="flex items-center justify-between flex-wrap grow">
|
||||
<div className="flex flex-col justify-center">
|
||||
<h1 className="text-xl font-semibold leading-none text-gray-900">AddTransfer Fee</h1>
|
||||
</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-100 opacity-50"
|
||||
onClick={() => {
|
||||
handleAddFeeDialog(false);
|
||||
resetForm();
|
||||
}}
|
||||
>
|
||||
<KeenIcon icon="cross" className="text-1.5xl" />
|
||||
</div>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
<DialogBody className="max-h-[1080px] overflow-y-auto">
|
||||
{alert.show && <Alert variant="danger">{alert.message}</Alert>}
|
||||
<form action="" onSubmit={doCreateTransferType}>
|
||||
<div className="card flex flex-col gap-5">
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Free Name</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
value={formField.name}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Description</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
value={formField.description}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, description: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Minimum Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.minimum_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
minimum_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Max Transaction Per Day"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Maximum Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.maximum_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
maximum_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Max Transaction Per Day"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period Start</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
autoComplete="off"
|
||||
value={formField.period_start ? formField.period_start.split('T')[0] : ''}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, period_start: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period End</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
autoComplete="off"
|
||||
value={formField.period_end ? formField.period_end.split('T')[0] : ''}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, period_end: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.deduct_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
deduct_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Max Transaction Per Day"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Percentage</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.deduct_percentage}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
deduct_percentage: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Max Transaction Per Day"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transacsion Type ID</label>
|
||||
<Select
|
||||
value={formField.transaction_type}
|
||||
onValueChange={(transaction_type) =>
|
||||
setFormField((prev) => ({ ...prev, transaction_type }))
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{transactionTypes.map((transactiontype, idx) => (
|
||||
<SelectItem value={transactiontype.id} key={transactiontype.id}>
|
||||
{transactiontype.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status</label>
|
||||
<Select
|
||||
value={formField.status}
|
||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status Include</label>
|
||||
<Select
|
||||
value={formField.status_include}
|
||||
onValueChange={(value) => setFormField({ ...formField, status_include: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Priority</label>
|
||||
<Select
|
||||
value={formField.priority ? 'Y' : 'N'}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, priority: value === 'Y' })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Priority" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex justify-end pt-2.5 gap-5">
|
||||
<Button variant={'outline'} type="reset">
|
||||
Reset
|
||||
</Button>
|
||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</DialogBody>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddFeeDialog;
|
||||
87
src/pages/transfer/transferfee/blocks/DeleteDialog.tsx
Normal file
87
src/pages/transfer/transferfee/blocks/DeleteDialog.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Alert, useDataGrid } from '@/components';
|
||||
import { ChangeEvent, useCallback, useState } from 'react';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { toast } from 'sonner';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
import { EnforceSwitch } from '@/components/switch';
|
||||
import { useContext } from 'react';
|
||||
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
|
||||
import { ManageTransferFeeContext } from '../hooks/ManageTransferFeeContext';
|
||||
import { DialogDescription } from '@radix-ui/react-dialog';
|
||||
import { useManageAccessTypeContext } from '@/pages/access/access-type/hooks/useManageAccessTypeContext';
|
||||
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const DeleteDialog = () => {
|
||||
const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } = useManageTransferFeeContext();
|
||||
const { reload } = useDataGrid();
|
||||
const { DeleteData } = useCallApi();
|
||||
const [enforce, setEnforce] = useState(false);
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
|
||||
const doDeleteTransferFee = useCallback(async () => {
|
||||
console.log("Selected Transfer Fee:", selectedTransferFee, "Type:", typeof selectedTransferFee);
|
||||
const response = await DeleteData(`${API_URL}/transactionfees/delete/${selectedTransferFee}/${enforce}`, {
|
||||
id: selectedTransferFee
|
||||
});
|
||||
|
||||
if (response?.status) {
|
||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
||||
handleDeleteFeeDialog(false, null);
|
||||
toast.success('Success Delete Product');
|
||||
reload();
|
||||
} else {
|
||||
toast.error('Failed Delete Product');
|
||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
||||
}
|
||||
}, [selectedTransferFee, enforce]);
|
||||
|
||||
// console.log(selectedTransferFee);
|
||||
|
||||
return (
|
||||
<Dialog open={showDeleteFeeDialog} onOpenChange={(open) => handleDeleteFeeDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-0 border-0 block">
|
||||
<DialogTitle className="text-lg">Delete Transfer Type</DialogTitle>
|
||||
<DialogDescription className="text-sm">Delete Transfer Type</DialogDescription>
|
||||
<Alert variant="warning">
|
||||
<h3 className="text-lg">Are you sure?</h3>
|
||||
<span className="text-sm">you will delete this data!</span>
|
||||
<div className="mt-2 flex items-center gap-x-2">
|
||||
<label className="form-label max-w-56">Hard Delete</label>
|
||||
<EnforceSwitch
|
||||
enforce={enforce}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
||||
setEnforce(e.target.checked);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Alert>
|
||||
{alert.show && (
|
||||
<Alert variant="danger">
|
||||
<h3>{alert.message}</h3>
|
||||
</Alert>
|
||||
)}
|
||||
</DialogHeader>
|
||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
||||
<Button variant={'outline'} onClick={() => handleDeleteFeeDialog(false, null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant={'destructive'} onClick={() => doDeleteTransferFee()}>
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeleteDialog;
|
||||
|
||||
export { DeleteDialog };
|
||||
499
src/pages/transfer/transferfee/blocks/EditDialog.tsx
Normal file
499
src/pages/transfer/transferfee/blocks/EditDialog.tsx
Normal file
@ -0,0 +1,499 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { NumericFormat } from 'react-number-format';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog';
|
||||
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { Alert, Container, DataGridInner, KeenIcon, useDataGrid } from '@/components';
|
||||
import { toast } from 'sonner';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
import { getAuth } from '@/auth';
|
||||
import { ManageTransferFeeContextProvider } from '../../transferfee/hooks/ManageTransferFeeContext';
|
||||
import AddFeeDialog from '../../transferfee/blocks/AddDialog';
|
||||
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
const API_URL_MASTERDATA = apiConfig.service_master_data;
|
||||
const API_URL_CUSTOMER = apiConfig.service_customer;
|
||||
|
||||
interface WalletProps {
|
||||
Wallet_id: string;
|
||||
Wallet_name: string;
|
||||
}
|
||||
|
||||
interface CustomerProps {
|
||||
id: string;
|
||||
username: string;
|
||||
msisdn: string;
|
||||
}
|
||||
|
||||
interface TransactionTypeProps {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const EditFeeDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { showEditFeeDialog, handleEditFeeDialog, selectedTransferFee } =
|
||||
useManageTransferFeeContext();
|
||||
const { reload } = useDataGrid();
|
||||
const [wallets, setWallets] = useState<WalletProps[]>([]);
|
||||
const { GetData, PutData } = useCallApi();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [transactionTypes, setTransactionTypes] = useState<TransactionTypeProps[]>([]);
|
||||
const parsedUser = getAuth()?.user;
|
||||
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
const [formField, setFormField] = useState({
|
||||
name: '',
|
||||
description: '',
|
||||
minimum_amount: 0,
|
||||
maximum_amount: 0,
|
||||
period_start: '',
|
||||
period_end: '',
|
||||
deduct_amount: 0,
|
||||
deduct_percentage: 0,
|
||||
priority: '',
|
||||
status: '',
|
||||
status_include: '',
|
||||
transaction_type: '',
|
||||
updated_by: '',
|
||||
updated_at: ''
|
||||
});
|
||||
useEffect(() => {
|
||||
const updated_time = new Date();
|
||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
if (showEditFeeDialog) {
|
||||
setFormField({
|
||||
...formField,
|
||||
updated_by: parsedUser?.username,
|
||||
updated_at: formattedTime
|
||||
});
|
||||
}
|
||||
}, [showEditFeeDialog]);
|
||||
/* actions */
|
||||
const doUpdateTransferFee = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const response = await PutData(`${API_URL}/transactionfees/update/${selectedTransferFee}`, {
|
||||
...formField
|
||||
});
|
||||
if (response?.status) {
|
||||
handleEditFeeDialog(false, null);
|
||||
toast.success('Success Update User');
|
||||
reload();
|
||||
} else {
|
||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
||||
}
|
||||
console.log(formField);
|
||||
},
|
||||
[formField, selectedTransferFee]
|
||||
);
|
||||
const fetchWallets = useCallback(async () => {
|
||||
const params = {
|
||||
limit: 100,
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: 'name',
|
||||
order_direction: 'ASC',
|
||||
filter: JSON.stringify({
|
||||
status: 'Y'
|
||||
})
|
||||
};
|
||||
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, params);
|
||||
if (response?.status && response?.data) {
|
||||
setWallets(response.data.list);
|
||||
} else {
|
||||
setWallets([]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchWallets();
|
||||
}, [fetchWallets]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showEditFeeDialog) return;
|
||||
|
||||
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 ? 'DESC' : 'ASC'
|
||||
});
|
||||
|
||||
// 🟡 Log daftar pelanggan saja (kalau respons pakai struktur {data: {list: [...]}})
|
||||
console.log('CUSTOMER LIST: ', response?.data?.list);
|
||||
|
||||
setCustomers(response?.data.list || []);
|
||||
} catch (error) {
|
||||
console.error('Error fetching customer', error);
|
||||
}
|
||||
};
|
||||
|
||||
getCustomerList([{ id: 'msisdn', desc: false }]);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!showEditFeeDialog) return;
|
||||
|
||||
const getTransactionTypeList = async (sorting: any) => {
|
||||
try {
|
||||
sorting = sorting.length === 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
const response = await GetData(`${API_URL}/transactiontype/list`, {
|
||||
limit: 100,
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||
});
|
||||
|
||||
// 🟡 Log daftar pelanggan saja (kalau respons pakai struktur {data: {list: [...]}})
|
||||
console.log('TRANSACTION TYPE LIST: ', response?.data?.list);
|
||||
|
||||
setTransactionTypes(response?.data.list || []);
|
||||
} catch (error) {
|
||||
console.error('Error fetching customer', error);
|
||||
}
|
||||
};
|
||||
|
||||
getTransactionTypeList([{ id: 'id', desc: false }]);
|
||||
}, [showEditFeeDialog]);
|
||||
|
||||
const fetchTransactionFee = useCallback(async (id: string) => {
|
||||
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, { id });
|
||||
// console.log("API Response:", response);
|
||||
|
||||
if (response?.status) {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
name: response.data.name,
|
||||
description: response.data.description,
|
||||
minimum_amount: response.data.minimum_amount,
|
||||
maximum_amount: response.data.maximum_amount,
|
||||
period_start: response.data.period_start,
|
||||
period_end: response.data.period_end,
|
||||
deduct_amount: response.data.deduct_amount,
|
||||
deduct_percentage: response.data.deduct_percentage,
|
||||
priority: response.data.priority,
|
||||
status: response.data.status,
|
||||
status_include: response.data.status_include,
|
||||
transaction_type: response.data.transaction_type.id
|
||||
|
||||
// updated_by: parsedUser?.username ,
|
||||
// updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
}));
|
||||
} else {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
name: '',
|
||||
description: '',
|
||||
minimum_amount: 0,
|
||||
maximum_amount: 0,
|
||||
period_start: '',
|
||||
period_end: '',
|
||||
deduct_amount: 0,
|
||||
deduct_percentage: 0,
|
||||
priority: '',
|
||||
status: '',
|
||||
status_include: '',
|
||||
transaction_type: ''
|
||||
}));
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedTransferFee) {
|
||||
fetchTransactionFee(selectedTransferFee);
|
||||
}
|
||||
}, [selectedTransferFee]);
|
||||
|
||||
return (
|
||||
<Dialog open={showEditFeeDialog} onOpenChange={(open) => handleEditFeeDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-5 border-0">
|
||||
<DialogTitle></DialogTitle>
|
||||
<DialogDescription></DialogDescription>
|
||||
<div className="flex items-center justify-between flex-wrap grow">
|
||||
<div className="flex flex-col justify-center">
|
||||
<h1 className="text-xl font-semibold leading-none text-gray-900">
|
||||
Update Transaction Fee
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
|
||||
</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-100 opacity-50"
|
||||
onClick={() => handleEditFeeDialog(false, null)}
|
||||
>
|
||||
<KeenIcon icon="cross" className="text-1.5xl" />
|
||||
</div>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
|
||||
<div className="flex flex-col px-0">
|
||||
{alert.show && (
|
||||
<Alert variant="danger">
|
||||
<h3>{alert.message}</h3>
|
||||
</Alert>
|
||||
)}
|
||||
<form action="" onSubmit={doUpdateTransferFee}>
|
||||
<div className="card flex flex-col gap-5">
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Free Name</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
value={formField.name}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Description</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
value={formField.description}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, description: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Minimum Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.minimum_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
minimum_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Minimum Amount"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Maximum Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.maximum_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
maximum_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Minimum Amount"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period Start</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
autoComplete="off"
|
||||
value={formField.period_start ? formField.period_start.split('T')[0] : ''}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, period_start: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period End</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
autoComplete="off"
|
||||
value={formField.period_end ? formField.period_end.split('T')[0] : ''}
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, period_end: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Amount</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.deduct_amount}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
deduct_amount: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Minimum Amount"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Percentage</label>
|
||||
<NumericFormat
|
||||
className="input"
|
||||
value={formField.deduct_percentage}
|
||||
thousandSeparator="."
|
||||
decimalSeparator=","
|
||||
allowNegative={false}
|
||||
onValueChange={(values) => {
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
deduct_percentage: values.floatValue || 0
|
||||
}));
|
||||
}}
|
||||
placeholder="Enter Minimum Amount"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transacsion Type ID</label>
|
||||
<Select
|
||||
value={formField.transaction_type}
|
||||
onValueChange={(transaction_type) =>
|
||||
setFormField((prev) => ({ ...prev, transaction_type }))
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{transactionTypes.map((transactiontype, idx) => (
|
||||
<SelectItem value={transactiontype.id} key={transactiontype.id}>
|
||||
{transactiontype.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status</label>
|
||||
<Select
|
||||
value={formField.status}
|
||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status Included</label>
|
||||
<Select
|
||||
value={formField.status_include}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, status_include: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Priority</label>
|
||||
<Select
|
||||
value={formField.priority}
|
||||
onValueChange={(value) => setFormField({ ...formField, priority: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* <div className="w-full">
|
||||
<label className="form-label">Priotity</label>
|
||||
<Select
|
||||
value={formField.priority}
|
||||
onValueChange={(value) => setFormField({ ...formField, priority: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div> */}
|
||||
|
||||
{/* <div className="w-full">
|
||||
<label className="form-label">Priority</label>
|
||||
<Select
|
||||
value={formField.priority ? 'Y' : 'N'}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, priority: value === 'Y' })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Priority" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Y</SelectItem>
|
||||
<SelectItem value="N">N</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div> */}
|
||||
<div className="flex justify-end pt-2.5 gap-5">
|
||||
<Button variant={'outline'} type="reset">
|
||||
Reset
|
||||
</Button>
|
||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</DialogBody>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export { EditFeeDialog };
|
||||
44
src/pages/transfer/transferfee/blocks/ListToolBar.tsx
Normal file
44
src/pages/transfer/transferfee/blocks/ListToolBar.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
||||
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
const ListToolbar = () => {
|
||||
const { table, reload } = useDataGrid();
|
||||
const { handleAddFeeDialog, handleEditFeeDialog, selectedTransferFee} = useManageTransferFeeContext();
|
||||
|
||||
return (
|
||||
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
||||
<div className="flex flex-wrap gap-2 lg:gap-5 w-full">
|
||||
<div className="flex justify-between w-full items-center">
|
||||
<div className="flex w-[50%] gap-3 items-center">
|
||||
<label className="input input-sm w-1/3">
|
||||
<KeenIcon icon="magnifier" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search Access Type"
|
||||
value={(table.getColumn('name')?.getFilterValue() as string) ?? ''}
|
||||
onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex gap-3 items-center">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-7.5 text-[0.8rem]"
|
||||
onClick={() => handleAddFeeDialog(true)}
|
||||
>
|
||||
Add Data
|
||||
</Button>
|
||||
<DefaultTooltip title={'Refresh'} placement={'top'}>
|
||||
<Button variant="outline" className="h-7.5" onClick={() => reload()}>
|
||||
<KeenIcon icon="arrows-circle" />
|
||||
</Button>
|
||||
</DefaultTooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ListToolbar;
|
||||
@ -0,0 +1,236 @@
|
||||
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { createContext, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import ListToolbar from '../blocks/ListToolBar';
|
||||
import DeleteDialog from '../blocks/DeleteDialog';
|
||||
import { EditFeeDialog } from '../blocks/EditDialog';
|
||||
|
||||
interface ContextProps {
|
||||
showEditFeeDialog: boolean;
|
||||
handleEditFeeDialog: (show: boolean, selectedTransferFee: string | null) => void;
|
||||
showAddFeeDialog: boolean;
|
||||
handleAddFeeDialog: (show: boolean) => void;
|
||||
handleDeleteFeeDialog: (show: boolean, selectedTransferFee: string | null) => void;
|
||||
showDeleteFeeDialog: boolean;
|
||||
selectedTransferFee: string | null;
|
||||
}
|
||||
|
||||
const initialProps: ContextProps = {
|
||||
showEditFeeDialog: false,
|
||||
handleEditFeeDialog: () => {},
|
||||
showAddFeeDialog: false,
|
||||
handleAddFeeDialog: () => {},
|
||||
showDeleteFeeDialog: false,
|
||||
handleDeleteFeeDialog: () => {},
|
||||
selectedTransferFee: null
|
||||
};
|
||||
|
||||
const ManageTransferFeeContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const [showEditFeeDialog, setShowEditFeeDialog] = useState(false);
|
||||
const [showAddFeeDialog, setShowAddFeeDialog] = useState(false);
|
||||
const [showDeleteFeeDialog, setShowDeleteFeeDialog] = useState(false);
|
||||
|
||||
const [selectedTransferFee, setSelectedTransferFee] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
|
||||
const handleEditFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selectedTransferFee : null);
|
||||
setShowEditFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleAddFeeDialog = useCallback((show: boolean) => {
|
||||
setShowAddFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleDeleteFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selectedTransferFee : null);
|
||||
setShowDeleteFeeDialog(show);
|
||||
}, []);
|
||||
const doGetTransferFeeListData = async (
|
||||
page: number,
|
||||
limit: number,
|
||||
sorting: any,
|
||||
filter: any
|
||||
) => {
|
||||
sorting = sorting.length == 0 ? [{ id: 'id', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value.toLowerCase() };
|
||||
const response = await GetData(`${API_URL}/transactionfees/list`, {
|
||||
limit: limit,
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'ASC' : 'DESC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
console.log('hasilnya', response?.data.list);
|
||||
console.log('transactiontype', response?.data);
|
||||
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
};
|
||||
const columns = useMemo<ColumnDef<any>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorFn: (row) => row.name,
|
||||
id: 'name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.description,
|
||||
id: 'description',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.minimum_amount,
|
||||
id: 'minimum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Min Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.maximum_amount,
|
||||
id: 'maximum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Max Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.period_start?.split('T')[0],
|
||||
id: 'period_start',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period Start" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.period_end?.split('T')[0],
|
||||
id: 'period_end',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period End" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_amount,
|
||||
id: 'deduct_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_percentage,
|
||||
id: 'deduct_percentage',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct %" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.priority,
|
||||
id: 'priority',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Priority" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[100px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.transaction_type?.name,
|
||||
id: 'transactionTypeId',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Transaction Type" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status_include,
|
||||
id: 'status_include',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: (data) => {
|
||||
const row = data.row.original;
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleEditFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="notepad-edit" />
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleDeleteFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="trash" />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
}
|
||||
],
|
||||
[handleEditFeeDialog, handleDeleteFeeDialog]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="container mx-auto py-5">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h1 className="text-2xl font-semibold">Manage Transaction Fee</h1>
|
||||
</div>
|
||||
<ManageTransferFeeContext.Provider
|
||||
value={{
|
||||
showEditFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
selectedTransferFee,
|
||||
showDeleteFeeDialog,
|
||||
handleDeleteFeeDialog
|
||||
}}
|
||||
>
|
||||
<Toaster expand visibleToasts={9} duration={3000} />
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 10 }}
|
||||
layout={{ card: true }}
|
||||
toolbar={<ListToolbar />}
|
||||
sorting={[{ id: 'id', desc: true }]}
|
||||
serverSide={true}
|
||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||
doGetTransferFeeListData(pageIndex, pageSize, sorting, columnFilters)
|
||||
}
|
||||
>
|
||||
{children}
|
||||
<DeleteDialog />
|
||||
<EditFeeDialog />
|
||||
</DataGridProvider>
|
||||
</ManageTransferFeeContext.Provider>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { ManageTransferFeeContext, ManageTransferFeeContextProvider };
|
||||
@ -0,0 +1,12 @@
|
||||
import { useContext } from 'react';
|
||||
import { ManageTransferFeeContext } from './ManageTransferFeeContext';
|
||||
|
||||
const useManageTransferFeeContext = () => {
|
||||
const context = useContext(ManageTransferFeeContext);
|
||||
|
||||
if (!context) throw new Error('useManageAccessTypeContext must be used within AuthProvider');
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export { useManageTransferFeeContext };
|
||||
Reference in New Issue
Block a user