Update API call for fetching sucos and modify payload structure

- Change `with_deleted` from true to false when fetching sucos
- Update payload sent to API to include only name, description, and status
This commit is contained in:
Wikzyy
2025-04-07 14:29:09 +07:00
parent 4a6033d7b4
commit 96cd2378ab
2 changed files with 18 additions and 21 deletions

View File

@ -153,7 +153,7 @@ const ManageSucosContextProvider = ({ children }: { children: React.ReactNode })
const response = await GetData(`${API_URL}/sucos/list`, {
limit: limit,
page: page + 1,
with_deleted: true,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
filter: JSON.stringify(filter)

View File

@ -53,13 +53,11 @@ const EditDialog = () => {
description: string;
status: string;
group: string[];
currency_id: string;
} = {
name: '',
description: '',
status: '',
group: [],
currency_id: ''
group: []
};
const [formField, setFormField] = useState(initialState);
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
@ -71,12 +69,12 @@ const EditDialog = () => {
};
const doUpdateWallet = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
async (payload: { name: string; description: string; status: string }) => {
// e.preventDefault();
const response = await PutData(
`${API_URL_MASTER_DATA}/wallet/update/${selectedWallet?.Wallet_id}`,
formField
payload
);
if (response?.status) {
@ -94,8 +92,14 @@ const EditDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(formField);
doUpdateWallet(e);
// const { name, description, status } = formField;
const payload = {
name: formField.name,
description: formField.description,
status: formField.status
};
// console.log(payload);
doUpdateWallet(payload);
setAlert({ show: false, message: '' });
};
@ -156,8 +160,6 @@ const EditDialog = () => {
.map((g) => g.name)
.join(', ');
const selectedCurrency = currencies.find((currency) => currency.ID === formField.currency_id);
useEffect(() => {
getCurrencyLists([{ id: 'name', desc: false }]);
getGroupLists([{ id: 'name', desc: false }]);
@ -182,7 +184,7 @@ const EditDialog = () => {
resetForm();
}
}, [showEditDialog]);
// console.log(selectedWallet);
return (
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
@ -246,17 +248,10 @@ const EditDialog = () => {
</div>
</div>
<div className="w-full">
<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">Currency</label>
<Input type="text" placeholder='Empty' value={selectedCurrency?.name || ''} readOnly />
</div>
</div>
<div className="w-full">
<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>
<Input type="text" placeholder='Empty' value={selectedGroupNames} readOnly />
<Input type="text" placeholder="Empty" value={selectedGroupNames} readOnly />
</div>
</div>
@ -264,7 +259,9 @@ const EditDialog = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Update</Button>
<Button variant="default" type="submit">
Update
</Button>
</div>
</div>
</form>