This commit is contained in:
Fadli 2023-01-06 03:18:55 +07:00
commit af8162f558
2 changed files with 78 additions and 11 deletions

View File

@ -10,6 +10,7 @@ import {
Space, Space,
Table, Table,
Tag, Tag,
InputNumber,
} from "antd"; } from "antd";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { ExclamationCircleOutlined } from "@ant-design/icons"; import { ExclamationCircleOutlined } from "@ant-design/icons";
@ -37,13 +38,13 @@ export const SupplierComponent = observer((props) => {
setIdData(data.id); setIdData(data.id);
}; };
const handleTopup = (data) => { const handleTopup = async (data) => {
console.log(data, "isi data"); store.supplier.code = data.code;
console.log(data.code, "isi data");
form.setFieldsValue({ form.setFieldsValue({
code: data.code, code: data.code,
}); });
store.supplier.visibleModalTransaction = true; store.supplier.visibleModalTransaction = true;
store.supplier.code = data.code;
}; };
const changeStatus = async (id, isActive) => { const changeStatus = async (id, isActive) => {
@ -163,7 +164,27 @@ export const SupplierComponent = observer((props) => {
}); });
}; };
const handleCancelTransaction = () => {
store.supplier.visibleModalTransaction = false;
};
const handleSubmitTransaction = async (data) => {
try {
modalLoader.setLoading(true);
const response = await store.supplier.createTransaction(data);
message.success(response?.body?.message || "Success Top Up");
} catch (e) {
console.log(e, "apa errornya");
message.error(e.response?.body?.message || "Failed Top Up");
}
modalLoader.setLoading(false);
store.supplier.visibleModalTransaction = false;
form.resetFields();
};
const handleCancel = () => { const handleCancel = () => {
form.resetFields();
setIdData(""); setIdData("");
store.supplier.visibleModalSupplier = false; store.supplier.visibleModalSupplier = false;
}; };
@ -350,7 +371,6 @@ export const SupplierComponent = observer((props) => {
okText={idData ? "Edit" : "Buat"} okText={idData ? "Edit" : "Buat"}
cancelText="Batal" cancelText="Batal"
onCancel={() => { onCancel={() => {
form.resetFields();
handleCancel(); handleCancel();
}} }}
onOk={() => { onOk={() => {
@ -420,7 +440,54 @@ export const SupplierComponent = observer((props) => {
)} )}
</Form> </Form>
</Modal> </Modal>
<TopupsaldoModal code={store.supplier.code} /> <Modal
visible={store.supplier.visibleModalTransaction}
title="Top Up Saldo"
okText="Top Up"
cancelText="Batal"
onCancel={() => {
form.resetFields();
handleCancelTransaction();
}}
onOk={() => {
form
.validateFields()
.then((values) => {
console.log(values, "isi form");
handleSubmitTransaction(values);
form.resetFields();
})
.catch((info) => {
console.error("Validate Failed:", info);
});
}}
>
<Form
form={form}
layout="vertical"
>
<Form.Item
name="code"
label="Supplier"
rules={[{ required: true, message: "Please input supplier!" }]}
>
<Input disabled={true} />
</Form.Item>
<Form.Item
name="amount"
label="Nominal"
rules={[{ required: true, message: "Please input amount!" }]}
>
<InputNumber
style={{ width: "100%" }}
formatter={(value) =>
`Rp. ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
parser={(value) => value.replace(/\Rp.\s?|(,*)/g, "")}
/>
</Form.Item>
</Form>
</Modal>
</div> </div>
); );
}); });

View File

@ -84,8 +84,8 @@ export const Home = observer(() => {
}} }}
> >
<Row> <Row>
<Row style={{ marginTop: 20 }}> <Row>
<Col style={{ marginRight: 40 }}> <Col span={8}>
<p> <p>
<h4> <h4>
Total Penjualan :{" "} Total Penjualan :{" "}
@ -108,7 +108,7 @@ export const Home = observer(() => {
</h4> </h4>
</p> </p>
</Col> </Col>
<Col> <Col span={8} offset={8}>
<p> <p>
<h4> <h4>
Total Profit :{" "} Total Profit :{" "}
@ -158,8 +158,8 @@ export const Home = observer(() => {
}} }}
> >
<Row> <Row>
<Row style={{ marginTop: 20 }}> <Row>
<Col style={{ marginRight: 40 }}> <Col span={8}>
<p> <p>
<h4> <h4>
Total Penjualan :{" "} Total Penjualan :{" "}
@ -182,7 +182,7 @@ export const Home = observer(() => {
</h4> </h4>
</p> </p>
</Col> </Col>
<Col> <Col span={8} offset={8}>
<p> <p>
<h4> <h4>
Total Profit :{" "} Total Profit :{" "}