This commit is contained in:
Raja Oktafrianto
2025-04-11 10:13:52 +07:00
11 changed files with 269 additions and 224 deletions

View File

@ -23,6 +23,7 @@ import {
SelectValue
} from '@/components/ui/select';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { NumericFormat } from 'react-number-format';
interface ProviderProps {
provider_id: number;
@ -40,15 +41,29 @@ const AddDialog = () => {
show: false,
message: ''
});
const initialState = {
const initialState: {
name: string;
code: string;
type: string;
description: string;
price_point: string | number | null;
price_cash: string | number | null;
cashback_point: string | number | null;
cashback_cash: string | number | null;
status: string;
provider: string;
process_on_third_party: string;
created_by: string;
created_at: string;
} = {
name: '',
code: '',
type: '',
description: '',
price_point: 0,
price_cash: 0,
cashback_point: 0,
cashback_cash: 0,
price_point: null,
price_cash: null,
cashback_point: null,
cashback_cash: null,
status: '',
provider: '',
process_on_third_party: '',
@ -117,11 +132,13 @@ const AddDialog = () => {
formField.type.trim() === '' ||
formField.code.trim() === '' ||
formField.description.trim() === '' ||
formField.price_point === 0 ||
formField.price_cash === 0 ||
formField.cashback_point === 0 ||
formField.cashback_cash === 0 ||
formField.price_point === null ||
formField.price_cash === null ||
formField.cashback_point === null ||
formField.cashback_cash === null ||
formField.status.trim() === '' ||
formField.provider.trim() === '' ||
formField.process_on_third_party.trim() === '' ||
formField.created_by.trim() === '' ||
formField.created_at.trim() === ''
) {
@ -234,19 +251,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56">
Price Point<span className="text-red-500">*</span>
</label>
<Input
<NumericFormat
className="input"
type="number"
min={0}
step={0.01}
value={formField.price_point}
onChange={(e) => {
const value = parseFloat(e.target.value);
setFormField({
...formField,
price_point: isNaN(value) ? 0 : value
});
value={formField.price_point ?? ''}
thousandSeparator="."
decimalSeparator=","
allowNegative={false}
onValueChange={(values) => {
setFormField((prev) => ({
...prev,
price_point: values.floatValue !== undefined ? values.floatValue : ''
}));
}}
placeholder="Enter Price Point"
/>
</div>
</div>
@ -256,19 +273,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56">
Price Cash<span className="text-red-500">*</span>
</label>
<Input
<NumericFormat
className="input"
type="number"
min={0}
step={0.01}
value={formField.price_cash}
onChange={(e) => {
const value = parseFloat(e.target.value);
setFormField({
...formField,
price_cash: isNaN(value) ? 0 : value
});
value={formField.price_cash ?? ''}
thousandSeparator="."
decimalSeparator=","
allowNegative={false}
onValueChange={(values) => {
setFormField((prev) => ({
...prev,
price_cash: values.floatValue !== undefined ? values.floatValue : ''
}));
}}
placeholder="Enter Price Cash"
/>
</div>
</div>
@ -278,19 +295,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56">
Cashback Point<span className="text-red-500">*</span>
</label>
<Input
<NumericFormat
className="input"
type="number"
min={0}
step={0.01}
value={formField.cashback_point}
onChange={(e) => {
const value = parseFloat(e.target.value);
setFormField({
...formField,
cashback_point: isNaN(value) ? 0 : value
});
value={formField.cashback_point ?? ''}
thousandSeparator="."
decimalSeparator=","
allowNegative={false}
onValueChange={(values) => {
setFormField((prev) => ({
...prev,
cashback_point: values.floatValue !== undefined ? values.floatValue : ''
}));
}}
placeholder="Enter Cashback Point"
/>
</div>
</div>
@ -300,19 +317,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56">
Cashback Cash<span className="text-red-500">*</span>
</label>
<Input
<NumericFormat
className="input"
type="number"
min={0}
step={0.01}
value={formField.cashback_cash}
onChange={(e) => {
const value = parseFloat(e.target.value);
setFormField({
...formField,
cashback_cash: isNaN(value) ? 0 : value
});
value={formField.cashback_cash ?? ''}
thousandSeparator="."
decimalSeparator=","
allowNegative={false}
onValueChange={(values) => {
setFormField((prev) => ({
...prev,
cashback_cash: values.floatValue !== undefined ? values.floatValue : ''
}));
}}
placeholder="Enter Cashback Cash"
/>
</div>
</div>

View File

@ -68,7 +68,7 @@ const AddDialog = () => {
type: string;
status: string;
transaction_type: string;
agent: string;
agent: string | null;
created_by: string;
created_at: string;
} = {
@ -77,7 +77,7 @@ const AddDialog = () => {
type: '',
status: '',
transaction_type: '',
agent: '',
agent: null,
created_by: '',
created_at: ''
};
@ -133,7 +133,7 @@ const AddDialog = () => {
return;
}
console.log(formField);
// console.log(formField);
doCreateProvider(e);
setAlert({ show: false, message: '' });
};

View File

@ -58,7 +58,7 @@ const EditDialog = () => {
type: string;
status: string;
transaction_type: string;
agent: string;
agent: string | null;
updated_by: string;
updated_at: string;
} = {
@ -67,7 +67,7 @@ const EditDialog = () => {
type: '',
status: '',
transaction_type: '',
agent: '',
agent: null,
updated_by: '',
updated_at: ''
};
@ -156,7 +156,7 @@ const EditDialog = () => {
type: response?.data.type,
status: response?.data.status,
transaction_type: response?.data.transaction_type.id,
agent: response?.data.agent?.id || ''
agent: response?.data.agent?.id || null
}));
}
}, []);
@ -169,8 +169,7 @@ const EditDialog = () => {
formField.description.trim() === '' ||
formField.type.trim() === '' ||
formField.status.trim() === '' ||
formField.transaction_type.trim() === '' ||
formField.agent.trim() === ''
formField.transaction_type.trim() === ''
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;

View File

@ -123,7 +123,16 @@ const AddDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.id_group.trim() === '' || formField.status.trim() === '') {
if (
formField.id_group.trim() === '' ||
formField.status.trim() === '' ||
formField.id_wallet.trim() === '' ||
formField.max_transaction_per_day === null ||
formField.balance_minimum === null ||
formField.balance_maximum === null ||
formField.credit_limit === null ||
formField.monthly_limit === null
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}

View File

@ -155,7 +155,7 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
},
{
accessorKey: 'type.name',
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
header: ({ column }) => <DataGridColumnHeader title="Transaction Type" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {

View File

@ -157,7 +157,7 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
},
{
accessorKey: 'type.name',
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
header: ({ column }) => <DataGridColumnHeader title="Transaction Type" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {

View File

@ -218,7 +218,7 @@ const AddDialog = () => {
order_direction: 'ASC',
};
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, params);
console.log(response)
// console.log(response)
if (response?.status && response?.data) {
setWallets(response.data.list);
} else {
@ -230,7 +230,7 @@ const AddDialog = () => {
if (!showAddDialog) return;
fetchWallets();
}, [showAddDialog]);
// console.log(formField)
return (
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">

View File

@ -19,7 +19,9 @@ const DeleteDialog = () => {
message: ''
});
const doDeleteTransferType = useCallback(async () => {
const doDeleteTransferType = useCallback(async (id:string|null) => {
if (!selectedTransferType) {
toast.error('No Transfer Type selected');
return;
@ -37,9 +39,15 @@ const DeleteDialog = () => {
setTimeout(() => toast.success('Success Delete Transaction Type'), 0);
} else {
setAlert({ show: true, message: response?.message });
setTimeout(() => toast.error('Failed Delete Product'), 0);
// setTimeout(() => toast.error('Failed Delete Product'), 0);
}
}, [selectedTransferType, DeleteData, handleDeleteDialog, reload]);
const handleDelete = ((id:string|null) => {
console.log(id);
doDeleteTransferType(id);
})
return (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
@ -60,7 +68,7 @@ const DeleteDialog = () => {
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteTransferType()}>
<Button variant={'destructive'} onClick={() => handleDelete(selectedTransferType)}>
Delete
</Button>
</DialogFooter>

View File

@ -70,8 +70,8 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React
}, []);
const handleDeleteDialog = useCallback((show: boolean, selected_transfertype: string | null) => {
setShowDeleteDialog(show);
setSelectedTransferType(show ? selected_transfertype : null);
setShowDeleteDialog(show);
}, []);
const columns = useMemo<ColumnDef<any>[]>(