diff --git a/src/apps/admin/layout/components/default-value.tsx b/src/apps/admin/layout/components/default-value.tsx new file mode 100644 index 0000000..310bc42 --- /dev/null +++ b/src/apps/admin/layout/components/default-value.tsx @@ -0,0 +1,155 @@ +import dayjs from 'dayjs'; +import { Button, Card, Col, Flex, InputNumber, Modal, Row, Form } from 'antd'; +import { Fragment, useEffect, useState } from 'react'; +import axios from 'axios'; +import { notificationError } from '@pos/base'; + +export default function DefaultValue() { + const [loading, setLoading] = useState(false); + const [loadingSave, setLoadingSave] = useState(false); + const [defaultPercentage, setDefaultPercentage] = useState(100); + const [currentPercentage, setCurrentPercentage] = useState(100); + + const [form] = Form.useForm(); + const [openModal, setOpenModal] = useState(false); + + const onCloseModal = async () => { + await form.resetFields(); + setOpenModal(false); + }; + + const onOpenModal = async () => { + await form.setFieldsValue({ default_value: defaultPercentage }); + setOpenModal(true); + }; + + const handleSaveData = async () => { + try { + const payload = await form.validateFields(); + setLoadingSave(true); + await axios + .post('v1/data-scheduling-default', payload) + .then(async (resp) => { + const value = resp.data?.data?.default_value; + await form.setFieldsValue({ default_value: value }); + setDefaultPercentage(value); + setLoadingSave(false); + onCloseModal(); + }) + .catch((err) => { + const message = err.message; + if (message) notificationError(message); + setLoadingSave(false); + }); + } catch (error) { + console.error(error); + } + }; + + const handleGetData = async () => { + setLoading(true); + await Promise.all([ + axios + .get('v1/data-scheduling-default') + .then((resp) => { + const value = resp.data?.data?.default_value; + form.setFieldsValue({ default_value: value }); + setDefaultPercentage(value); + }) + .catch((err) => { + const message = err.message; + if (message) notificationError(message); + }), + axios + .get('v1/data-scheduling-active', { params: { date: dayjs().format('YYYY-MM-DD') } }) + .then((resp) => { + const value = resp.data?.data?.value; + form.setFieldsValue({ value: value }); + setCurrentPercentage(value); + }) + .catch((err) => { + const message = err.message; + if (message) notificationError(message); + }), + ]); + setLoading(false); + }; + + useEffect(() => { + handleGetData(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( + + DEFAULT PERCENTAGE} + > +
+ + + + + +
{`%`}
+
+
+
+ {`*Value akan diterapkan otomatis jika tidak ada pengaturan khusus pada tanggal tersebut.`} +
+
+
+ + + + +
DEFAULT PERCENTAGE
+ +
{`${defaultPercentage >= 0 ? `${defaultPercentage} %` : '-'}`}
+ +
+
+ {`Value otomatis jika tak ada setelan khusus.`} +
+
+
+ + + + +
CURRENT PERCENTAGE
+
{`${currentPercentage >= 0 ? `${currentPercentage} %` : '-'}`}
+
+ {`Value yang di terapkan hari ini ${dayjs().format('DD-MM-YYYY')}.`} +
+
+
+ +
+
+ ); +} diff --git a/src/apps/admin/layout/index.tsx b/src/apps/admin/layout/index.tsx index 34af951..04cd658 100644 --- a/src/apps/admin/layout/index.tsx +++ b/src/apps/admin/layout/index.tsx @@ -89,7 +89,7 @@ export default function AdminLayout(props: AdminLayoutProps) { }, { key: '2', - label: 'Settings', + label: 'Setting', icon: , onClick: () => gotoSetting(), }, diff --git a/src/apps/admin/pages/setting.tsx b/src/apps/admin/pages/setting.tsx index bb5ebc0..030ecbc 100644 --- a/src/apps/admin/pages/setting.tsx +++ b/src/apps/admin/pages/setting.tsx @@ -2,6 +2,7 @@ import { ACCESS_SETTING, UserDataState } from '@pos/base'; import { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useRecoilValue } from 'recoil'; +import DefaultValue from '../layout/components/default-value'; export default function SettingModule() { const user = useRecoilValue(UserDataState); @@ -22,5 +23,9 @@ export default function SettingModule() { } }, []); - return
Setting
; + return ( +
+ +
+ ); }