fix editdialog transfertype

This commit is contained in:
bagusajisaputroo
2025-05-09 14:19:04 +07:00
parent 8a3a574a80
commit fc9beeeaa2

View File

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