feat: create feature local data configuration

main-cloud
Firman Ramdhani 2025-05-02 10:14:53 +07:00
parent d49c487e61
commit 685d14a7df
2 changed files with 43 additions and 6 deletions

View File

@ -1,13 +1,15 @@
import axios from 'axios';
import { useEffect, useState } from 'react';
import { App, Button, Col, InputNumber, InputNumberProps, Modal, ModalProps, Row, Slider } from 'antd';
import { API_URL } from '@pos/base';
export default function LocalDataConfiguration(modalProps: ModalProps) {
const { modal } = App.useApp();
const { modal, notification } = App.useApp();
const [configData, setConfigData] = useState<any>();
const [inputValue, setInputValue] = useState(0);
const [loadingGet, setLoadingGet] = useState(false);
const [loadingSave, setLoadingSave] = useState(false);
const onChange: InputNumberProps['onChange'] = (newValue) => {
setInputValue(newValue as number);
};
@ -23,15 +25,47 @@ export default function LocalDataConfiguration(modalProps: ModalProps) {
}
async function handleSave(value: number) {
console.log('Konfigurasi disimpan:', value);
setLoadingSave(true);
setLoadingSave(false);
await axios
.put(API_URL.EDIT_TRANSACTION_SETTING, { id: configData?.id, value })
.then(() => {
notification.success({
message: 'Sukses',
description: 'Konfigurasi berhasil disimpan',
});
if (modalProps.onCancel) modalProps.onCancel(null as any);
})
.catch((err) => {
notification.error({
message: 'Gagal',
description: err?.message ?? err?.response?.data?.message ?? 'Terjadi kesalahan saat menyimpan konfigurasi',
});
})
.finally(() => {
setLoadingSave(false);
});
}
async function handleGetData() {
console.log('Get data konfigurasi:');
setLoadingGet(true);
setLoadingGet(false);
await axios
.get(API_URL.GET_TRANSACTION_SETTING)
.then((res) => {
const data = res.data.data;
const respValue = data?.value;
setInputValue(Number(respValue ?? '0'));
setConfigData(data);
})
.catch((err) => {
notification.error({
message: 'Gagal',
description: err?.message ?? err?.response?.data?.message ?? 'Terjadi kesalahan saat mengambil konfigurasi',
});
})
.finally(() => {
setLoadingGet(false);
});
}
useEffect(() => {

View File

@ -5,4 +5,7 @@ export const API_URL = {
REPORT_SUMMARY_INCOME_ITEM: '/v1/report-summary/income-item',
REPORT_SUMMARY_INCOME_ITEM_MASTER: '/v1/report-summary/income-item-master',
EDIT_TRANSACTION_SETTING: '/v1/transaction-setting',
GET_TRANSACTION_SETTING: '/v1/transaction-setting/detail',
};