feat: create feature local data configuration
parent
d49c487e61
commit
685d14a7df
|
@ -1,13 +1,15 @@
|
||||||
|
import axios from 'axios';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { App, Button, Col, InputNumber, InputNumberProps, Modal, ModalProps, Row, Slider } from 'antd';
|
import { App, Button, Col, InputNumber, InputNumberProps, Modal, ModalProps, Row, Slider } from 'antd';
|
||||||
|
import { API_URL } from '@pos/base';
|
||||||
|
|
||||||
export default function LocalDataConfiguration(modalProps: ModalProps) {
|
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 [inputValue, setInputValue] = useState(0);
|
||||||
const [loadingGet, setLoadingGet] = useState(false);
|
const [loadingGet, setLoadingGet] = useState(false);
|
||||||
const [loadingSave, setLoadingSave] = useState(false);
|
const [loadingSave, setLoadingSave] = useState(false);
|
||||||
|
|
||||||
const onChange: InputNumberProps['onChange'] = (newValue) => {
|
const onChange: InputNumberProps['onChange'] = (newValue) => {
|
||||||
setInputValue(newValue as number);
|
setInputValue(newValue as number);
|
||||||
};
|
};
|
||||||
|
@ -23,15 +25,47 @@ export default function LocalDataConfiguration(modalProps: ModalProps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSave(value: number) {
|
async function handleSave(value: number) {
|
||||||
console.log('Konfigurasi disimpan:', value);
|
|
||||||
setLoadingSave(true);
|
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() {
|
async function handleGetData() {
|
||||||
console.log('Get data konfigurasi:');
|
|
||||||
setLoadingGet(true);
|
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(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -5,4 +5,7 @@ export const API_URL = {
|
||||||
|
|
||||||
REPORT_SUMMARY_INCOME_ITEM: '/v1/report-summary/income-item',
|
REPORT_SUMMARY_INCOME_ITEM: '/v1/report-summary/income-item',
|
||||||
REPORT_SUMMARY_INCOME_ITEM_MASTER: '/v1/report-summary/income-item-master',
|
REPORT_SUMMARY_INCOME_ITEM_MASTER: '/v1/report-summary/income-item-master',
|
||||||
|
|
||||||
|
EDIT_TRANSACTION_SETTING: '/v1/transaction-setting',
|
||||||
|
GET_TRANSACTION_SETTING: '/v1/transaction-setting/detail',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue