fix form update manage wallet
- remove validation - add .join to merge value group from response
This commit is contained in:
@ -52,13 +52,13 @@ const EditDialog = () => {
|
|||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
status: string;
|
status: string;
|
||||||
group: string;
|
group: string[];
|
||||||
currency_id: string;
|
currency_id: string;
|
||||||
} = {
|
} = {
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
status: '',
|
status: '',
|
||||||
group: '',
|
group: [],
|
||||||
currency_id: ''
|
currency_id: ''
|
||||||
};
|
};
|
||||||
const [formField, setFormField] = useState(initialState);
|
const [formField, setFormField] = useState(initialState);
|
||||||
@ -94,17 +94,6 @@ const EditDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (
|
|
||||||
formField.name.trim() === '' ||
|
|
||||||
formField.description.trim() === '' ||
|
|
||||||
formField.status.trim() === '' ||
|
|
||||||
formField.currency_id === '' ||
|
|
||||||
formField.group.length === 0
|
|
||||||
) {
|
|
||||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(formField);
|
console.log(formField);
|
||||||
doUpdateWallet(e);
|
doUpdateWallet(e);
|
||||||
setAlert({ show: false, message: '' });
|
setAlert({ show: false, message: '' });
|
||||||
@ -115,7 +104,7 @@ const EditDialog = () => {
|
|||||||
id
|
id
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log(response);
|
console.log(response);
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -124,7 +113,7 @@ const EditDialog = () => {
|
|||||||
status: response?.data.status,
|
status: response?.data.status,
|
||||||
currency_id: response?.data.currency_id,
|
currency_id: response?.data.currency_id,
|
||||||
group: Array.isArray(response?.data.group)
|
group: Array.isArray(response?.data.group)
|
||||||
? response?.data.group.map((target: any) => target.name)
|
? response?.data.group.map((target: GroupProps) => target.id)
|
||||||
: []
|
: []
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -162,6 +151,11 @@ const EditDialog = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const selectedGroupNames = groups
|
||||||
|
.filter((g) => formField.group.includes(g.id))
|
||||||
|
.map((g) => g.name)
|
||||||
|
.join(', ');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCurrencyLists([{ id: 'name', desc: false }]);
|
getCurrencyLists([{ id: 'name', desc: false }]);
|
||||||
getGroupLists([{ id: 'name', desc: false }]);
|
getGroupLists([{ id: 'name', desc: false }]);
|
||||||
@ -234,9 +228,7 @@ const EditDialog = () => {
|
|||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
<label className="form-label flex items-center gap-1 max-w-56">Status</label>
|
||||||
Status
|
|
||||||
</label>
|
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||||
@ -254,9 +246,7 @@ const EditDialog = () => {
|
|||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
<label className="form-label flex items-center gap-1 max-w-56">Currency</label>
|
||||||
Currency
|
|
||||||
</label>
|
|
||||||
<Select
|
<Select
|
||||||
value={formField.currency_id}
|
value={formField.currency_id}
|
||||||
onValueChange={(value) => setFormField({ ...formField, currency_id: value })}
|
onValueChange={(value) => setFormField({ ...formField, currency_id: value })}
|
||||||
@ -278,7 +268,7 @@ const EditDialog = () => {
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">Groups</label>
|
<label className="form-label flex items-center gap-1 max-w-56">Groups</label>
|
||||||
<Input type="text" value={formField.group} readOnly />
|
<Input type="text" value={selectedGroupNames} readOnly />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,8 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
headerClassName: 'w-[100px]'
|
headerClassName: 'w-[100px] text-center',
|
||||||
|
cellClassName: 'text-center'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -140,7 +141,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
headerClassName: 'w-[100px]',
|
headerClassName: 'w-[100px] text-center',
|
||||||
cellClassName: 'text-center'
|
cellClassName: 'text-center'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +186,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
<Toaster expand visibleToasts={9} duration={3000} />
|
<Toaster expand visibleToasts={9} duration={3000} />
|
||||||
<DataGridProvider
|
<DataGridProvider
|
||||||
columns={columns}
|
columns={columns}
|
||||||
pagination={{ size: 5 }}
|
pagination={{ size: 25 }}
|
||||||
toolbar={<ListToolbar />}
|
toolbar={<ListToolbar />}
|
||||||
layout={{ card: true }}
|
layout={{ card: true }}
|
||||||
sorting={[{ id: 'id', desc: false }]}
|
sorting={[{ id: 'id', desc: false }]}
|
||||||
|
|||||||
Reference in New Issue
Block a user