import axios from 'axios'; import { useEffect, useState } from 'react'; import { App, Button, Col, InputNumber, InputNumberProps, Modal, ModalProps, Row, Slider } from 'antd'; import { API_URL, BASE_API_URL_LOCAL } from '@pos/base'; export default function LocalDataConfiguration(modalProps: ModalProps) { const { modal, notification } = App.useApp(); const [configData, setConfigData] = useState(); const [inputValue, setInputValue] = useState(0); const [loadingGet, setLoadingGet] = useState(false); const [loadingSave, setLoadingSave] = useState(false); const onChange: InputNumberProps['onChange'] = (newValue) => { setInputValue(newValue as number); }; function makeColorText(value: number) { if (value <= 30) { return 'text-red-500'; } else if (value > 30 && value <= 80) { return 'text-yellow-500'; } else if (value > 80 && value <= 100) { return 'text-green-500'; } } async function handleSave(value: number) { setLoadingSave(true); await axios .put(API_URL.EDIT_TRANSACTION_SETTING, { id: configData?.id, value }, { baseURL: BASE_API_URL_LOCAL }) .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() { setLoadingGet(true); await axios .get(API_URL.GET_TRANSACTION_SETTING, { baseURL: BASE_API_URL_LOCAL }) .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(() => { if (modalProps.open) handleGetData(); }, [modalProps.open]); return ( Batal , , ]} >
{`Gunakan slider atau input number dibawah ini untuk menentukan persentase data yang ingin ditampilkan di aplikasi lokal Anda. Semakin tinggi persentasenya, semakin banyak data yang akan ditampilkan. Sesuaikan dengan kebutuhan untuk memastikan performa aplikasi tetap optimal.`}
); }