feat: crud product
This commit is contained in:
parent
91ade48bea
commit
412ecc827e
|
@ -14,7 +14,6 @@ export const ProductComponent = observer((props) => {
|
||||||
const [idData, setIdData] = 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(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
|
@ -35,11 +34,12 @@ export const ProductComponent = observer((props) => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
price: data.price,
|
price: data.price,
|
||||||
base_price: data.base_price,
|
markUpPrice: data.basePrice,
|
||||||
code: data.code,
|
code: data.code,
|
||||||
status: data.status,
|
status: data.status,
|
||||||
|
subCategoriesId: data.sub_categories.id,
|
||||||
});
|
});
|
||||||
setVisibleModal(true);
|
store.product.visibleModalProduct = true;
|
||||||
setIdData(data.id);
|
setIdData(data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +59,10 @@ export const ProductComponent = observer((props) => {
|
||||||
dataIndex: "basePrice",
|
dataIndex: "basePrice",
|
||||||
key: "basePrice",
|
key: "basePrice",
|
||||||
},
|
},
|
||||||
,
|
|
||||||
{
|
{
|
||||||
title: "Harga Jual",
|
title: "Harga Jual",
|
||||||
dataIndex: "price",
|
dataIndex: "basePrice",
|
||||||
key: "price",
|
key: "basePrice",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Gangguan",
|
title: "Gangguan",
|
||||||
|
@ -71,7 +70,7 @@ export const ProductComponent = observer((props) => {
|
||||||
key: "status",
|
key: "status",
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<Tag
|
<Tag
|
||||||
color={record?.status === "AKTIF" ? "processing" : "#E3E8EE"}
|
color={record?.status === "ACTIVE" ? "processing" : "#E3E8EE"}
|
||||||
style={{color: "#4F566B"}}
|
style={{color: "#4F566B"}}
|
||||||
>
|
>
|
||||||
{capitalize(record?.status)}
|
{capitalize(record?.status)}
|
||||||
|
@ -84,10 +83,10 @@ export const ProductComponent = observer((props) => {
|
||||||
key: "tersedia",
|
key: "tersedia",
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<Tag
|
<Tag
|
||||||
color={record?.status === "AKTIF" ? "processing" : "#E3E8EE"}
|
color={record?.status === "ACTIVE" ? "processing" : "#E3E8EE"}
|
||||||
style={{color: "#4F566B"}}
|
style={{color: "#4F566B"}}
|
||||||
>
|
>
|
||||||
{record?.status === "AKTIF" ? " Ya" : "Tidak"}
|
{record?.status === "ACTIVE" ? " Ya" : "Tidak"}
|
||||||
</Tag>
|
</Tag>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -139,11 +138,12 @@ export const ProductComponent = observer((props) => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIdData('')
|
setIdData('')
|
||||||
setVisibleModal(false);
|
store.product.visibleModalProduct = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
const handleSubmit = async (data) => {
|
||||||
if (idData != '') {
|
console.log(data, "isi data2")
|
||||||
|
if (idData !== '') {
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
try {
|
try {
|
||||||
await store.product.update(idData, data)
|
await store.product.update(idData, data)
|
||||||
|
@ -152,7 +152,9 @@ export const ProductComponent = observer((props) => {
|
||||||
message.error("Failed Update Data Member")
|
message.error("Failed Update Data Member")
|
||||||
}
|
}
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
setVisibleModal(false);
|
store.product.visibleModalProduct = false;
|
||||||
|
setIdData('');
|
||||||
|
form.resetFields();
|
||||||
} else {
|
} else {
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
try {
|
try {
|
||||||
|
@ -163,7 +165,9 @@ export const ProductComponent = observer((props) => {
|
||||||
message.error("Failed Add Member")
|
message.error("Failed Add Member")
|
||||||
}
|
}
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
setVisibleModal(false);
|
store.product.visibleModalProduct = false;
|
||||||
|
setIdData('');
|
||||||
|
form.resetFields();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +180,7 @@ export const ProductComponent = observer((props) => {
|
||||||
bordered
|
bordered
|
||||||
/>
|
/>
|
||||||
<Modal
|
<Modal
|
||||||
visible={visibleModal}
|
visible={store.product.visibleModalProduct}
|
||||||
title={idData ? "Edit Product" : "Create a new Product"}
|
title={idData ? "Edit Product" : "Create a new Product"}
|
||||||
okText={idData ? "Edit" : "Create"}
|
okText={idData ? "Edit" : "Create"}
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
|
@ -188,6 +192,7 @@ export const ProductComponent = observer((props) => {
|
||||||
form
|
form
|
||||||
.validateFields()
|
.validateFields()
|
||||||
.then((values) => {
|
.then((values) => {
|
||||||
|
console.log(values, "isi form")
|
||||||
handleSubmit(values);
|
handleSubmit(values);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
})
|
})
|
||||||
|
@ -215,7 +220,7 @@ export const ProductComponent = observer((props) => {
|
||||||
<Input/>
|
<Input/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="base_price"
|
name="markUpPrice"
|
||||||
label="Mark Up Price"
|
label="Mark Up Price"
|
||||||
rules={[{required: true, message: "Please input mark up price!"}]}
|
rules={[{required: true, message: "Please input mark up price!"}]}
|
||||||
>
|
>
|
||||||
|
@ -239,7 +244,7 @@ export const ProductComponent = observer((props) => {
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="sub_category"
|
name="subCategoriesId"
|
||||||
label="Sub categories"
|
label="Sub categories"
|
||||||
rules={[{required: true, message: "Please select sub categories!"}]}
|
rules={[{required: true, message: "Please select sub categories!"}]}
|
||||||
>
|
>
|
||||||
|
|
|
@ -60,7 +60,7 @@ export const Product = observer(() => {
|
||||||
placeholder="input search text"
|
placeholder="input search text"
|
||||||
style={{width: 200, marginRight: 10}}
|
style={{width: 200, marginRight: 10}}
|
||||||
/>
|
/>
|
||||||
<Button onClick={() => store.product.visibleModal = true}>
|
<Button onClick={() => store.product.visibleModalProduct = true}>
|
||||||
<PlusSquareOutlined/> New
|
<PlusSquareOutlined/> New
|
||||||
</Button>
|
</Button>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {action, makeAutoObservable} from "mobx";
|
import {makeAutoObservable} from "mobx";
|
||||||
import {http} from "../utils/http";
|
import {http} from "../utils/http";
|
||||||
|
|
||||||
export class Product {
|
export class Product {
|
||||||
|
@ -7,6 +7,7 @@ export class Product {
|
||||||
data = [];
|
data = [];
|
||||||
total_data = 0;
|
total_data = 0;
|
||||||
filterCategory = null;
|
filterCategory = null;
|
||||||
|
visibleModalProduct = false;
|
||||||
|
|
||||||
pageCategories = 0;
|
pageCategories = 0;
|
||||||
pageSizeCategories = 10
|
pageSizeCategories = 10
|
||||||
|
@ -46,15 +47,14 @@ export class Product {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
async create(data) {
|
async create(data) {
|
||||||
const response = await http.post('/product', data);
|
const response = await http.post('/product').send(data);
|
||||||
await this.getData();
|
await this.getData();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id, data) {
|
async update(id, data) {
|
||||||
const response = await http.put(`/product/${id}`, data);
|
const response = await http.put(`/product/${id}`).send(data);
|
||||||
await this.getData();
|
await this.getData();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user