Merge branch 'develop' of gitlab.com:empatnusabangsa/ppob/ppob-frontend into develop
This commit is contained in:
		
							
								
								
									
										217
									
								
								src/component/CategoryComponent.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										217
									
								
								src/component/CategoryComponent.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,217 @@ | ||||
| import React, {useEffect, useState} from "react"; | ||||
| import {Button, Form, Input, message, Modal, Select, Space, Table, Tag} from "antd"; | ||||
| import {observer} from "mobx-react-lite"; | ||||
| import {ExclamationCircleOutlined} from "@ant-design/icons"; | ||||
| import {useHistory} from "react-router-dom"; | ||||
| import {capitalize} from "lodash"; | ||||
| import {useStore} from "../utils/useStore"; | ||||
| import {LINKS} from "../routes/app"; | ||||
|  | ||||
| export const CategoryComponent = observer((props) => { | ||||
|     const store = useStore(); | ||||
|     const [form] = Form.useForm(); | ||||
|     const {Option} = Select; | ||||
|     const history = useHistory(); | ||||
|     const [idData, setIdData] = useState(''); | ||||
|     const [confirmLoading, setConfirmLoading] = useState(false); | ||||
|     const [isLoading, setIsLoading] = useState(false); | ||||
|  | ||||
|     useEffect(() => { | ||||
|         const init = async () => { | ||||
|             try { | ||||
|                 setIsLoading(true); | ||||
|                 //store.product.pageCategories=StrToLower(props.category) | ||||
|                 await store.product.getDataSubCategories(); | ||||
|                 setIsLoading(false); | ||||
|             } catch (e) { | ||||
|                 setIsLoading(false); | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         init(); | ||||
|     }, []); | ||||
|  | ||||
|     const handleEditButton = (data) => { | ||||
|         console.log(data, "isi data") | ||||
|         form.setFieldsValue({ | ||||
|             name: data.name, | ||||
|         }); | ||||
|         store.category.visibleModalCategory = true; | ||||
|         setIdData(data.id); | ||||
|     } | ||||
|  | ||||
|     const columns = [ | ||||
|         { | ||||
|             title: "Product Name", | ||||
|             dataIndex: "name", | ||||
|             key: "name", | ||||
|         }, | ||||
|         // { | ||||
|         //     title: "Gangguan", | ||||
|         //     dataIndex: "status", | ||||
|         //     key: "status", | ||||
|         //     render: (text, record) => ( | ||||
|         //         <Tag | ||||
|         //             color={record?.status === "ACTIVE" ? "blue" : "#E3E8EE"} | ||||
|         //             style={{color: "#4F566B"}} | ||||
|         //         > | ||||
|         //             {capitalize(record?.status)} | ||||
|         //         </Tag> | ||||
|         //     ), | ||||
|         // }, | ||||
|         // { | ||||
|         //     title: "Tersedia", | ||||
|         //     dataIndex: "tersedia", | ||||
|         //     key: "tersedia", | ||||
|         //     render: (text, record) => ( | ||||
|         //         <Tag | ||||
|         //             color={record?.status === "ACTIVE" ? "blue" : "#E3E8EE"} | ||||
|         //             style={{color: "#4F566B"}} | ||||
|         //         > | ||||
|         //             {record?.status === "ACTIVE" ? " Ya" : "Tidak"} | ||||
|         //         </Tag> | ||||
|         //     ), | ||||
|         // }, | ||||
|         { | ||||
|             title: "Action", | ||||
|             key: "action", | ||||
|             render: (text, record) => ( | ||||
|                 <Space size="middle"> | ||||
|                     <Button | ||||
|                         onClick={() => handleEditButton(record)} | ||||
|                     >Edit</Button> | ||||
|                     <Button | ||||
|                         onClick={() => handleDelete(record.id)} | ||||
|                     > | ||||
|                         Delete | ||||
|                     </Button> | ||||
|                 </Space> | ||||
|             ), | ||||
|         }, | ||||
|     ]; | ||||
|  | ||||
|     const deleteData = async (id) => { | ||||
|         try { | ||||
|             console.log(id); | ||||
|             await store.category.delete(id); | ||||
|             message.success("Data Berhasil Dihapus"); | ||||
|             history.push(LINKS.PRODUCT); | ||||
|         } catch (err) { | ||||
|             console.log("error", err); | ||||
|             message.error("Gagal menghapus"); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     const handleDelete = (id) => { | ||||
|         Modal.confirm({ | ||||
|             title: "Are you sure delete this record?", | ||||
|             icon: <ExclamationCircleOutlined/>, | ||||
|             okText: "Yes", | ||||
|             okType: "primary", | ||||
|             cancelText: "Cancel", | ||||
|             onOk() { | ||||
|                 return deleteData(id); | ||||
|             }, | ||||
|             onCancel() { | ||||
|                 console.log("Cancel"); | ||||
|             }, | ||||
|         }); | ||||
|     }; | ||||
|  | ||||
|     const handleCancel = () => { | ||||
|         setIdData('') | ||||
|         store.category.visibleModalCategory = false; | ||||
|     } | ||||
|  | ||||
|     const handleSubmit = async (data) => { | ||||
|         console.log(data, "isi data2") | ||||
|         if (idData !== '') { | ||||
|             setConfirmLoading(true); | ||||
|             try { | ||||
|                 await store.category.update(idData, data) | ||||
|                 message.success("Success Update Data Category") | ||||
|             } catch (e) { | ||||
|                 message.error("Failed Update Data Category") | ||||
|             } | ||||
|             setConfirmLoading(false); | ||||
|             store.category.visibleModalCategory = false; | ||||
|             setIdData(''); | ||||
|             form.resetFields(); | ||||
|         } else { | ||||
|             setConfirmLoading(true); | ||||
|             try { | ||||
|                 await store.category.create(data) | ||||
|                 message.success("Success Add New Category") | ||||
|             } catch (e) { | ||||
|                 console.log(e, "apa errornya") | ||||
|                 message.error("Failed Add Category") | ||||
|             } | ||||
|             setConfirmLoading(false); | ||||
|             store.category.visibleModalCategory = false; | ||||
|             setIdData(''); | ||||
|             form.resetFields(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return ( | ||||
|         <div> | ||||
|             <Table | ||||
|                 style={{textAlign: "center"}} | ||||
|                 columns={columns} | ||||
|                 dataSource={store.category.data} | ||||
|                 bordered | ||||
|                 pagination={{ | ||||
|                     pageSize: store.product.pageSize, | ||||
|                     total: store.product.total_data, | ||||
|                     current: store.product.page + 1, | ||||
|                     showSizeChanger: true, | ||||
|                     simple: false | ||||
|                 }} | ||||
|                 onChange={async (page) => { | ||||
|                     let pageNumber = page.current; | ||||
|                     store.product.pageSize = page.pageSize; | ||||
|                     store.product.page = pageNumber - 1; | ||||
|                     // store.membership.isLoading = true; | ||||
|                     await store.product.getData(); | ||||
|                     // store.membership.isLoading = false; | ||||
|                 }} | ||||
|             /> | ||||
|  | ||||
|             <Modal | ||||
|                 visible={store.category.visibleModalCategory} | ||||
|                 title={idData ? "Edit Category" : "Create a new Category"} | ||||
|                 okText={idData ? "Edit" : "Create"} | ||||
|                 cancelText="Cancel" | ||||
|                 onCancel={() => { | ||||
|                     form.resetFields(); | ||||
|                     handleCancel(); | ||||
|                 }} | ||||
|                 onOk={() => { | ||||
|                     form | ||||
|                         .validateFields() | ||||
|                         .then((values) => { | ||||
|                             console.log(values, "isi form") | ||||
|                             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 category!"}]} | ||||
|                     > | ||||
|                         <Input/> | ||||
|                     </Form.Item> | ||||
|                 </Form> | ||||
|             </Modal> | ||||
|         </div> | ||||
|     ); | ||||
| }); | ||||
| @@ -72,7 +72,7 @@ export const PartnerComponent = observer((props) => { | ||||
|       dataIndex: "status", | ||||
|       key: "status", | ||||
|       render: (text, record) => ( | ||||
|         <Button type={record?.status === true ? "primary" : "danger"}> | ||||
|         <Button size="small" type={record?.status === true ? "primary" : "danger"}> | ||||
|           {record?.status === true ? " ACTIVE" : "INACTIVE"}  | ||||
|         </Button> | ||||
|       ), | ||||
|   | ||||
| @@ -20,6 +20,7 @@ export const ProductComponent = observer((props) => { | ||||
|         const init = async () => { | ||||
|             try { | ||||
|                 setIsLoading(true); | ||||
|                 //store.product.pageCategories=StrToLower(props.category) | ||||
|                 await store.product.getDataSubCategories(); | ||||
|                 setIsLoading(false); | ||||
|             } catch (e) { | ||||
| @@ -71,7 +72,7 @@ export const ProductComponent = observer((props) => { | ||||
|             key: "status", | ||||
|             render: (text, record) => ( | ||||
|                 <Tag | ||||
|                     color={record?.status === "ACTIVE" ? "processing" : "#E3E8EE"} | ||||
|                     color={record?.status === "ACTIVE" ? "blue" : "#E3E8EE"} | ||||
|                     style={{color: "#4F566B"}} | ||||
|                 > | ||||
|                     {capitalize(record?.status)} | ||||
| @@ -84,7 +85,7 @@ export const ProductComponent = observer((props) => { | ||||
|             key: "tersedia", | ||||
|             render: (text, record) => ( | ||||
|                 <Tag | ||||
|                     color={record?.status === "ACTIVE" ? "processing" : "#E3E8EE"} | ||||
|                     color={record?.status === "ACTIVE" ? "blue" : "#E3E8EE"} | ||||
|                     style={{color: "#4F566B"}} | ||||
|                 > | ||||
|                     {record?.status === "ACTIVE" ? " Ya" : "Tidak"} | ||||
|   | ||||
| @@ -125,6 +125,9 @@ export const SupplierComponent = observer((props) => { | ||||
|     setIdData(""); | ||||
|     store.supplier.visibleModalSupplier = false; | ||||
|   }; | ||||
|   const handleCancelTransaction= () => { | ||||
|     store.supplier.visibleModalTransaction = false; | ||||
|   }; | ||||
|  | ||||
|   const handleSubmit = async (data) => { | ||||
|     console.log(data, "isi data2"); | ||||
| @@ -157,6 +160,24 @@ export const SupplierComponent = observer((props) => { | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   const handleSubmitTransaction = async (data) => { | ||||
|     console.log(data, "isi data2"); | ||||
|       setConfirmLoading(true); | ||||
|       try { | ||||
|         await store.supplier.createTransaction(data); | ||||
|         message.success("Success Top Up"); | ||||
|         //await store.supplier.getData() | ||||
|       } catch (e) { | ||||
|         console.log(e, "apa errornya"); | ||||
|         message.error("Failed Top Up"); | ||||
|       } | ||||
|       setConfirmLoading(false); | ||||
|       store.supplier.visibleModalTransaction = false; | ||||
|       form.resetFields(); | ||||
|   };   | ||||
|  | ||||
|    | ||||
|  | ||||
|   return ( | ||||
|     <div> | ||||
|       <Table | ||||
| @@ -220,6 +241,45 @@ export const SupplierComponent = observer((props) => { | ||||
|           </Form.Item> | ||||
|         </Form> | ||||
|       </Modal> | ||||
|       <Modal | ||||
|         visible={store.supplier.visibleModalTransaction} | ||||
|         title="Top Up Saldo" | ||||
|         okText="Top Up" | ||||
|         cancelText="Cancel" | ||||
|         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="supplier" | ||||
|             label="Supplier" | ||||
|             rules={[{ required: true, message: "Please input supplier!" }]} | ||||
|           > | ||||
|             <Input /> | ||||
|           </Form.Item> | ||||
|           <Form.Item | ||||
|             name="amount" | ||||
|             label="Amount" | ||||
|             rules={[{ required: true, message: "Please input amount!" }]} | ||||
|           > | ||||
|             <Input /> | ||||
|           </Form.Item> | ||||
|         </Form> | ||||
|       </Modal> | ||||
|     </div> | ||||
|   ); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user