feat: adjust buy product on click
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
import React from "react";
|
||||
import {Form, Input, message, Modal} from "antd";
|
||||
import {observer} from "mobx-react-lite";
|
||||
import {useStore} from "../utils/useStore";
|
||||
|
||||
export const BuyProductModal = observer(({initialData}) => {
|
||||
const store = useStore();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const handleCancelBuyProduct = () => {
|
||||
form.resetFields();
|
||||
store.transaction.visibleModalTransaction = false;
|
||||
};
|
||||
|
||||
const handleSubmitBuyProduct = async (data) => {
|
||||
try {
|
||||
const response = await store.transaction.buyProduct({productCode: data});
|
||||
if (response.status === 200) {
|
||||
message.success("Success Buy Product");
|
||||
} else {
|
||||
message.error("Failed Buy Product");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e, "apa errornya");
|
||||
message.error("Failed Buy Product");
|
||||
}
|
||||
store.transaction.visibleModalTransaction = false;
|
||||
form.resetFields();
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Modal
|
||||
visible={store.transaction.visibleModalTransaction}
|
||||
title={`Buy Product ${initialData?.name}`}
|
||||
okText="Buy"
|
||||
cancelText="Cancel"
|
||||
onCancel={handleCancelBuyProduct}
|
||||
onOk={() => {
|
||||
form
|
||||
.validateFields()
|
||||
.then((values) => {
|
||||
handleSubmitBuyProduct(values);
|
||||
})
|
||||
.catch((info) => {
|
||||
console.error("Validate Failed:", info);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={{supplier: store.supplier.code}}
|
||||
>
|
||||
<Form.Item
|
||||
name="code"
|
||||
label="Code"
|
||||
rules={[{required: true, message: "Please input Code!"}]}
|
||||
>
|
||||
<Input/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user