fix: responsive tabs by data T[Transaction page]

This commit is contained in:
buckyhelmsmash 2021-12-10 17:59:41 +07:00
parent 1caed6d769
commit 9208bd5dd8
2 changed files with 79 additions and 54 deletions

View File

@ -11,11 +11,17 @@ export const Pulsa = () => {
const [productData, setProductData] = useState([]) const [productData, setProductData] = useState([])
const [productFilter, setProductFilter] = useState("") const [productFilter, setProductFilter] = useState("")
// useEffect(()=>{ useEffect(() => {
// if(!productFilter){ if (!productFilter) {
// setProductData(store.transaction.data) console.log('⚡ filter is null', productFilter)
// } setProductData(store.transaction.data)
// },[productFilter]) } else {
console.log('⚡ filter is not null', productFilter)
setProductData(store.transaction.data.filter(function (product) {
return product.sub_categories.name === productFilter
}))
}
}, [productFilter])
useEffect(() => { useEffect(() => {
const init = async () => { const init = async () => {
@ -23,6 +29,7 @@ export const Pulsa = () => {
setIsLoading(true); setIsLoading(true);
await store.transaction.getDataSubCategories(); await store.transaction.getDataSubCategories();
await store.transaction.getData(); await store.transaction.getData();
await store.transaction.getDataCategories();
setIsLoading(false); setIsLoading(false);
} catch (e) { } catch (e) {
setIsLoading(false); setIsLoading(false);
@ -30,6 +37,7 @@ export const Pulsa = () => {
}; };
init(); init();
setProductFilter("")
}, []); }, []);
// data // data

View File

@ -1,4 +1,5 @@
import React from "react"; import React, { useEffect, useState } from "react";
import { useStore } from "../../utils/useStore";
import { Button, Card, Col, Input, Row, Tabs } from "antd"; import { Button, Card, Col, Input, Row, Tabs } from "antd";
import { FilterOutlined, } from "@ant-design/icons"; import { FilterOutlined, } from "@ant-design/icons";
import { BreadcumbComponent } from "../../component/BreadcumbComponent"; import { BreadcumbComponent } from "../../component/BreadcumbComponent";
@ -9,6 +10,31 @@ const {TabPane} = Tabs;
const { Search } = Input; const { Search } = Input;
export const Transaction = () => { export const Transaction = () => {
const store = useStore();
const [isLoading, setIsLoading] = useState(false);
// Init
useEffect(() => {
const init = async () => {
try {
setIsLoading(true);
await store.transaction.getDataCategories();
setIsLoading(false);
} catch (e) {
setIsLoading(false);
}
};
init();
}, []);
// Category
useEffect(() => {
console.log('⚡ transaction category store', store.transaction.dataCategories)
}, [store.transaction.dataCategories])
const callback = (key) => { const callback = (key) => {
console.log(key); console.log(key);
}; };
@ -46,21 +72,12 @@ export const Transaction = () => {
size="default" size="default"
tabBarGutter="50" tabBarGutter="50"
> >
<TabPane tab="Pulsa" key="1"> {store.transaction.dataCategories.map((item, index) => (
<TabPane tab={item.name} key={index}>
<Pulsa /> <Pulsa />
</TabPane> </TabPane>
<TabPane tab="Game Voucher" key="2"> ))}
Game Voucher
</TabPane>
<TabPane tab="Product" key="3">
Product
</TabPane>
<TabPane tab="Prduct" key="4">
Product
</TabPane>
<TabPane tab="Prdct" key="5">
Product
</TabPane>
</Tabs> </Tabs>
</Card> </Card>
</div> </div>