diff --git a/src/component/CategoryComponent.js b/src/component/CategoryComponent.js new file mode 100644 index 0000000..87f01c7 --- /dev/null +++ b/src/component/CategoryComponent.js @@ -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) => ( + // + // {capitalize(record?.status)} + // + // ), + // }, + // { + // title: "Tersedia", + // dataIndex: "tersedia", + // key: "tersedia", + // render: (text, record) => ( + // + // {record?.status === "ACTIVE" ? " Ya" : "Tidak"} + // + // ), + // }, + { + title: "Action", + key: "action", + render: (text, record) => ( + + + + + ), + }, + ]; + + 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: , + 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 ( +
+ { + 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; + }} + /> + + { + form.resetFields(); + handleCancel(); + }} + onOk={() => { + form + .validateFields() + .then((values) => { + console.log(values, "isi form") + handleSubmit(values); + form.resetFields(); + }) + .catch((info) => { + console.error("Validate Failed:", info); + }); + }} + > +
+ + + + +
+ + ); +}); diff --git a/src/component/PartnerComponent.js b/src/component/PartnerComponent.js index 64f27ee..87636a0 100644 --- a/src/component/PartnerComponent.js +++ b/src/component/PartnerComponent.js @@ -72,7 +72,7 @@ export const PartnerComponent = observer((props) => { dataIndex: "status", key: "status", render: (text, record) => ( - ), diff --git a/src/component/ProductComponent.js b/src/component/ProductComponent.js index 3266a2e..ec308be 100644 --- a/src/component/ProductComponent.js +++ b/src/component/ProductComponent.js @@ -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) => ( {capitalize(record?.status)} @@ -84,7 +85,7 @@ export const ProductComponent = observer((props) => { key: "tersedia", render: (text, record) => ( {record?.status === "ACTIVE" ? " Ya" : "Tidak"} diff --git a/src/component/SupplierComponent.js b/src/component/SupplierComponent.js index 95e527c..e23240e 100644 --- a/src/component/SupplierComponent.js +++ b/src/component/SupplierComponent.js @@ -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 (
{ + { + form.resetFields(); + handleCancelTransaction(); + }} + onOk={() => { + form + .validateFields() + .then((values) => { + console.log(values, "isi form"); + handleSubmitTransaction(values); + form.resetFields(); + }) + .catch((info) => { + console.error("Validate Failed:", info); + }); + }} + > +
+ + + + + + + +
); }); diff --git a/src/pages/App/MenuList.js b/src/pages/App/MenuList.js index e6d6a9c..b64a400 100644 --- a/src/pages/App/MenuList.js +++ b/src/pages/App/MenuList.js @@ -4,10 +4,13 @@ import {Link} from "react-router-dom"; import { AppstoreOutlined, DatabaseOutlined, + FileAddOutlined, FileProtectOutlined, + FileSyncOutlined, HomeOutlined, MenuUnfoldOutlined, MoneyCollectOutlined, + ProfileOutlined, ProjectOutlined, UserOutlined, } from "@ant-design/icons"; @@ -83,6 +86,40 @@ export const MenuList = observer((props) => { )} + {store.authentication.userData.role !== "Retail" && ( + } + title="Product" + > + + + + Product + + + + + + Category + + + + + + Sub Category + + + + )} + {store.authentication.userData.role === ("Retail" || "Admin") && ( + + + + Transaction + + + )} {store.authentication.userData.role !== "Retail" && ( @@ -108,16 +145,16 @@ export const MenuList = observer((props) => { - Profile - - - {/**/} - {/* */} - {/* */} - {/* About*/} - {/* */} - {/**/} - - + Profile + + + {/**/} + {/* */} + {/* */} + {/* About*/} + {/* */} + {/**/} + + ); }); diff --git a/src/pages/Config/Supplier.js b/src/pages/Config/Supplier.js index 0e5474b..19de002 100644 --- a/src/pages/Config/Supplier.js +++ b/src/pages/Config/Supplier.js @@ -1,91 +1,97 @@ -import React, {useEffect, useState} from "react"; -import {Button, Card, Col, Input, Row, Tabs} from "antd"; -import {FilterOutlined, PlusSquareOutlined,} from "@ant-design/icons"; -import {BreadcumbComponent} from "../../component/BreadcumbComponent"; -import {useStore} from "../../utils/useStore"; -import {observer} from "mobx-react-lite"; -import {SupplierComponent} from "../../component/SupplierComponent"; -import {LINKS} from "../../routes/app"; +import React, { useEffect, useState } from "react"; +import { Button, Card, Col, Input, Row, Tabs } from "antd"; +import { FilterOutlined, PlusSquareOutlined,DownloadOutlined } from "@ant-design/icons"; +import { BreadcumbComponent } from "../../component/BreadcumbComponent"; +import { useStore } from "../../utils/useStore"; +import { observer } from "mobx-react-lite"; +import { SupplierComponent } from "../../component/SupplierComponent"; +import { LINKS } from "../../routes/app"; -const {TabPane} = Tabs; -const {Search} = Input; +const { TabPane } = Tabs; +const { Search } = Input; export const Supplier = observer(() => { - const [isLoading, setIsLoading] = useState(false); - const store = useStore(); + const [isLoading, setIsLoading] = useState(false); + const store = useStore(); - useEffect(() => { - const init = async () => { - try { - setIsLoading(true); - //await store.supplier.getDataCategories(); - await store.supplier.getData(); - setIsLoading(false); - } catch (e) { - setIsLoading(false); - } - }; + useEffect(() => { + const init = async () => { + try { + setIsLoading(true); + //await store.supplier.getDataCategories(); + await store.supplier.getData(); + setIsLoading(false); + } catch (e) { + setIsLoading(false); + } + }; - init(); - }, []); + init(); + }, []); - // const handleChangeTabPane = async (key) => { - // store.product.filterCategory = key; - // console.log(key); - // }; + // const handleChangeTabPane = async (key) => { + // store.product.filterCategory = key; + // console.log(key); + // }; - const routeData = [ - { - route: LINKS.HOME, - name: "Home", - }, - { - route: LINKS.SUPPLIER, - name: Supplier, - }, - ]; - - return ( -
- - - -
- - - - console.log(value)} - /> - - - - - - - - - )) - - - - ); + const routeData = [ + { + route: LINKS.HOME, + name: "Home", + }, + { + route: LINKS.SUPPLIER, + name: Supplier, + }, + ]; + + return ( +
+ + + +
+ + + + console.log(value)} + /> + + + + + + + + + + + )) + + + + ); }); diff --git a/src/pages/Membership/Membership.js b/src/pages/Membership/Membership.js index 95b271f..44b1186 100644 --- a/src/pages/Membership/Membership.js +++ b/src/pages/Membership/Membership.js @@ -48,7 +48,7 @@ export const Membership = observer(() => { key: "status", render: (text, record) => ( {record?.isActive === true ? " ACTIVE" : "INACTIVE"} diff --git a/src/pages/Payback/Payback.js b/src/pages/Payback/Payback.js index adb7056..c3c6738 100644 --- a/src/pages/Payback/Payback.js +++ b/src/pages/Payback/Payback.js @@ -53,7 +53,7 @@ export const Payback = observer(() => { amount: "Rp. 1.000.000", }, { - key: '4',Z + key: '4', id: 1, name: "John Doe", picture: "https://presidenproperti.com/wp-content/uploads/2018/11/blog-ph.jpg", diff --git a/src/pages/Product/Category.js b/src/pages/Product/Category.js new file mode 100644 index 0000000..3c875e1 --- /dev/null +++ b/src/pages/Product/Category.js @@ -0,0 +1,83 @@ +import React, { useEffect, useState } from "react"; +import { Button, Card, Col, Input, Row, Tabs } from "antd"; +import { FilterOutlined, PlusSquareOutlined } from "@ant-design/icons"; +import { BreadcumbComponent } from "../../component/BreadcumbComponent"; +import { useStore } from "../../utils/useStore"; +import { observer } from "mobx-react-lite"; +import { LINKS } from "../../routes/app"; +import { CategoryComponent } from "../../component/CategoryComponent"; + +const { TabPane } = Tabs; +const { Search } = Input; + +export const Category = observer(() => { + const [isLoading, setIsLoading] = useState(false); + const store = useStore(); + + useEffect(() => { + const init = async () => { + try { + setIsLoading(true); + //await store.product.getDataCategories(); + await store.category.getData(); + setIsLoading(false); + } catch (e) { + setIsLoading(false); + } + }; + + init(); + }, []); + + const handleChangeTabPane = async (key) => { + store.product.filterCategory = key; + console.log(key); + }; + + const routeData = [ + { + route: LINKS.HOME, + name: "Home", + }, + { + route: LINKS.CATEGORY, + name: Category, + }, + ]; + + return ( +
+ + + +
+ + + + + + + + + + + + + ))} + + + + ); +}); diff --git a/src/pages/Product/Product.js b/src/pages/Product/Product.js index fae9465..d756d5d 100644 --- a/src/pages/Product/Product.js +++ b/src/pages/Product/Product.js @@ -1,91 +1,86 @@ -import React, {useEffect, useState} from "react"; -import {Button, Card, Col, Input, Row, Tabs} from "antd"; -import {FilterOutlined, PlusSquareOutlined,} from "@ant-design/icons"; -import {BreadcumbComponent} from "../../component/BreadcumbComponent"; -import {useStore} from "../../utils/useStore"; -import {observer} from "mobx-react-lite"; -import {ProductComponent} from "../../component/ProductComponent"; -import {LINKS} from "../../routes/app"; +import React, { useEffect, useState } from "react"; +import { Button, Card, Col, Input, Row, Tabs } from "antd"; +import { FilterOutlined, PlusSquareOutlined } from "@ant-design/icons"; +import { BreadcumbComponent } from "../../component/BreadcumbComponent"; +import { useStore } from "../../utils/useStore"; +import { observer } from "mobx-react-lite"; +import { ProductComponent } from "../../component/ProductComponent"; +import { LINKS } from "../../routes/app"; -const {TabPane} = Tabs; -const {Search} = Input; +const { TabPane } = Tabs; +const { Search } = Input; export const Product = observer(() => { - const [isLoading, setIsLoading] = useState(false); - const store = useStore(); + const [isLoading, setIsLoading] = useState(false); + const store = useStore(); - useEffect(() => { - const init = async () => { - try { - setIsLoading(true); - await store.product.getDataCategories(); - await store.product.getData(); - setIsLoading(false); - } catch (e) { - setIsLoading(false); - } - }; - - init(); - }, []); - - const handleChangeTabPane = async (key) => { - store.product.filterCategory = key; - console.log(key); - await store.product.getData() + useEffect(() => { + const init = async () => { + try { + setIsLoading(true); + await store.product.getDataCategories(); + await store.product.getData(); + setIsLoading(false); + } catch (e) { + setIsLoading(false); + } }; - const routeData = [ - { - route: LINKS.HOME, - name: "Home", - }, - { - route: LINKS.PRODUCT, - name: Product, - }, - ]; + init(); + }, []); - return ( -
- - - -
- - - - - - - - - {store.product.dataCategories.map((item) => ( - - - - ))} - - - - ); + const handleChangeTabPane = async (key) => { + store.product.filterCategory = key; + console.log(key); + await store.product.getData(); + }; + + const routeData = [ + { + route: LINKS.HOME, + name: "Home", + }, + { + route: LINKS.PRODUCT, + name: Product, + }, + ]; + + return ( +
+ + + +
+ + + + + + + + + + {store.product.dataCategories.map((item) => ( + + {/* */} + + + ))} + + + + ); }); diff --git a/src/pages/Product/Subcategory.js b/src/pages/Product/Subcategory.js new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/app.js b/src/routes/app.js index 09e89b8..fb9f807 100644 --- a/src/routes/app.js +++ b/src/routes/app.js @@ -8,6 +8,7 @@ import {Profile} from "../pages/Profile/Profile"; import {Commission} from "../pages/Config/Commission"; import {Partner} from "../pages/Config/Partner"; import {Supplier} from "../pages/Config/Supplier"; +import {Category} from "../pages/Product/Category"; import {Payback} from "../pages/Payback/Payback"; @@ -21,6 +22,7 @@ export const LINKS = { PARTNER: "/app/partner", COMMISSION: "/app/commission", SUPPLIER: "/app/supplier", + CATEGORY: "/app/category", PAYBACK: "/app/payback", }; @@ -33,6 +35,9 @@ export const AppRoute = () => { + + + diff --git a/src/store/category.js b/src/store/category.js new file mode 100644 index 0000000..895de03 --- /dev/null +++ b/src/store/category.js @@ -0,0 +1,69 @@ +import {makeAutoObservable} from "mobx"; +import {http} from "../utils/http"; + +export class Category { + page = 0; + pageSize = 10 + data = []; + total_data = 0; + filterCategory = null; + visibleModalCategory = false; + + pageCategories = 0; + pageSizeCategories = 10 + dataCategories = []; + total_dataCategories = 0; + + pageSubCategories = 0; + pageSizeSubCategories = 10 + dataSubCategories = []; + total_dataSubCategories = 0; + + constructor(ctx) { + this.ctx = ctx; + makeAutoObservable(this); + } + + async getData() { + const response = await http.get(`/product/categories?page=${this.page}&pageSize=${this.pageSize}`); + console.log(response) + this.data = response.body.data ?? [] + this.total_data = response.body.total_data ?? 0 + } + + async getDataSubCategories() { + const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); + this.dataSubCategories = response.body.data ?? [] + this.total_dataSubCategories = response.body.count ?? 0 + } + + async getDataCategories() { + const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`); + + this.dataCategories = response.body.data ?? [] + this.total_dataCategories = response.body.total_data ?? 0 + if (this.dataCategories.length > 0) { + this.filterCategory = this.dataCategories[0].id + } + } + + async create(data) { + const response = await http.post('/product/categories').send(data); + await this.getData(); + return response; + } + + async update(id, data) { + const response = await http.put(`/product/categories/${id}`).send(data); + await this.getData(); + return response; + } + + async delete(id) { + const response = await http.del(`/product/${id}`); + await this.getData(); + return response; + } +} + + diff --git a/src/store/index.js b/src/store/index.js index 26a144f..2f07d46 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -8,6 +8,8 @@ import { Supplier } from "./supplier"; import { Commission } from "./commission"; import { Transaction } from "./transaction"; import { TokenUtil } from "../utils/token"; +import { Category } from "./category"; + import { Role } from "./role"; export class Store { @@ -19,6 +21,7 @@ export class Store { partner = new Partner(this); supplier = new Supplier(this); commission = new Commission(this); + category = new Category(this); transaction = new Transaction(this); role = new Role(this); diff --git a/src/store/membership.js b/src/store/membership.js index eba13d4..e8830c8 100644 --- a/src/store/membership.js +++ b/src/store/membership.js @@ -14,10 +14,16 @@ export class Membership { @action async getData() { - const response = await http.get(`/users/find-by-supperior?page=${this.page}&pageSize=${this.pageSize}`); + const response = await http.get(`/users?page=${this.page}&pageSize=${this.pageSize}`); + console.log(response) this.data = response.body.data ?? [] this.total_data = response.body.total_data ?? 0 } + // async getData() { + // const response = await http.get(`/users/find-by-supperior?page=${this.page}&pageSize=${this.pageSize}`); + // this.data = response.body.data ?? [] + // this.total_data = response.body.total_data ?? 0 + // } @action async create(data) { diff --git a/src/store/subcategory.js b/src/store/subcategory.js new file mode 100644 index 0000000..e69de29 diff --git a/src/store/supplier.js b/src/store/supplier.js index ecebdba..8464141 100644 --- a/src/store/supplier.js +++ b/src/store/supplier.js @@ -8,6 +8,7 @@ export class Supplier { total_data = 0; filterCategory = null; visibleModalSupplier = false; + visibleModalTransaction=false; pageCategories = 0; pageSizeCategories = 10 @@ -36,9 +37,14 @@ export class Supplier { await this.getData(); return response; } + async createTransaction(data) { + const response = await http.post('/transaction/add-saldo-supplier').send(data); + await this.getData(); + return response; + } async update(id, data) { - const response = await http.put(`/product/${id}`).send(data); + const response = await http.put(`/users/supplier/${id}`).send(data); await this.getData(); return response; }