Merge branch 'develop' of https://gitlab.com/empatnusabangsa/ppob/ppob-frontend into develop
This commit is contained in:
commit
91ade48bea
|
@ -1,17 +1,47 @@
|
||||||
import React, {useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {Button, message, Modal, Space, Table, Tag} from "antd";
|
import {Button, Form, Input, message, Modal, Select, Space, Table, Tag} 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";
|
||||||
import {useHistory} from "react-router-dom";
|
import {useHistory} from "react-router-dom";
|
||||||
import {capitalize} from "lodash";
|
import {capitalize} from "lodash";
|
||||||
import {store} from "../utils/useStore";
|
import {useStore} from "../utils/useStore";
|
||||||
import {PulsaModal} from "../pages/Product/PulsaModal";
|
|
||||||
|
|
||||||
export const ProductComponent = observer((props) => {
|
export const ProductComponent = observer((props) => {
|
||||||
|
const store = useStore();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const {Option} = Select;
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [initialData, setInitialData] = useState({});
|
const [idData, setIdData] = useState('');
|
||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [visibleModal, setVisibleModal] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const init = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await store.product.getDataSubCategories();
|
||||||
|
setIsLoading(false);
|
||||||
|
} catch (e) {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
init();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleEditButton = (data) => {
|
||||||
|
console.log(data, "isi data")
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: data.name,
|
||||||
|
price: data.price,
|
||||||
|
base_price: data.base_price,
|
||||||
|
code: data.code,
|
||||||
|
status: data.status,
|
||||||
|
});
|
||||||
|
setVisibleModal(true);
|
||||||
|
setIdData(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
|
@ -67,15 +97,10 @@ export const ProductComponent = observer((props) => {
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => handleEditButton(record)}
|
||||||
setInitialData(record);
|
|
||||||
store.product.visibleModal = true;
|
|
||||||
}}
|
|
||||||
>Edit</Button>
|
>Edit</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={() => handleDelete(record.id)}
|
||||||
handleDelete(record.id);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -112,20 +137,23 @@ export const ProductComponent = observer((props) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const handleCancel = () => {
|
||||||
if (initialData.id) {
|
setIdData('')
|
||||||
setInitialData({})
|
setVisibleModal(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async (data) => {
|
||||||
|
if (idData != '') {
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
try {
|
try {
|
||||||
await store.product.update(initialData.id, data)
|
await store.product.update(idData, data)
|
||||||
message.success("Success Update Data Member")
|
message.success("Success Update Data Member")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error("Failed Update Data Member")
|
message.error("Failed Update Data Member")
|
||||||
}
|
}
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
store.product.visibleModal = false;
|
setVisibleModal(false);
|
||||||
} else {
|
} else {
|
||||||
setInitialData({})
|
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
try {
|
try {
|
||||||
await store.product.create(data)
|
await store.product.create(data)
|
||||||
|
@ -135,7 +163,7 @@ export const ProductComponent = observer((props) => {
|
||||||
message.error("Failed Add Member")
|
message.error("Failed Add Member")
|
||||||
}
|
}
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
store.product.visibleModal = false;
|
setVisibleModal(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,16 +175,84 @@ export const ProductComponent = observer((props) => {
|
||||||
dataSource={props.data}
|
dataSource={props.data}
|
||||||
bordered
|
bordered
|
||||||
/>
|
/>
|
||||||
<PulsaModal visible={store.product.visibleModal}
|
<Modal
|
||||||
confirmLoading={confirmLoading}
|
visible={visibleModal}
|
||||||
initialData={initialData}
|
title={idData ? "Edit Product" : "Create a new Product"}
|
||||||
onCreate={async (data) => {
|
okText={idData ? "Edit" : "Create"}
|
||||||
await onSubmit(data)
|
cancelText="Cancel"
|
||||||
}}
|
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setInitialData({})
|
form.resetFields();
|
||||||
store.product.visibleModal = false;
|
handleCancel();
|
||||||
}}/>
|
}}
|
||||||
|
onOk={() => {
|
||||||
|
form
|
||||||
|
.validateFields()
|
||||||
|
.then((values) => {
|
||||||
|
handleSubmit(values);
|
||||||
|
form.resetFields();
|
||||||
|
})
|
||||||
|
.catch((info) => {
|
||||||
|
console.error("Validate Failed:", info);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
name="name"
|
||||||
|
label="Name"
|
||||||
|
rules={[{required: true, message: "Please input name!"}]}
|
||||||
|
>
|
||||||
|
<Input/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="price"
|
||||||
|
label="Price"
|
||||||
|
rules={[{required: true, message: "Please input price!"}]}
|
||||||
|
>
|
||||||
|
<Input/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="base_price"
|
||||||
|
label="Mark Up Price"
|
||||||
|
rules={[{required: true, message: "Please input mark up price!"}]}
|
||||||
|
>
|
||||||
|
<Input/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="code"
|
||||||
|
label="Code"
|
||||||
|
rules={[{required: true, message: "Please input code!"}]}
|
||||||
|
>
|
||||||
|
<Input/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="status"
|
||||||
|
label="Status"
|
||||||
|
rules={[{required: true, message: "Please select Status!"}]}
|
||||||
|
>
|
||||||
|
<Select placeholder="Select Sub Category" allowClear>
|
||||||
|
<Option value="ACTIVE">ACTIVE</Option>
|
||||||
|
<Option value="INACTIVE">INACTIVE</Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="sub_category"
|
||||||
|
label="Sub categories"
|
||||||
|
rules={[{required: true, message: "Please select sub categories!"}]}
|
||||||
|
>
|
||||||
|
<Select placeholder="Select Sub Category" allowClear>
|
||||||
|
{store.product.dataSubCategories.map((item) => (
|
||||||
|
<Option value={item.id} key={item.id}>
|
||||||
|
{item.name}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,135 +0,0 @@
|
||||||
import React, {useEffect, useState} from "react";
|
|
||||||
import {Form, Input, Modal, Select} from "antd";
|
|
||||||
import {useStore} from "../../utils/useStore";
|
|
||||||
import {observer} from "mobx-react-lite";
|
|
||||||
|
|
||||||
export const PulsaModal = observer(({visible, onCreate, onCancel, initialData}) => {
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const {Option} = Select;
|
|
||||||
const store = useStore();
|
|
||||||
const [visibleModal, setVisibleModal] = useState(false);
|
|
||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const init = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await store.product.getDataSubCategories();
|
|
||||||
setIsLoading(false);
|
|
||||||
} catch (e) {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
init();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
|
||||||
const subCategoriesOption = [
|
|
||||||
<Option key={123} value={123}>
|
|
||||||
{123}
|
|
||||||
</Option>,
|
|
||||||
<Option key={431} value={123}>
|
|
||||||
{123}
|
|
||||||
</Option>
|
|
||||||
];
|
|
||||||
|
|
||||||
const subCategoriesOption2 = store.product.dataSubCategories.slice().map(subCategory => {
|
|
||||||
return (
|
|
||||||
<Option key={subCategory.id} value={subCategory.id}>
|
|
||||||
{subCategory.name}
|
|
||||||
</Option>
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(store.product.dataSubCategories, 'subCategoriesOption2');
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
visible={visible}
|
|
||||||
title={initialData.id ? "Edit Product" : "Create a new Product"}
|
|
||||||
okText={initialData.id ? "Edit" : "Create"}
|
|
||||||
cancelText="Cancel"
|
|
||||||
onCancel={() => {
|
|
||||||
form.resetFields();
|
|
||||||
onCancel();
|
|
||||||
}}
|
|
||||||
onOk={() => {
|
|
||||||
form
|
|
||||||
.validateFields()
|
|
||||||
.then((values) => {
|
|
||||||
onCreate(values);
|
|
||||||
form.resetFields();
|
|
||||||
})
|
|
||||||
.catch((info) => {
|
|
||||||
console.log("Validate Failed:", info);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Form
|
|
||||||
form={form}
|
|
||||||
layout="vertical"
|
|
||||||
name="form_in_modal"
|
|
||||||
initialValues={initialData}
|
|
||||||
>
|
|
||||||
<Form.Item
|
|
||||||
name="name"
|
|
||||||
label="Name"
|
|
||||||
rules={[{required: true, message: "Please input name!"}]}
|
|
||||||
>
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="price"
|
|
||||||
label="Price"
|
|
||||||
rules={[{required: true, message: "Please input price!"}]}
|
|
||||||
>
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="base_price"
|
|
||||||
label="Mark Up Price"
|
|
||||||
rules={[{required: true, message: "Please input mark up price!"}]}
|
|
||||||
>
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="code"
|
|
||||||
label="Code"
|
|
||||||
rules={[{required: true, message: "Please input code!"}]}
|
|
||||||
>
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="status"
|
|
||||||
label="Status"
|
|
||||||
rules={[{required: true, message: "Please select Status!"}]}
|
|
||||||
>
|
|
||||||
<Select placeholder="Select Sub Category" allowClear>
|
|
||||||
<Option value="ACTIVE">ACTIVE</Option>
|
|
||||||
<Option value="INACTIVE">INACTIVE</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="sub_category"
|
|
||||||
label="Sub categories"
|
|
||||||
rules={[{required: true, message: "Please select sub categories!"}]}
|
|
||||||
>
|
|
||||||
<Select placeholder="Select Sub Category" allowClear>
|
|
||||||
{subCategoriesOption2}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
{/*<Form.Item*/}
|
|
||||||
{/* name="subCategories"*/}
|
|
||||||
{/* label="Sub Categories"*/}
|
|
||||||
{/* rules={[{required: true, message: "Please select Sub Category!"}]}*/}
|
|
||||||
{/*>*/}
|
|
||||||
{/* <Select placeholder="Select Sub Category" allowClear>*/}
|
|
||||||
{/* {subCategoriesOption2}*/}
|
|
||||||
{/* </Select>*/}
|
|
||||||
{/*</Form.Item>*/}
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
});
|
|
|
@ -18,8 +18,6 @@ export class Product {
|
||||||
dataSubCategories = [];
|
dataSubCategories = [];
|
||||||
total_dataSubCategories = 0;
|
total_dataSubCategories = 0;
|
||||||
|
|
||||||
visibleModal = false;
|
|
||||||
|
|
||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
|
@ -33,7 +31,7 @@ export class Product {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataSubCategories() {
|
async getDataSubCategories() {
|
||||||
const response = await http.get(`/product/sub-categories?pageSize=${this.pageSizeSubCategories}`);
|
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
|
||||||
this.dataSubCategories = response.body.data ?? []
|
this.dataSubCategories = response.body.data ?? []
|
||||||
this.total_dataSubCategories = response.body.count ?? 0
|
this.total_dataSubCategories = response.body.count ?? 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user