This commit is contained in:
Raja Oktafrianto
2025-04-12 13:28:50 +07:00
2 changed files with 27 additions and 11 deletions

View File

@ -37,7 +37,7 @@ const TransferType = () => {
</div>
<AddDialog />
<DeleteDialog />
{/* <EditDialog /> */}
<EditDialog />
</Container>
</ManageTransferTypeContextProvider>

View File

@ -43,7 +43,7 @@ interface CustomerProps {
msisdn: string;
}
interface GroupProps {
interface PermissionObject {
id: string;
name: string;
description: string;
@ -56,7 +56,7 @@ const EditDialog = () => {
useManageTransferTypeContext();
const { reload } = useDataGrid();
const [wallets, setWallets] = useState<WalletProps[]>([]);
const [groups, setGroups] = useState<GroupProps[]>([]);
const [groups, setGroups] = useState<PermissionObject[]>([]);
const { GetData, PutData } = useCallApi();
const [isSubmitting, setIsSubmitting] = useState(false);
const parsedUser = getAuth()?.user;
@ -215,9 +215,13 @@ const EditDialog = () => {
const doUpdateTransferType = useCallback(async () => {
try {
const response = await PutData(`${API_URL}/transactiontype/update/${selectedTransferType}`, {
...formField
});
// Create a clean copy of the form data with properly formatted permissions
const formDataToSend = {
...formField,
permission: formField.permission.filter(id => typeof id === 'string')
};
const response = await PutData(`${API_URL}/transactiontype/update/${selectedTransferType}`, formDataToSend);
if (response?.status) {
setAlert({ show: false, message: '' });
@ -299,7 +303,7 @@ const EditDialog = () => {
limit: 100,
page: 1,
with_deleted: false,
order_field: 'wallets.name',
order_field: 'Wallets.name',
order_direction: 'ASC',
});
@ -321,8 +325,21 @@ const EditDialog = () => {
const fetchTransactionType = async () => {
try {
const response = await GetData(`${API_URL}/transactiontype/getdata/${selectedTransferType}`, {});
console.log(response);
if (response?.status) {
// Process permissions to ensure they're always string IDs
let permissionIds: string[] = [];
if (Array.isArray(response.data.permission)) {
permissionIds = response.data.permission.map((perm: any) => {
// Check if permission is an object or string
if (typeof perm === 'object' && perm !== null) {
return perm.id;
}
return perm;
});
}
setFormField((prev) => ({
...prev,
name: response.data.name,
@ -335,7 +352,7 @@ const EditDialog = () => {
status_approval: response.data.status_approval,
type: response.data.type || '',
status: response.data.status,
permission: response.data.permission || []
permission: permissionIds
}));
}
} catch (error) {
@ -346,14 +363,13 @@ const EditDialog = () => {
});
}
};
const timer = setTimeout(() => {
fetchTransactionType();
}, 150);
return () => clearTimeout(timer);
}, [showEditDialog, selectedTransferType, GetData]);
useEffect(() => {
if (showEditDialog === false) {
resetForm();