Pages Supplier
This commit is contained in:
		| @@ -1,244 +1,178 @@ | |||||||
| import React, {useEffect, useState} from "react"; | import React, { useEffect, useState } from "react"; | ||||||
| import {Button, Form, Input, message, Modal, Select, Space, Table, Tag} from "antd"; | import { | ||||||
| import {observer} from "mobx-react-lite"; |   Button, | ||||||
| import {ExclamationCircleOutlined} from "@ant-design/icons"; |   Form, | ||||||
| import {useHistory} from "react-router-dom"; |   Input, | ||||||
| import {capitalize} from "lodash"; |   message, | ||||||
| import {useStore} from "../utils/useStore"; |   Modal, | ||||||
| import {LINKS} from "../routes/app"; |   Select, | ||||||
|  |   Space, | ||||||
|  |   Table, | ||||||
|  | } 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 CommissionComponent = observer((props) => { | export const CommissionComponent = observer((props) => { | ||||||
|     const store = useStore(); |   const store = useStore(); | ||||||
|     const [form] = Form.useForm(); |   const [form] = Form.useForm(); | ||||||
|     const {Option} = Select; |   const { Option } = Select; | ||||||
|     const history = useHistory(); |   const history = useHistory(); | ||||||
|     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); | ||||||
|  |  | ||||||
|     useEffect(() => { |   useEffect(() => { | ||||||
|         const init = async () => { |     const init = async () => { | ||||||
|             try { |       try { | ||||||
|                 setIsLoading(true); |         setIsLoading(true); | ||||||
|                 //await store.product.getDataSubCategories(); |         //await store.product.getDataSubCategories(); | ||||||
|                 setIsLoading(false); |         setIsLoading(false); | ||||||
|             } catch (e) { |       } catch (e) { | ||||||
|                 setIsLoading(false); |         setIsLoading(false); | ||||||
|             } |       } | ||||||
|         }; |  | ||||||
|  |  | ||||||
|         init(); |  | ||||||
|     }, []); |  | ||||||
|  |  | ||||||
|     const handleEditButton = (data) => { |  | ||||||
|         console.log(data, "isi data") |  | ||||||
|         form.setFieldsValue({ |  | ||||||
|             name: data.name, |  | ||||||
|             npwp: data.npwp, |  | ||||||
|             address: data.address, |  | ||||||
|              |  | ||||||
|         }); |  | ||||||
|         store.commission.visibleModalCommission = true; |  | ||||||
|         setIdData(data.id); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     const columns = [ |  | ||||||
|         { |  | ||||||
|           title: "Name", |  | ||||||
|           dataIndex: "name", |  | ||||||
|           key: "name", |  | ||||||
|         }, |  | ||||||
|         { |  | ||||||
|           title: "Npwp", |  | ||||||
|           dataIndex: "npwp", |  | ||||||
|           key: "npwp", |  | ||||||
|         }, |  | ||||||
|         { |  | ||||||
|           title: "Address", |  | ||||||
|           dataIndex: "address", |  | ||||||
|           key: "address", |  | ||||||
|         }, |  | ||||||
|         { |  | ||||||
|           title: "Status", |  | ||||||
|           dataIndex: "status", |  | ||||||
|           key: "status", |  | ||||||
|           render: (text, record) => ( |  | ||||||
|             <Tag |  | ||||||
|               color={record?.status === true ? "processing" : "#E3E8EE"} |  | ||||||
|               style={{ color: "#4F566B" }} |  | ||||||
|             > |  | ||||||
|               {record?.status === true ? " ACTIVE" : "INACTIVE"} |  | ||||||
|             </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.commission.delete(id); |  | ||||||
|             message.success("Data Berhasil Dihapus"); |  | ||||||
|             history.push(LINKS.PRODUCT); |  | ||||||
|         } catch (err) { |  | ||||||
|             console.log("error", err); |  | ||||||
|             message.error("Gagal menghapus"); |  | ||||||
|         } |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     const handleDelete = (id) => { |     init(); | ||||||
|         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 = () => { |   const handleEditButton = (data) => { | ||||||
|         setIdData('') |     console.log(data, "isi data"); | ||||||
|         store.commission.visibleModalCommission = false; |     form.setFieldsValue({ | ||||||
|  |       value: data.commission, | ||||||
|  |     }); | ||||||
|  |     store.commission.visibleModalCommission = true; | ||||||
|  |     setIdData(data.id); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   const columns = [ | ||||||
|  |     { | ||||||
|  |       title: "Name", | ||||||
|  |       dataIndex: "name", | ||||||
|  |       key: "name", | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       title: "Amount", | ||||||
|  |       dataIndex: "commission", | ||||||
|  |       key: "commission", | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       title: "Action", | ||||||
|  |       key: "action", | ||||||
|  |       render: (text, record) => ( | ||||||
|  |         <Space size="middle"> | ||||||
|  |           <Button onClick={() => handleEditButton(record)}>Edit</Button> | ||||||
|  |         </Space> | ||||||
|  |       ), | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  |  | ||||||
|  |   const deleteData = async (id) => { | ||||||
|  |     try { | ||||||
|  |       console.log(id); | ||||||
|  |       await store.commission.delete(id); | ||||||
|  |       message.success("Data Berhasil Dihapus"); | ||||||
|  |       history.push(LINKS.PRODUCT); | ||||||
|  |     } catch (err) { | ||||||
|  |       console.log("error", err); | ||||||
|  |       message.error("Gagal menghapus"); | ||||||
|     } |     } | ||||||
|  |   }; | ||||||
|  |  | ||||||
|     const handleSubmit = async (data) => { |   const handleCancel = () => { | ||||||
|         console.log(data, "isi data2") |     setIdData(""); | ||||||
|         if (idData !== '') { |     store.commission.visibleModalCommission = false; | ||||||
|             setConfirmLoading(true); |   }; | ||||||
|             try { |  | ||||||
|                 await store.commission.update(idData, data) |   const handleSubmit = async (data) => { | ||||||
|                 message.success("Success Update Data Member") |     console.log(data, "isi data2"); | ||||||
|             } catch (e) { |     if (idData !== "") { | ||||||
|                 message.error("Failed Update Data Member") |       setConfirmLoading(true); | ||||||
|             } |       try { | ||||||
|             setConfirmLoading(false); |         await store.commission.update(idData, data); | ||||||
|             store.commission.visibleModalCommission = false; |         message.success("Success Update Data Member"); | ||||||
|             setIdData(''); |       } catch (e) { | ||||||
|             form.resetFields(); |         message.error("Failed Update Data Member"); | ||||||
|         } else { |       } | ||||||
|             setConfirmLoading(true); |       setConfirmLoading(false); | ||||||
|             try { |       store.commission.visibleModalCommission = false; | ||||||
|                 await store.commission.create(data) |       setIdData(""); | ||||||
|                 message.success("Success Add New Member") |       form.resetFields(); | ||||||
|             } catch (e) { |     } else { | ||||||
|                 console.log(e, "apa errornya") |       setConfirmLoading(true); | ||||||
|                 message.error("Failed Add Member") |       try { | ||||||
|             } |         await store.commission.create(data); | ||||||
|             setConfirmLoading(false); |         message.success("Success Add New Member"); | ||||||
|             store.commission.visibleModalCommission = false; |       } catch (e) { | ||||||
|             setIdData(''); |         console.log(e, "apa errornya"); | ||||||
|             form.resetFields(); |         message.error("Failed Add Member"); | ||||||
|         } |       } | ||||||
|  |       setConfirmLoading(false); | ||||||
|  |       store.commission.visibleModalCommission = false; | ||||||
|  |       setIdData(""); | ||||||
|  |       form.resetFields(); | ||||||
|     } |     } | ||||||
|  |   }; | ||||||
|  |  | ||||||
|     return ( |   return ( | ||||||
|         <div> |     <div> | ||||||
|             <Table |       <Table | ||||||
|                 style={{textAlign: "center"}} |         style={{ textAlign: "center" }} | ||||||
|                 columns={columns} |         columns={columns} | ||||||
|                 dataSource={store.commission.data} |         dataSource={store.commission.data} | ||||||
|                 bordered |         bordered | ||||||
|                 pagination={{ |         pagination={{ | ||||||
|                     pageSize: store.product.pageSize, |           pageSize: store.product.pageSize, | ||||||
|                     total: store.product.total_data, |           total: store.product.total_data, | ||||||
|                     current: store.product.page + 1, |           current: store.product.page + 1, | ||||||
|                     showSizeChanger: true, |           showSizeChanger: true, | ||||||
|                     simple: false |           simple: false, | ||||||
|                 }} |         }} | ||||||
|                 onChange={async (page) => { |         onChange={async (page) => { | ||||||
|                     let pageNumber = page.current; |           let pageNumber = page.current; | ||||||
|                     store.commission.pageSize = page.pageSize; |           store.commission.pageSize = page.pageSize; | ||||||
|                     store.commission.page = pageNumber - 1; |           store.commission.page = pageNumber - 1; | ||||||
|                     // store.membership.isLoading = true; |           // store.membership.isLoading = true; | ||||||
|                     await store.commission.getData(); |           await store.commission.getData(); | ||||||
|                     // store.membership.isLoading = false; |           // store.membership.isLoading = false; | ||||||
|                 }} |         }} | ||||||
|             /> |       /> | ||||||
|  |  | ||||||
|             <Modal |       <Modal | ||||||
|                 visible={store.commission.visibleModalCommission} |         visible={store.commission.visibleModalCommission} | ||||||
|                 title={idData ? "Edit Commission" : "Create a new commission"} |         title={idData ? "Edit Commission" : "Create a new commission"} | ||||||
|                 okText={idData ? "Edit" : "Create"} |         okText={idData ? "Edit" : "Create"} | ||||||
|                 cancelText="Cancel" |         cancelText="Cancel" | ||||||
|                 onCancel={() => { |         onCancel={() => { | ||||||
|                     form.resetFields(); |           form.resetFields(); | ||||||
|                     handleCancel(); |           handleCancel(); | ||||||
|                 }} |         }} | ||||||
|                 onOk={() => { |         onOk={() => { | ||||||
|                     form |           form | ||||||
|                         .validateFields() |             .validateFields() | ||||||
|                         .then((values) => { |             .then((values) => { | ||||||
|                             console.log(values, "isi form") |               console.log(values, "isi form"); | ||||||
|                             handleSubmit(values); |               handleSubmit(values); | ||||||
|                             form.resetFields(); |               form.resetFields(); | ||||||
|                         }) |             }) | ||||||
|                         .catch((info) => { |             .catch((info) => { | ||||||
|                             console.error("Validate Failed:", info); |               console.error("Validate Failed:", info); | ||||||
|                         }); |             }); | ||||||
|                 }} |         }} | ||||||
|             > |       > | ||||||
|                 <Form |         <Form form={form} layout="vertical"> | ||||||
|                     form={form} |           <Form.Item | ||||||
|                     layout="vertical" |             name="value" | ||||||
|                 > |             label="Commission" | ||||||
|                     <Form.Item |             rules={[{ required: true, message: "Please input commission!" }]} | ||||||
|                     name="name" |           > | ||||||
|                     label="Name" |             <Input /> | ||||||
|                     rules={[{required: true, message: 'Please input name!'}]} |           </Form.Item> | ||||||
|                 > |         </Form> | ||||||
|                     <Input/> |       </Modal> | ||||||
|                 </Form.Item> |     </div> | ||||||
|                 <Form.Item |   ); | ||||||
|                     name="owner" |  | ||||||
|                     label="Owner" |  | ||||||
|                     rules={[{required: true, message: 'Please input owner!'}]} |  | ||||||
|                 > |  | ||||||
|                     <Input/> |  | ||||||
|                 </Form.Item> |  | ||||||
|                 <Form.Item |  | ||||||
|                     name="password_account" |  | ||||||
|                     label="Password Account" |  | ||||||
|                     rules={[{required: true, message: 'Please input password account!'}]} |  | ||||||
|                 > |  | ||||||
|                     <Input/> |  | ||||||
|                 </Form.Item> |  | ||||||
|                 <Form.Item |  | ||||||
|                     name="npwp" |  | ||||||
|                     label="Npwp" |  | ||||||
|                     rules={[{required: true, message: 'Please input npwp!'}]} |  | ||||||
|                 > |  | ||||||
|                     <Input/> |  | ||||||
|                 </Form.Item> |  | ||||||
|                 <Form.Item |  | ||||||
|                     name="address" |  | ||||||
|                     label="address" |  | ||||||
|                     rules={[{required: true, message: 'Please input password!'}]} |  | ||||||
|                 > |  | ||||||
|                     <Input/> |  | ||||||
|                 </Form.Item> |  | ||||||
|                 </Form> |  | ||||||
|             </Modal> |  | ||||||
|         </div> |  | ||||||
|     ); |  | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -1,43 +1,23 @@ | |||||||
| import React, { useEffect, useState } from "react"; | import React, { useEffect, useState } from "react"; | ||||||
| import { | import { Button, Form, Input, message, Modal, Space, Table, Tag } from "antd"; | ||||||
|   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 { useStore } from "../utils/useStore"; | import { useStore } from "../utils/useStore"; | ||||||
| import { LINKS } from "../routes/app"; | import { LINKS } from "../routes/app"; | ||||||
|  | import { TopupsaldoModal } from "./TopupsaldoModal"; | ||||||
|  |  | ||||||
| export const SupplierComponent = observer((props) => { | export const SupplierComponent = observer((props) => { | ||||||
|   const store = useStore(); |   const store = useStore(); | ||||||
|   const [form] = Form.useForm(); |   const [form] = Form.useForm(); | ||||||
|   //const [formEdit] = Form.useForm(); |  | ||||||
|   const { Option } = Select; |  | ||||||
|   const history = useHistory(); |   const history = useHistory(); | ||||||
|   const [idData, setIdData] = useState(""); |   const [idData, setIdData] = useState(""); | ||||||
|   const [confirmLoading, setConfirmLoading] = useState(false); |   const [code, setCode] = useState(""); | ||||||
|   const [isLoading, setIsLoading] = useState(false); |  | ||||||
|  |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const init = async () => { |     const init = async () => { | ||||||
|       try { |       await store.supplier.getData(); | ||||||
|         setIsLoading(true); |  | ||||||
|         await store.supplier.getData(); |  | ||||||
|         setIsLoading(false); |  | ||||||
|       } catch (e) { |  | ||||||
|         setIsLoading(false); |  | ||||||
|       } |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     init(); |     init(); | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
| @@ -52,6 +32,14 @@ export const SupplierComponent = observer((props) => { | |||||||
|     setIdData(data.id); |     setIdData(data.id); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   const handleTopup = (data) => { | ||||||
|  |     console.log(data, "isi data"); | ||||||
|  |     form.setFieldsValue({ | ||||||
|  |       code: data.code, | ||||||
|  |     }); | ||||||
|  |     store.supplier.visibleModalTransaction = true; | ||||||
|  |     setCode(data.code); | ||||||
|  |   }; | ||||||
|   const changeStatus = async (id, isActive) => { |   const changeStatus = async (id, isActive) => { | ||||||
|     const status = isActive ? "inactive" : "active"; |     const status = isActive ? "inactive" : "active"; | ||||||
|     const status2 = isActive ? "Inactivating" : "Activating"; |     const status2 = isActive ? "Inactivating" : "Activating"; | ||||||
| @@ -78,6 +66,12 @@ export const SupplierComponent = observer((props) => { | |||||||
|       dataIndex: "code", |       dataIndex: "code", | ||||||
|       key: "code", |       key: "code", | ||||||
|     }, |     }, | ||||||
|  |     , | ||||||
|  |     { | ||||||
|  |       title: "Saldo", | ||||||
|  |       dataIndex: "saldo", | ||||||
|  |       key: "saldo", | ||||||
|  |     }, | ||||||
|     { |     { | ||||||
|       title: "Status", |       title: "Status", | ||||||
|       dataIndex: "status", |       dataIndex: "status", | ||||||
| @@ -85,8 +79,7 @@ export const SupplierComponent = observer((props) => { | |||||||
|       render: (text, record) => ( |       render: (text, record) => ( | ||||||
|         <Tag |         <Tag | ||||||
|           color={record?.status === true ? "processing" : "#E3E8EE"} |           color={record?.status === true ? "processing" : "#E3E8EE"} | ||||||
|           style={{ color: "#4F566B", cursor: "pointer" }} |           style={{ color: "#4F566B"}} | ||||||
|           onClick={() => changeStatus(record?.id, record?.status)} |  | ||||||
|         > |         > | ||||||
|           {record?.status === true ? " ACTIVE" : "INACTIVE"} |           {record?.status === true ? " ACTIVE" : "INACTIVE"} | ||||||
|         </Tag> |         </Tag> | ||||||
| @@ -98,7 +91,13 @@ export const SupplierComponent = observer((props) => { | |||||||
|       render: (text, record) => ( |       render: (text, record) => ( | ||||||
|         <Space size="middle"> |         <Space size="middle"> | ||||||
|           <Button onClick={() => handleEditButton(record)}>Edit</Button> |           <Button onClick={() => handleEditButton(record)}>Edit</Button> | ||||||
|           <Button onClick={() => handleDelete(record.id)}>Delete</Button> |           <Button | ||||||
|  |             type={record?.status === true ? "danger" : "primary"} | ||||||
|  |             onClick={() => changeStatus(record?.id, record?.status)} | ||||||
|  |           > | ||||||
|  |             {record?.status === true ? "INACTIVE" : "ACTIVE"} | ||||||
|  |           </Button> | ||||||
|  |           <Button onClick={() => handleTopup(record)}> Top Up Saldo</Button> | ||||||
|         </Space> |         </Space> | ||||||
|       ), |       ), | ||||||
|     }, |     }, | ||||||
| @@ -140,7 +139,6 @@ export const SupplierComponent = observer((props) => { | |||||||
|   const handleSubmit = async (data) => { |   const handleSubmit = async (data) => { | ||||||
|     console.log(data, "isi data2"); |     console.log(data, "isi data2"); | ||||||
|     if (idData !== "") { |     if (idData !== "") { | ||||||
|       setConfirmLoading(true); |  | ||||||
|       try { |       try { | ||||||
|         await store.supplier.update(idData, data); |         await store.supplier.update(idData, data); | ||||||
|         message.success("Success Update Data Member"); |         message.success("Success Update Data Member"); | ||||||
| @@ -148,21 +146,19 @@ export const SupplierComponent = observer((props) => { | |||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         message.error("Failed Update Data Member"); |         message.error("Failed Update Data Member"); | ||||||
|       } |       } | ||||||
|       setConfirmLoading(false); |  | ||||||
|       store.supplier.visibleModalSupplier = false; |       store.supplier.visibleModalSupplier = false; | ||||||
|       setIdData(""); |       setIdData(""); | ||||||
|       form.resetFields(); |       form.resetFields(); | ||||||
|     } else { |     } else { | ||||||
|       setConfirmLoading(true); |  | ||||||
|       try { |       try { | ||||||
|         await store.supplier.create(data); |         await store.supplier.create(data); | ||||||
|         message.success("Success Add New Member"); |         message.success("Success Add New Member"); | ||||||
|         //await store.supplier.getData() |  | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         console.log(e, "apa errornya"); |         console.log(e, "apa errornya"); | ||||||
|         message.error("Failed Add Member"); |         message.error("Failed Add Member"); | ||||||
|       } |       } | ||||||
|       setConfirmLoading(false); |  | ||||||
|       store.supplier.visibleModalSupplier = false; |       store.supplier.visibleModalSupplier = false; | ||||||
|       setIdData(""); |       setIdData(""); | ||||||
|       form.resetFields(); |       form.resetFields(); | ||||||
| @@ -187,12 +183,9 @@ export const SupplierComponent = observer((props) => { | |||||||
|           let pageNumber = page.current; |           let pageNumber = page.current; | ||||||
|           store.supplier.pageSize = page.pageSize; |           store.supplier.pageSize = page.pageSize; | ||||||
|           store.supplier.page = pageNumber - 1; |           store.supplier.page = pageNumber - 1; | ||||||
|           // store.membership.isLoading = true; |  | ||||||
|           await store.supplier.getData(); |           await store.supplier.getData(); | ||||||
|           // store.membership.isLoading = false; |  | ||||||
|         }} |         }} | ||||||
|       /> |       /> | ||||||
|  |  | ||||||
|       <Modal |       <Modal | ||||||
|         visible={store.supplier.visibleModalSupplier} |         visible={store.supplier.visibleModalSupplier} | ||||||
|         title={idData ? "Edit Supplier" : "Create a new Supplier"} |         title={idData ? "Edit Supplier" : "Create a new Supplier"} | ||||||
| @@ -232,6 +225,7 @@ export const SupplierComponent = observer((props) => { | |||||||
|           </Form.Item> |           </Form.Item> | ||||||
|         </Form> |         </Form> | ||||||
|       </Modal> |       </Modal> | ||||||
|  |       <TopupsaldoModal code={code} /> | ||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
| }); | }); | ||||||
|   | |||||||
							
								
								
									
										74
									
								
								src/component/TopupsaldoModal.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								src/component/TopupsaldoModal.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | |||||||
|  | import React from "react"; | ||||||
|  | import { Form, Input, message, Modal } from "antd"; | ||||||
|  | import { observer } from "mobx-react-lite"; | ||||||
|  | import { useStore } from "../utils/useStore"; | ||||||
|  |  | ||||||
|  | export const TopupsaldoModal = observer((props) => { | ||||||
|  |   const store = useStore(); | ||||||
|  |   const [form] = Form.useForm(); | ||||||
|  |  | ||||||
|  |   const handleCancelTransaction = () => { | ||||||
|  |     store.supplier.visibleModalTransaction = false; | ||||||
|  |   }; | ||||||
|  |   const handleSubmitTransaction = async (data) => { | ||||||
|  |     console.log(data, "isi data2"); | ||||||
|  |  | ||||||
|  |     try { | ||||||
|  |       await store.supplier.createTransaction(data); | ||||||
|  |       message.success("Success Top Up"); | ||||||
|  |     } catch (e) { | ||||||
|  |       console.log(e, "apa errornya"); | ||||||
|  |       message.error("Failed Top Up"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     store.supplier.visibleModalTransaction = false; | ||||||
|  |     form.resetFields(); | ||||||
|  |   }; | ||||||
|  |   return ( | ||||||
|  |     <div> | ||||||
|  |       <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" | ||||||
|  |           initialValues={{ supplier: props.code }} | ||||||
|  |         > | ||||||
|  |           <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> | ||||||
|  |   ); | ||||||
|  | }); | ||||||
| @@ -1,90 +1,73 @@ | |||||||
| import React, {useEffect, useState} from "react"; | import React, { useEffect, useState } from "react"; | ||||||
| import {Button, Card, Col, Input, Row, Tabs} from "antd"; | import { Button, Card, Col, Input, Row, Tabs } from "antd"; | ||||||
| import {FilterOutlined, PlusSquareOutlined,} from "@ant-design/icons"; | import { FilterOutlined, PlusSquareOutlined } from "@ant-design/icons"; | ||||||
| import {BreadcumbComponent} from "../../component/BreadcumbComponent"; | import { BreadcumbComponent } from "../../component/BreadcumbComponent"; | ||||||
| import {useStore} from "../../utils/useStore"; | import { useStore } from "../../utils/useStore"; | ||||||
| import {observer} from "mobx-react-lite"; | import { observer } from "mobx-react-lite"; | ||||||
| import {CommissionComponent} from "../../component/CommissionComponent"; | import { CommissionComponent } from "../../component/CommissionComponent"; | ||||||
| import {LINKS} from "../../routes/app"; | import { LINKS } from "../../routes/app"; | ||||||
|  |  | ||||||
| const {TabPane} = Tabs; | const { TabPane } = Tabs; | ||||||
| const {Search} = Input; | const { Search } = Input; | ||||||
|  |  | ||||||
| export const Commission = observer(() => { | export const Commission = observer(() => { | ||||||
|     const [isLoading, setIsLoading] = useState(false); |   const [isLoading, setIsLoading] = useState(false); | ||||||
|     const store = useStore(); |   const store = useStore(); | ||||||
|  |  | ||||||
|     useEffect(() => { |   useEffect(() => { | ||||||
|         const init = async () => { |     const init = async () => { | ||||||
|             try { |       try { | ||||||
|                 setIsLoading(true); |         setIsLoading(true); | ||||||
|                 //await store.commission.getDataCategories(); |         //await store.commission.getDataCategories(); | ||||||
|                 await store.commission.getData(); |         await store.commission.getData(); | ||||||
|                 setIsLoading(false); |         setIsLoading(false); | ||||||
|             } catch (e) { |       } catch (e) { | ||||||
|                 setIsLoading(false); |         setIsLoading(false); | ||||||
|             } |       } | ||||||
|         }; |     }; | ||||||
|  |  | ||||||
|         init(); |     init(); | ||||||
|     }, []); |   }, []); | ||||||
|  |  | ||||||
|     // const handleChangeTabPane = async (key) => { |   const routeData = [ | ||||||
|     //     store.product.filterCategory = key; |     { | ||||||
|     //     console.log(key); |       route: LINKS.HOME, | ||||||
|     // }; |       name: "Home", | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       route: LINKS.COMMISSION, | ||||||
|  |       name: <span style={{ fontWeight: "bold" }}>Commission</span>, | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  |  | ||||||
|     const routeData = [ |   return ( | ||||||
|         { |     <div className={["ppob-container"].join(" ")}> | ||||||
|             route: LINKS.HOME, |       <BreadcumbComponent data={routeData} /> | ||||||
|             name: "Home", |       <Card> | ||||||
|         }, |         {/* <Row style={{ marginBottom: 20 }}> */} | ||||||
|         { |           {/* <Col span={12}> | ||||||
|             route: LINKS.COMMISSION, |             <Button> | ||||||
|             name: <span style={{fontWeight: 'bold'}}>Commission</span>, |               <FilterOutlined /> | ||||||
|         }, |               Filter | ||||||
|     ]; |             </Button> | ||||||
|  |           </Col> */} | ||||||
|  |           {/* <Col span={24} style={{ textAlign: "right" }}> | ||||||
|  |             <Search | ||||||
|  |               placeholder="input search text" | ||||||
|  |               style={{ | ||||||
|  |                 width: store.ui.mediaQuery.isMobile ? 160 : 200, | ||||||
|  |                 marginRight: store.ui.mediaQuery.isMobile ? 0 : 10, | ||||||
|  |                 marginBottom: store.ui.mediaQuery.isMobile ? 10 : 0, | ||||||
|  |               }} | ||||||
|  |             /> | ||||||
|  |             <Button onClick={() => (store.commission.visibleModalCommission = true)}> | ||||||
|  |               <PlusSquareOutlined /> New | ||||||
|  |             </Button> | ||||||
|  |           </Col> | ||||||
|  |         </Row> */} | ||||||
|  |         <div style={{marginTop:20}}> <CommissionComponent/></div> | ||||||
|         |         | ||||||
|     return ( |       </Card> | ||||||
|         <div className={["ppob-container"].join(" ")}> |     </div> | ||||||
|             <BreadcumbComponent data={routeData}/> |   ); | ||||||
|             <Card> |  | ||||||
|                 <Row style={{marginBottom: 20}}> |  | ||||||
|                     <Col span={12}> |  | ||||||
|                         <Button> |  | ||||||
|                             <FilterOutlined/> |  | ||||||
|                             Filter |  | ||||||
|                         </Button> |  | ||||||
|                     </Col> |  | ||||||
|                     <Col span={12} style={{textAlign: "right"}}> |  | ||||||
|                         <Search |  | ||||||
|                             placeholder="input search text" |  | ||||||
|                             style={{ |  | ||||||
|                                 width: store.ui.mediaQuery.isMobile ? 160 : 200, |  | ||||||
|                                 marginRight: store.ui.mediaQuery.isMobile ? 0 : 10, |  | ||||||
|                                 marginBottom: store.ui.mediaQuery.isMobile ? 10 : 0, |  | ||||||
|                               }} |  | ||||||
|                         /> |  | ||||||
|                         <Button onClick={() => store.partner.visibleModalPartner = true}> |  | ||||||
|                             <PlusSquareOutlined/> New |  | ||||||
|                         </Button> |  | ||||||
|                     </Col> |  | ||||||
|                 </Row> |  | ||||||
|                 <Tabs |  | ||||||
|                     //onChange={handleChangeTabPane} |  | ||||||
|                     size="default" |  | ||||||
|                     tabBarGutter="50" |  | ||||||
|                 > |  | ||||||
|                      |  | ||||||
|                         <TabPane |  | ||||||
|                             tab="Commision" |  | ||||||
|                             key="1" |  | ||||||
|                         > |  | ||||||
|                             <CommissionComponent/> |  | ||||||
|                         </TabPane> |  | ||||||
|                     )) |  | ||||||
|                 </Tabs> |  | ||||||
|             </Card> |  | ||||||
|         </div> |  | ||||||
|     ); |  | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -47,28 +47,6 @@ export const Supplier = observer(() => { | |||||||
|     init(); |     init(); | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
|   // const handleChangeTabPane = async (key) => { |  | ||||||
|   //     store.product.filterCategory = key; |  | ||||||
|   //     console.log(key); |  | ||||||
|   // }; |  | ||||||
|   const handleCancelTransaction = () => { |  | ||||||
|     store.supplier.visibleModalTransaction = false; |  | ||||||
|   }; |  | ||||||
|   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(); |  | ||||||
|   }; |  | ||||||
|   const routeData = [ |   const routeData = [ | ||||||
|     { |     { | ||||||
|       route: LINKS.HOME, |       route: LINKS.HOME, | ||||||
| @@ -85,13 +63,13 @@ export const Supplier = observer(() => { | |||||||
|       <BreadcumbComponent data={routeData} /> |       <BreadcumbComponent data={routeData} /> | ||||||
|       <Card> |       <Card> | ||||||
|         <Row style={{ marginBottom: 20 }}> |         <Row style={{ marginBottom: 20 }}> | ||||||
|           <Col span={12}> |           {/* <Col span={12}> | ||||||
|             <Button> |             <Button> | ||||||
|               <FilterOutlined /> |               <FilterOutlined /> | ||||||
|               Filter |               Filter | ||||||
|             </Button> |             </Button> | ||||||
|           </Col> |           </Col> */} | ||||||
|           <Col span={12} style={{ textAlign: "right" }}> |           <Col span={24} style={{ textAlign: "right" }}> | ||||||
|             <Search |             <Search | ||||||
|               placeholder="input search text" |               placeholder="input search text" | ||||||
|               style={{ |               style={{ | ||||||
| @@ -102,76 +80,14 @@ export const Supplier = observer(() => { | |||||||
|               onSearch={(value) => console.log(value)} |               onSearch={(value) => console.log(value)} | ||||||
|             /> |             /> | ||||||
|             <Button |             <Button | ||||||
|               //style={{ marginLeft: "10px" }} |  | ||||||
|               onClick={() => (store.supplier.visibleModalSupplier = true)} |               onClick={() => (store.supplier.visibleModalSupplier = true)} | ||||||
|             > |             > | ||||||
|               <PlusSquareOutlined /> New |               <PlusSquareOutlined /> New | ||||||
|             </Button> |             </Button> | ||||||
|           </Col> |           </Col> | ||||||
|         </Row> |         </Row> | ||||||
|         <Col span={24} style={{ textAlign: "right" }}> |         <SupplierComponent /> | ||||||
|           <Button |  | ||||||
|             onClick={() => (store.supplier.visibleModalTransaction = true)} |  | ||||||
|           > |  | ||||||
|             <DownloadOutlined /> Top Up Saldo |  | ||||||
|           </Button> |  | ||||||
|         </Col> |  | ||||||
|         <Tabs |  | ||||||
|           //onChange={handleChangeTabPane} |  | ||||||
|           size="default" |  | ||||||
|           tabBarGutter="50" |  | ||||||
|         > |  | ||||||
|           <TabPane tab="Supplier" key="1"> |  | ||||||
|             <SupplierComponent /> |  | ||||||
|           </TabPane> |  | ||||||
|           )) |  | ||||||
|         </Tabs> |  | ||||||
|       </Card> |       </Card> | ||||||
|       <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!" }]} |  | ||||||
|           > |  | ||||||
|             <Select placeholder="Select Code Supplier" allowClear> |  | ||||||
|               {store.supplier.data.map((item) => ( |  | ||||||
|                 <Option value={item.code} key={item.code}> |  | ||||||
|                   {item.code} |  | ||||||
|                 </Option> |  | ||||||
|               ))} |  | ||||||
|             </Select> |  | ||||||
|           </Form.Item> |  | ||||||
|           <Form.Item |  | ||||||
|             name="amount" |  | ||||||
|             label="Amount" |  | ||||||
|             rules={[{ required: true, message: "Please input amount!" }]} |  | ||||||
|           > |  | ||||||
|             <Input /> |  | ||||||
|           </Form.Item> |  | ||||||
|         </Form> |  | ||||||
|       </Modal> |  | ||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -12,6 +12,8 @@ import { | |||||||
|   Space, |   Space, | ||||||
|   Table, |   Table, | ||||||
|   Tag, |   Tag, | ||||||
|  |   Form, | ||||||
|  |   Select, | ||||||
| } from "antd"; | } from "antd"; | ||||||
| import { useStore } from "../../utils/useStore"; | import { useStore } from "../../utils/useStore"; | ||||||
| import { observer } from "mobx-react-lite"; | import { observer } from "mobx-react-lite"; | ||||||
| @@ -19,14 +21,16 @@ import { | |||||||
|   ExclamationCircleOutlined, |   ExclamationCircleOutlined, | ||||||
|   FilterOutlined, |   FilterOutlined, | ||||||
|   PlusSquareOutlined, |   PlusSquareOutlined, | ||||||
|  |   DownloadOutlined, | ||||||
| } from "@ant-design/icons"; | } from "@ant-design/icons"; | ||||||
| import { MembershipModal } from "./MembershipModal"; | import { MembershipModal } from "./MembershipModal"; | ||||||
| import { BreadcumbComponent } from "../../component/BreadcumbComponent"; | import { BreadcumbComponent } from "../../component/BreadcumbComponent"; | ||||||
| import { LINKS } from "../../routes/app"; | import { LINKS } from "../../routes/app"; | ||||||
|  |  | ||||||
| const { Search } = Input; | const { Search } = Input; | ||||||
|  | const { Option } = Select; | ||||||
| export const Membership = observer(() => { | export const Membership = observer(() => { | ||||||
|  |   const [form] = Form.useForm(); | ||||||
|   const store = useStore(); |   const store = useStore(); | ||||||
|   const [visibleModal, setVisibleModal] = useState(false); |   const [visibleModal, setVisibleModal] = useState(false); | ||||||
|   const [initialData, setInitialData] = useState({}); |   const [initialData, setInitialData] = useState({}); | ||||||
| @@ -62,6 +66,24 @@ export const Membership = observer(() => { | |||||||
|       message.error(`Failed ${status2} Membership`); |       message.error(`Failed ${status2} Membership`); | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|  |   const handleCancelTransaction = () => { | ||||||
|  |     store.supplier.visibleModalTransaction = false; | ||||||
|  |   }; | ||||||
|  |   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(); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   const columns = [ |   const columns = [ | ||||||
|     { |     { | ||||||
| @@ -219,6 +241,19 @@ export const Membership = observer(() => { | |||||||
|               </Button> |               </Button> | ||||||
|             </Col> |             </Col> | ||||||
|           </Row> |           </Row> | ||||||
|  |           <Col | ||||||
|  |             span={24} | ||||||
|  |             style={{ | ||||||
|  |               textAlign: "right", | ||||||
|  |               marginBottom: store.ui.mediaQuery.isMobile ? 30 : 10, | ||||||
|  |             }} | ||||||
|  |           > | ||||||
|  |             <Button | ||||||
|  |               onClick={() => (store.supplier.visibleModalTransaction = true)} | ||||||
|  |             > | ||||||
|  |               <DownloadOutlined /> Top Up Saldo | ||||||
|  |             </Button> | ||||||
|  |           </Col> | ||||||
|           {store.ui.mediaQuery.isDesktop && ( |           {store.ui.mediaQuery.isDesktop && ( | ||||||
|             <Table |             <Table | ||||||
|               key="1" |               key="1" | ||||||
| @@ -306,6 +341,51 @@ export const Membership = observer(() => { | |||||||
|           )} |           )} | ||||||
|         </div> |         </div> | ||||||
|       </Card> |       </Card> | ||||||
|  |       <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!" }]} | ||||||
|  |           > | ||||||
|  |             <Select placeholder="Select Code Supplier" allowClear> | ||||||
|  |               {store.supplier.data.map((item) => ( | ||||||
|  |                 <Option value={item.code} key={item.code}> | ||||||
|  |                   {item.code} | ||||||
|  |                 </Option> | ||||||
|  |               ))} | ||||||
|  |             </Select> | ||||||
|  |           </Form.Item> | ||||||
|  |           <Form.Item | ||||||
|  |             name="amount" | ||||||
|  |             label="Amount" | ||||||
|  |             rules={[{ required: true, message: "Please input amount!" }]} | ||||||
|  |           > | ||||||
|  |             <Input /> | ||||||
|  |           </Form.Item> | ||||||
|  |         </Form> | ||||||
|  |       </Modal> | ||||||
|       <MembershipModal |       <MembershipModal | ||||||
|         visible={visibleModal} |         visible={visibleModal} | ||||||
|         confirmLoading={confirmLoading} |         confirmLoading={confirmLoading} | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ export class Commission { | |||||||
|     data = []; |     data = []; | ||||||
|     total_data = 0; |     total_data = 0; | ||||||
|     filterCategory = null; |     filterCategory = null; | ||||||
|     visibleModalSupplier = false; |     visibleModalCommission = false; | ||||||
|  |  | ||||||
|     pageCategories = 0; |     pageCategories = 0; | ||||||
|     pageSizeCategories = 10 |     pageSizeCategories = 10 | ||||||
| @@ -37,7 +37,7 @@ export class Commission { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async update(id, data) { |     async update(id, data) { | ||||||
|         const response = await http.put(`/product/${id}`).send(data); |         const response = await http.put(`/config/commission/${id}`).send(data); | ||||||
|         await this.getData(); |         await this.getData(); | ||||||
|         return response; |         return response; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user