feat: adjust buy product on click
This commit is contained in:
parent
5069f63374
commit
c73f642b93
|
@ -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>
|
||||
);
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
export const appConfig = {
|
||||
apiUrl: 'https://ppob-backend.k3s.bangun-kreatif.com/v1'
|
||||
// apiUrl: 'http://localhost:3222/v1'
|
||||
};
|
||||
|
||||
//export default appConfig;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import React, {useEffect, useState} from "react";
|
||||
import {useStore} from "../../utils/useStore";
|
||||
import { Button, Card, Col, Input, Row, Select, message } from "antd";
|
||||
import {Button, Card, Col, Input, message, Modal, Row, Select} from "antd";
|
||||
import {observer} from "mobx-react-lite";
|
||||
import { BuyProductModal } from "../../component/BuyProductModal";
|
||||
import {MoneyCollectOutlined} from "@ant-design/icons";
|
||||
|
||||
const {Search} = Input;
|
||||
const {Option} = Select;
|
||||
|
@ -12,9 +12,6 @@ export const Product = observer(() => {
|
|||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [productData, setProductData] = useState([]);
|
||||
const [data, setData] = useState({});
|
||||
const [kode, setKode] = useState({});
|
||||
const [cardIndex, setCardIndex] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
|
@ -46,17 +43,20 @@ export const Product = observer(() => {
|
|||
}, [store.transaction.dataSubCategories]);
|
||||
|
||||
const handleChangeSubcategory = async (item) => {
|
||||
console.log("item", item);
|
||||
store.transaction.filterSubCategory = item;
|
||||
await store.transaction.getData();
|
||||
};
|
||||
|
||||
const handleBuyProduct = async (kode) => {
|
||||
console.log(kode);
|
||||
const handleBuyProduct = async (data) => {
|
||||
try {
|
||||
await store.product.buyProduct({ productCode: kode });
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
@ -64,9 +64,7 @@ export const Product = observer(() => {
|
|||
return (
|
||||
<div>
|
||||
<Row>
|
||||
<span style={{ fontWeight: "bold", marginBottom: "10px" }}>
|
||||
Sub Category
|
||||
</span>
|
||||
<span style={{fontWeight: "bold", marginBottom: "10px"}}>Sub Category</span>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col span={24}>
|
||||
|
@ -108,15 +106,21 @@ export const Product = observer(() => {
|
|||
<Col key={index} xs={24} md={16} lg={8}>
|
||||
<Card
|
||||
onClick={() => {
|
||||
setKode(item.code);
|
||||
setCardIndex(index);
|
||||
}}
|
||||
hoverable
|
||||
style={{
|
||||
cursor: "pointer",
|
||||
borderColor: cardIndex === index ? "#2D9CDB" : "",
|
||||
marginLeft: "10px",
|
||||
Modal.confirm({
|
||||
title: `Are you sure buy ${item.name}?`,
|
||||
icon: <MoneyCollectOutlined/>,
|
||||
okText: "Confirm",
|
||||
cancelText: "Cancel",
|
||||
okType: "primary",
|
||||
onOk() {
|
||||
handleBuyProduct(item.code)
|
||||
},
|
||||
onCancel() {
|
||||
console.log("Cancel");
|
||||
},
|
||||
});
|
||||
}}
|
||||
style={{cursor: "pointer"}}
|
||||
>
|
||||
<span style={{color: "black"}}>{item.name}</span>
|
||||
<br/>
|
||||
|
@ -133,15 +137,11 @@ export const Product = observer(() => {
|
|||
)}
|
||||
{productData.length !== 0 && (
|
||||
<Col style={{ textAlign: "right" }}>
|
||||
<Button
|
||||
style={{ backgroundColor: "#2D9CDB", color: "white" }}
|
||||
onClick={() => handleBuyProduct(kode)}
|
||||
>
|
||||
<Button style={{backgroundColor: "#2D9CDB", color: "white"}}>
|
||||
Beli Sekarang
|
||||
</Button>
|
||||
</Col>
|
||||
)}
|
||||
<BuyProductModal initialData={data} />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user