From b8c407bf11808b52dfdc4c0b9c6063f20e922332 Mon Sep 17 00:00:00 2001 From: caturbgs Date: Thu, 16 Dec 2021 23:22:50 +0700 Subject: [PATCH] feat: adjust flow to display transaction --- src/pages/Transaction/Product.js | 107 +++++++++++++++++++++++ src/pages/Transaction/Pulsa.js | 126 --------------------------- src/pages/Transaction/Transaction.js | 79 +++++++---------- src/store/transaction.js | 7 +- 4 files changed, 143 insertions(+), 176 deletions(-) create mode 100644 src/pages/Transaction/Product.js delete mode 100644 src/pages/Transaction/Pulsa.js diff --git a/src/pages/Transaction/Product.js b/src/pages/Transaction/Product.js new file mode 100644 index 0000000..d451a31 --- /dev/null +++ b/src/pages/Transaction/Product.js @@ -0,0 +1,107 @@ +import React, {useEffect, useState} from "react"; +import {useStore} from "../../utils/useStore"; +import {Button, Card, Col, Input, Modal, Row, Select} from "antd"; +import {observer} from "mobx-react-lite"; + +const {Search} = Input; +const {Option} = Select; + +export const Product = observer(() => { + const store = useStore(); + + const [isLoading, setIsLoading] = useState(false); + const [productData, setProductData] = useState([]); + + useEffect(() => { + const init = async () => { + try { + setIsLoading(true); + await store.transaction.getDataSubCategories(); + await store.transaction.getDataCategories(); + setIsLoading(false); + } catch (e) { + setIsLoading(false); + } + }; + + init(); + }, []); + + // data + useEffect(() => { + console.log('⚡ transaction data store', store.transaction.data) + setProductData(store.transaction.data) + }, [store.transaction.data]) + + // Subcategory + useEffect(() => { + console.log('⚡ transaction subcategory store', store.transaction.dataSubCategories) + }, [store.transaction.dataSubCategories]) + + + const handleChangeSubcategory = async (item) => { + console.log('item', item); + store.transaction.filterSubCategory = item; + await store.transaction.getData(); + } + + const success = () => { + Modal.success({ + content: 'some messages...some messages...', + }); + } + + return ( +
+ + + Sub-Category + + + + + + + + + + Produk & Nominal + + + + + + {productData.length != 0 && + {productData.map((item, index) => ( + + + {item.name} +
+ {item.price} +
+ + ))} +
} + {productData.length != 0 && + + } +
+ ); +}); diff --git a/src/pages/Transaction/Pulsa.js b/src/pages/Transaction/Pulsa.js deleted file mode 100644 index bb7195d..0000000 --- a/src/pages/Transaction/Pulsa.js +++ /dev/null @@ -1,126 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { useStore } from "../../utils/useStore"; -import { Button, Card, Col, Dropdown, Menu, message, Modal, Row, Space, } from "antd"; -import { DownOutlined, TabletOutlined, UserOutlined } from "@ant-design/icons"; - -export const Pulsa = () => { - - const store = useStore(); - - const [isLoading, setIsLoading] = useState(false); - - const [productData, setProductData] = useState([]) - const [productFilter, setProductFilter] = useState("") - useEffect(() => { - if (!productFilter) { - console.log('⚡ filter is null', productFilter) - setProductData(store.transaction.data) - } else { - console.log('⚡ filter is not null', productFilter) - setProductData(store.transaction.data.filter(function (product) { - return product.sub_categories.name === productFilter - })) - } - }, [productFilter]) - - useEffect(() => { - const init = async () => { - try { - setIsLoading(true); - await store.transaction.getDataSubCategories(); - await store.transaction.getData(); - await store.transaction.getDataCategories(); - setIsLoading(false); - } catch (e) { - setIsLoading(false); - } - }; - - init(); - setProductFilter("") - }, []); - - // data - useEffect(() => { - console.log('⚡ transaction data store', store.transaction.data) - setProductData(store.transaction.data) - }, [store.transaction.data]) - - // Subcategory - useEffect(() => { - console.log('⚡ transaction subcategory store', store.transaction.dataSubCategories) - }, [store.transaction.dataSubCategories]) - - - function handleMenuClick(item) { - message.info("⚡ Click on menu item."); - console.log("⚡ click", item); - setProductFilter(item.name) - } - - const menu = ( - - {store.transaction.dataSubCategories.map((item, index) => ( - } onClick={() => handleMenuClick(item)} > - {item.name} - - ))} - - - ); - - function success() { - Modal.success({ - content: 'some messages...some messages...', - }); - } - - return ( -
- - - Sub-Category - - - - - - - - - - - - Produk & Nominal - - - - {productData.map((item, index) => ( - - - {item.name} -
- {item.price} -
- - ))} -
- - - -
- ); -}; diff --git a/src/pages/Transaction/Transaction.js b/src/pages/Transaction/Transaction.js index 33cf846..37a229e 100644 --- a/src/pages/Transaction/Transaction.js +++ b/src/pages/Transaction/Transaction.js @@ -1,16 +1,14 @@ -import React, { useEffect, useState } from "react"; -import { useStore } from "../../utils/useStore"; -import { Button, Card, Col, Input, Row, Tabs } from "antd"; -import { FilterOutlined, } from "@ant-design/icons"; -import { BreadcumbComponent } from "../../component/BreadcumbComponent"; -import { Pulsa } from "./Pulsa"; -import { LINKS } from "../../routes/app"; +import React, {useEffect, useState} from "react"; +import {useStore} from "../../utils/useStore"; +import {Card, Tabs} from "antd"; +import {BreadcumbComponent} from "../../component/BreadcumbComponent"; +import {Product} from "./Product"; +import {LINKS} from "../../routes/app"; +import {observer} from "mobx-react-lite"; -const { TabPane } = Tabs; -const { Search } = Input; - -export const Transaction = () => { +const {TabPane} = Tabs; +export const Transaction = observer(() => { const store = useStore(); const [isLoading, setIsLoading] = useState(false); @@ -35,9 +33,10 @@ export const Transaction = () => { console.log('⚡ transaction category store', store.transaction.dataCategories) }, [store.transaction.dataCategories]) - const callback = (key) => { - console.log(key); + const handleChangeTabs = async (key) => { + store.transaction.filterCategory = key; }; + const routeData = [ { route: LINKS.HOME, @@ -45,41 +44,27 @@ export const Transaction = () => { }, { route: LINKS.TRANSACTION, - name: Transaction, + name: Transaction, }, ]; - return ( -
- - - - - - - - - - - - {store.transaction.dataCategories.map((item, index) => ( - - - - ))} - - -
+ return ( +
+ + + + {store.transaction.dataCategories.map((item, index) => ( + + + + ))} + + + +
); -}; +}); diff --git a/src/store/transaction.js b/src/store/transaction.js index 9372be4..b0570ac 100644 --- a/src/store/transaction.js +++ b/src/store/transaction.js @@ -6,7 +6,7 @@ export class Transaction { pageSize = 10 data = []; total_data = 0; - filterCategory = null; + filterSubCategory = null; visibleModalProduct = false; pageCategories = 0; @@ -18,6 +18,7 @@ export class Transaction { pageSizeSubCategories = 10 dataSubCategories = []; total_dataSubCategories = 0; + filterSubCategory = null; pageHistoryTransaction = 0; // pageSizeHistoryTransaction = 10 @@ -31,7 +32,7 @@ export class Transaction { async getData() { try { - const response = await http.get(`/product/by-categories?categories=${this.filterCategory}&page=${this.page}&pageSize=${this.pageSize}`); + const response = await http.get(`/product/by-categories-all?subCategories=${this.filterSubCategory}&page=${this.page}&pageSize=${this.pageSize}`); this.data = response.body.data ?? [] this.total_data = response.body.total_data ?? 0 } catch (e) { @@ -41,7 +42,7 @@ export class Transaction { async getDataSubCategories() { try { - const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); + const response = await http.get(`/product/sub-categories?categories=${this.filterCategory}&page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); this.dataSubCategories = response.body.data ?? [] this.total_dataSubCategories = response.body.count ?? 0 } catch (e) {