fix editdialog transfertype
This commit is contained in:
@ -71,7 +71,6 @@ const EditDialog = () => {
|
||||
|
||||
const [isLoadingWallets, setIsLoadingWallets] = useState(false);
|
||||
|
||||
|
||||
const initialState: {
|
||||
name: string;
|
||||
description: string;
|
||||
@ -122,6 +121,10 @@ const EditDialog = () => {
|
||||
permission: prevState.permission.filter((id) => id !== groupId)
|
||||
};
|
||||
} else {
|
||||
// Hapus error permission ketika user memilih group
|
||||
if (errors.permission && prevState.permission.length === 0) {
|
||||
setErrors((prev) => ({ ...prev, permission: '' }));
|
||||
}
|
||||
return {
|
||||
...prevState,
|
||||
permission: [...prevState.permission, groupId]
|
||||
@ -138,7 +141,8 @@ const EditDialog = () => {
|
||||
{ key: 'wallet_destination', label: 'To Account' },
|
||||
{ key: 'status', label: 'Status' },
|
||||
{ key: 'status_approval', label: 'Status Approval' },
|
||||
{ key: 'status_kind', label: 'Status Kind' }
|
||||
{ key: 'status_kind', label: 'Status Kind' },
|
||||
{ key: 'permission', label: 'Group' }
|
||||
];
|
||||
|
||||
const newErrors: Record<string, string> = {};
|
||||
@ -146,7 +150,9 @@ const EditDialog = () => {
|
||||
|
||||
requiredFields.forEach(({ key, label }) => {
|
||||
if (
|
||||
formField[key as keyof typeof formField] === '' ||
|
||||
key === 'permission'
|
||||
? !formField[key] || formField[key].length === 0
|
||||
: formField[key as keyof typeof formField] === '' ||
|
||||
formField[key as keyof typeof formField] === null ||
|
||||
formField[key as keyof typeof formField] === undefined
|
||||
) {
|
||||
@ -228,9 +234,7 @@ const EditDialog = () => {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : 'Failed to Update Transfer Type'
|
||||
)
|
||||
toast.error(error instanceof Error ? error.message : 'Failed to Update Transfer Type');
|
||||
return false;
|
||||
}
|
||||
}, [formField, selectedTransferType]);
|
||||
@ -399,7 +403,6 @@ const EditDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
@ -592,7 +595,9 @@ const EditDialog = () => {
|
||||
setErrors((prev) => ({ ...prev, wallet_destination: '' }));
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className={errors.wallet_destination ? 'border-red-500' : ''}>
|
||||
<SelectTrigger
|
||||
className={errors.wallet_destination ? 'border-red-500' : ''}
|
||||
>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@ -604,7 +609,9 @@ const EditDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.wallet_destination && (
|
||||
<span className="text-red-500 text-xs mt-1">{errors.wallet_destination}</span>
|
||||
<span className="text-red-500 text-xs mt-1">
|
||||
{errors.wallet_destination}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@ -759,9 +766,11 @@ const EditDialog = () => {
|
||||
placeholder="No groups selected"
|
||||
value={selectedPermissionNames || ''}
|
||||
readOnly
|
||||
className="bg-gray-100 mb-2"
|
||||
className={`bg-gray-100 mb-2 ${errors.permission ? 'border-red-500' : ''}`}
|
||||
/>
|
||||
|
||||
{errors.permission && (
|
||||
<span className="text-red-500 text-xs mt-2">{errors.permission}</span>
|
||||
)}
|
||||
<div className="border rounded-md p-3 max-h-48 overflow-y-auto">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
||||
{groups.map((group) => (
|
||||
@ -786,11 +795,7 @@ const EditDialog = () => {
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-2.5 gap-5">
|
||||
<Button
|
||||
variant={'outline'}
|
||||
type="button"
|
||||
onClick={() => resetForm()}
|
||||
>
|
||||
<Button variant={'outline'} type="button" onClick={() => resetForm()}>
|
||||
Reset
|
||||
</Button>
|
||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||
|
||||
Reference in New Issue
Block a user