diff --git a/src/pages/disbursement/history-transaction/HistoryTransaction.tsx b/src/pages/disbursement/history-transaction/HistoryTransaction.tsx index dc6c51f..61b9d2d 100644 --- a/src/pages/disbursement/history-transaction/HistoryTransaction.tsx +++ b/src/pages/disbursement/history-transaction/HistoryTransaction.tsx @@ -23,7 +23,7 @@ const HistoryTransactionDisbursement = () => { - History Transaction + History Disbursement
diff --git a/src/pages/transfer/transfertype/blocks/AddDialog.tsx b/src/pages/transfer/transfertype/blocks/AddDialog.tsx index 19760af..bff4222 100644 --- a/src/pages/transfer/transfertype/blocks/AddDialog.tsx +++ b/src/pages/transfer/transfertype/blocks/AddDialog.tsx @@ -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) + console.log(formField) return ( handleAddDialog(open)}> diff --git a/src/pages/transfer/transfertype/blocks/EditDialog.tsx b/src/pages/transfer/transfertype/blocks/EditDialog.tsx index 8f52633..db7e391 100644 --- a/src/pages/transfer/transfertype/blocks/EditDialog.tsx +++ b/src/pages/transfer/transfertype/blocks/EditDialog.tsx @@ -25,23 +25,16 @@ import { useCallApi } from '@/hooks'; import { getAuth } from '@/auth'; import { ManageTransferFeeContextProvider } from '../../transferfee/hooks/ManageTransferFeeContext'; import AddFeeDialog from '../../transferfee/blocks/AddDialog'; -import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; -import { - Command, - CommandEmpty, - CommandGroup, - CommandInput, - CommandItem, - CommandList -} from '@/components/ui/command'; +import { Checkbox } from '@/components/ui/checkbox'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; 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; + id: string; + name: string; } interface CustomerProps { @@ -50,19 +43,11 @@ interface CustomerProps { msisdn: string; } -interface TranssactionTypeProps { +interface GroupProps { + id: string; name: string; description: string; - minimum_amount: number; - maximum_amount: number; - max_transaction_per_day: number; - status_approval: string; status: string; - type: string; - wallet_origin: WalletProps; - wallet_destination: WalletProps; - wallet_fee_destination: WalletProps; - customer_fee_destination: CustomerProps; } const EditDialog = () => { @@ -71,29 +56,43 @@ const EditDialog = () => { useManageTransferTypeContext(); const { reload } = useDataGrid(); const [wallets, setWallets] = useState([]); + const [groups, setGroups] = useState([]); const { GetData, PutData } = useCallApi(); const [isSubmitting, setIsSubmitting] = useState(false); const parsedUser = getAuth()?.user; const [customers, setCustomers] = useState([]); - const [open, setOpen] = useState(false); + const [selectedGroups, setSelectedGroups] = useState([]); const [alert, setAlert] = useState({ show: false, message: '' }); - const initialState = { + const initialState: { + name: string; + description: string; + wallet_origin: string; + wallet_destination: string; + minimum_amount: number; + maximum_amount: number; + max_transaction_per_day: number; + status: string; + type: string; + status_approval: string; + updated_by: string; + updated_at: string; + permission: string[]; + } = { name: '', description: '', wallet_origin: '', wallet_destination: '', - wallet_fee_destination: '', - customer_fee_destination: '', minimum_amount: 0, maximum_amount: 0, max_transaction_per_day: 0, status_approval: '', type: '', status: '', + permission: [], updated_by: '', updated_at: '' }; @@ -102,27 +101,47 @@ const EditDialog = () => { const resetForm = () => { setFormField(initialState); + setSelectedGroups([]); + setAlert({ show: false, message: '' }); + }; + + const handleGroupChange = (groupId: string) => { + setFormField((prevState) => { + const isSelected = prevState.permission.includes(groupId); + + if (isSelected) { + // Remove the permission if already selected + return { + ...prevState, + permission: prevState.permission.filter((id) => id !== groupId) + }; + } else { + // Add the permission if not selected + return { + ...prevState, + permission: [...prevState.permission, groupId] + }; + } + }); }; - // Validation function to make certain fields required const validateForm = () => { const requiredFields = [ 'name', 'description', 'wallet_origin', 'wallet_destination', - 'wallet_fee_destination', - 'customer_fee_destination', 'status', 'status_approval', 'type' ]; const missingFields = requiredFields.filter( - (field) => - formField[field as keyof typeof formField] === '' || - formField[field as keyof typeof formField] === null || - formField[field as keyof typeof formField] === undefined + (field) => { + return formField[field as keyof typeof formField] === '' || + formField[field as keyof typeof formField] === null || + formField[field as keyof typeof formField] === undefined; + } ); if (missingFields.length > 0) { @@ -133,6 +152,15 @@ const EditDialog = () => { return false; } + // Validate that at least one permission is selected + if (formField.permission.length === 0) { + setAlert({ + show: true, + message: 'Please select at least one group permission' + }); + return false; + } + setAlert({ show: false, message: '' }); return true; }; @@ -148,7 +176,12 @@ const EditDialog = () => { updated_at: formattedTime })); } - }, [showEditDialog]); + }, [showEditDialog, parsedUser]); + + const selectedPermissionNames = groups + .filter((g) => formField.permission.includes(g.id)) + .map((g) => g.name) + .join(', '); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -165,6 +198,14 @@ const EditDialog = () => { handleEditDialog(false, null); toast.success('Success Update Transfer Type'); reload(); + + const createActivity = { + module: 'Manage Transfer Type', + description: `Edit Transfer Type => ${selectedTransferType}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); } }) .finally(() => { @@ -197,11 +238,13 @@ const EditDialog = () => { } }, [formField, selectedTransferType, PutData]); + // Fetch customers useEffect(() => { if (!showEditDialog) return; - const getCustomerList = async (sorting: any) => { + + const getCustomerList = async () => { try { - sorting = sorting.length === 0 ? [{ id: 'name', desc: false }] : sorting; + const sorting = [{ id: 'id', desc: false }]; const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, { limit: 100, page: 1, @@ -209,74 +252,113 @@ const EditDialog = () => { order_field: sorting[0].id, order_direction: sorting[0].desc ? 'DESC' : 'ASC' }); - setCustomers(response?.data.list); + + if (response?.status && response?.data) { + setCustomers(response.data.list); + } } catch (error) { console.error('Error fetching customer', error); } }; - getCustomerList([{ id: 'id', desc: false }]); + getCustomerList(); }, [showEditDialog, GetData]); - - 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([]); - } - }, [GetData]); + // Fetch groups useEffect(() => { if (!showEditDialog) return; - fetchWallets(); - }, [showEditDialog, fetchWallets]); - - const fetchTransactionType = useCallback(async (id: string) => { - try { - const response = await GetData(`${API_URL}/transactiontype/getdata/${id}`, { id }); - if (response?.status) { - setFormField((prev) => ({ - ...prev, - name: response.data.name, - description: response.data.description, - wallet_origin: response.data.wallet_origin.id, - wallet_destination: response.data.wallet_destination.id, - wallet_fee_destination: response.data.wallet_fee_destination.id, - customer_fee_destination: response.data.customer_fee_destination.id, - minimum_amount: response.data.minimum_amount, - maximum_amount: response.data.maximum_amount, - max_transaction_per_day: response.data.max_transaction_per_day, - status_approval: response.data.status_approval, - type: response.data.type || '', - status: response.data.status - })); + + const getGroupList = async () => { + try { + const response = await GetData(`${API_URL_MASTERDATA}/groups/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: 'name', + order_direction: 'ASC' + }); + + if (response?.status && response?.data) { + setGroups(response.data.list); + } + } catch (error) { + console.error('Error fetching groups', error); } - // console.log(response); - } catch (error) { - console.error('Error fetching transaction type', error); - setAlert({ - show: true, - message: 'Failed to load transaction type data' - }); - } - }, [GetData]); + }; + + getGroupList(); + }, [showEditDialog, GetData]); + + // Fetch wallets + useEffect(() => { + if (!showEditDialog) return; + + const getWalletList = async () => { + try { + const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: 'wallets.name', + order_direction: 'ASC', + }); + + if (response?.status && response?.data) { + setWallets(response.data.list); + } + } catch (error) { + console.error('Error fetching wallets', error); + } + }; + + getWalletList(); + }, [showEditDialog, GetData]); + + // Fetch transaction type data + useEffect(() => { + if (!showEditDialog || !selectedTransferType) return; + + const fetchTransactionType = async () => { + try { + const response = await GetData(`${API_URL}/transactiontype/getdata/${selectedTransferType}`, {}); + + if (response?.status) { + setFormField((prev) => ({ + ...prev, + name: response.data.name, + description: response.data.description, + wallet_origin: response.data.wallet_origin?.id || '', + wallet_destination: response.data.wallet_destination?.id || '', + minimum_amount: response.data.minimum_amount, + maximum_amount: response.data.maximum_amount, + max_transaction_per_day: response.data.max_transaction_per_day, + status_approval: response.data.status_approval, + type: response.data.type || '', + status: response.data.status, + permission: response.data.permission || [] + })); + } + } catch (error) { + console.error('Error fetching transaction type', error); + setAlert({ + show: true, + message: 'Failed to load transaction type data' + }); + } + }; + + const timer = setTimeout(() => { + fetchTransactionType(); + }, 150); + + return () => clearTimeout(timer); + }, [showEditDialog, selectedTransferType, GetData]); useEffect(() => { - if (selectedTransferType) { - fetchTransactionType(selectedTransferType); + if (showEditDialog === false) { + resetForm(); } - }, [selectedTransferType, fetchTransactionType]); + }, [showEditDialog]); return ( handleEditDialog(open, null)}> @@ -305,9 +387,11 @@ const EditDialog = () => {
{alert.show && ( - -

{alert.message}

-
+
+ +

{alert.message}

+
+
)}
@@ -439,8 +523,8 @@ const EditDialog = () => { {wallets.map((wallet) => ( - - {wallet.Wallet_name} + + {wallet.name} ))} @@ -467,8 +551,8 @@ const EditDialog = () => { {wallets.map((wallet) => ( - - {wallet.Wallet_name} + + {wallet.name} ))} @@ -476,86 +560,6 @@ const EditDialog = () => {
-
-
- -
- -
-
-
-
-
- -
- - - - - - - - { - e.currentTarget.scrollTop += e.deltaY; - }} - > - No Customer found. - - {customers.map((customer) => ( - { - setFormField({ - ...formField, - customer_fee_destination: customer.id - }); - setOpen(false); - }} - > - {customer.username} - {customer.msisdn} - - ))} - - - - - -
-
-
@@ -637,7 +641,47 @@ const EditDialog = () => {
- + + {/* Group Permission Section - Read Only Display */} +
+
+ +
+ + + {/* Groups Selection Area */} +
+
+ {groups.map((group) => ( +
+ handleGroupChange(group.id)} + /> + +
+ ))} +
+
+
+
+
+
- {/* Transaction Fee Section */} diff --git a/src/pages/transfer/transfertype/hooks/ManageTransferTypeContext.tsx b/src/pages/transfer/transfertype/hooks/ManageTransferTypeContext.tsx index f5fcd14..2fde89a 100644 --- a/src/pages/transfer/transfertype/hooks/ManageTransferTypeContext.tsx +++ b/src/pages/transfer/transfertype/hooks/ManageTransferTypeContext.tsx @@ -76,6 +76,16 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React const columns = useMemo[]>( () => [ + { + accessorFn: (row) => row.id, + id: 'id', + header: ({ column }) => ( + + ), + enableSorting: false, + enableHiding: false, + meta: { headerClassName: 'w-[250px]' } + }, { accessorFn: (row) => row.name, id: 'name', @@ -213,7 +223,7 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React order_direction: orderDirection, filter: JSON.stringify(filter) }); - + console.log(response?.data.list); return { data: response?.data.list, totalCount: response?.data.total_count }; };