feat: rewrite component use effect
This commit is contained in:
parent
2e0eb03d3a
commit
f89a1620db
|
@ -1,19 +1,7 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, {useState} from "react";
|
||||||
import {
|
import {Button, Form, Input, message, Modal, Select, Space, Table,} 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 {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";
|
||||||
|
|
||||||
|
@ -26,21 +14,6 @@ export const CategoryComponent = observer((props) => {
|
||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
const [isLoading, setIsLoading] = 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) => {
|
const handleEditButton = (data) => {
|
||||||
console.log(data, "isi data");
|
console.log(data, "isi data");
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
|
@ -154,18 +127,18 @@ export const CategoryComponent = observer((props) => {
|
||||||
dataSource={store.category.data}
|
dataSource={store.category.data}
|
||||||
bordered
|
bordered
|
||||||
pagination={{
|
pagination={{
|
||||||
pageSize: store.product.pageSize,
|
pageSize: store.category.pageSize,
|
||||||
total: store.product.total_data,
|
total: store.category.total_data,
|
||||||
current: store.product.page + 1,
|
current: store.category.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.product.pageSize = page.pageSize;
|
store.category.pageSize = page.pageSize;
|
||||||
store.product.page = pageNumber - 1;
|
store.category.page = pageNumber - 1;
|
||||||
// store.membership.isLoading = true;
|
// store.membership.isLoading = true;
|
||||||
await store.product.getData();
|
await store.category.getData();
|
||||||
// store.membership.isLoading = false;
|
// store.membership.isLoading = false;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -149,7 +149,6 @@ export const ProductComponent = observer((props) => {
|
||||||
|
|
||||||
const handleRemoveFilter = async () => {
|
const handleRemoveFilter = async () => {
|
||||||
store.product.filterSupplier = null;
|
store.product.filterSupplier = null;
|
||||||
store.product.filterCategory = null;
|
|
||||||
store.product.filterSubCategory = null;
|
store.product.filterSubCategory = null;
|
||||||
setFilterSupplier(null);
|
setFilterSupplier(null);
|
||||||
setFilterCategories(null);
|
setFilterCategories(null);
|
||||||
|
@ -167,7 +166,6 @@ export const ProductComponent = observer((props) => {
|
||||||
|
|
||||||
const handleSubmitFilter = async () => {
|
const handleSubmitFilter = async () => {
|
||||||
store.product.filterSupplier = filterSupplier;
|
store.product.filterSupplier = filterSupplier;
|
||||||
store.product.filterCategory = filterCategories;
|
|
||||||
store.product.filterSubCategory = filterSubCategories;
|
store.product.filterSubCategory = filterSubCategories;
|
||||||
await store.product.getData();
|
await store.product.getData();
|
||||||
store.product.visibleModalFilterProduct = false;
|
store.product.visibleModalFilterProduct = false;
|
||||||
|
|
|
@ -1,21 +1,8 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, {useState} from "react";
|
||||||
import {
|
import {Button, Form, Input, message, Modal, Select, Space, Table,} 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 {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";
|
|
||||||
|
|
||||||
export const SubcategoryComponent = observer((props) => {
|
export const SubcategoryComponent = observer((props) => {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
@ -26,24 +13,9 @@ export const SubcategoryComponent = observer((props) => {
|
||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const init = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
//store.product.pageCategories=StrToLower(props.category)
|
|
||||||
getData();
|
|
||||||
setIsLoading(false);
|
|
||||||
} catch (e) {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
init();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
await store.subcategory.getData();
|
|
||||||
await store.category.getData();
|
await store.category.getData();
|
||||||
|
await store.subcategory.getData();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditButton = (data) => {
|
const handleEditButton = (data) => {
|
||||||
|
@ -120,7 +92,7 @@ export const SubcategoryComponent = observer((props) => {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//console.log()
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table
|
<Table
|
||||||
|
@ -129,16 +101,16 @@ export const SubcategoryComponent = observer((props) => {
|
||||||
dataSource={store.subcategory.data}
|
dataSource={store.subcategory.data}
|
||||||
bordered
|
bordered
|
||||||
pagination={{
|
pagination={{
|
||||||
pageSize: store.product.pageSize,
|
pageSize: store.subcategory.pageSize,
|
||||||
total: store.product.total_data,
|
total: store.subcategory.total_data,
|
||||||
current: store.product.page + 1,
|
current: store.subcategory.page + 1,
|
||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
simple: false,
|
simple: false,
|
||||||
}}
|
}}
|
||||||
onChange={(page) => {
|
onChange={(page) => {
|
||||||
let pageNumber = page.current;
|
let pageNumber = page.current;
|
||||||
store.product.pageSize = page.pageSize;
|
store.subcategory.pageSize = page.pageSize;
|
||||||
store.product.page = pageNumber - 1;
|
store.subcategory.page = pageNumber - 1;
|
||||||
// store.membership.isLoading = true;
|
// store.membership.isLoading = true;
|
||||||
getData();
|
getData();
|
||||||
// store.membership.isLoading = false;
|
// store.membership.isLoading = false;
|
||||||
|
|
|
@ -18,7 +18,6 @@ export const Category = observer(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
//await store.product.getDataCategories();
|
|
||||||
await store.category.getData();
|
await store.category.getData();
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -29,11 +28,6 @@ export const Category = observer(() => {
|
||||||
init();
|
init();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleChangeTabPane = async (key) => {
|
|
||||||
store.product.filterCategory = key;
|
|
||||||
console.log(key);
|
|
||||||
};
|
|
||||||
|
|
||||||
const routeData = [
|
const routeData = [
|
||||||
{
|
{
|
||||||
route: LINKS.HOME,
|
route: LINKS.HOME,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
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} from "antd";
|
||||||
import { FilterOutlined, PlusSquareOutlined } from "@ant-design/icons";
|
import {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";
|
||||||
|
@ -17,7 +17,7 @@ export const Subcategory = observer(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
// await getData();
|
getData();
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
@ -31,6 +31,7 @@ export const Subcategory = observer(() => {
|
||||||
await store.category.getData();
|
await store.category.getData();
|
||||||
await store.subcategory.getData();
|
await store.subcategory.getData();
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeData = [
|
const routeData = [
|
||||||
{
|
{
|
||||||
route: LINKS.HOME,
|
route: LINKS.HOME,
|
||||||
|
|
|
@ -7,7 +7,6 @@ export class Product {
|
||||||
data = [];
|
data = [];
|
||||||
total_data = 0;
|
total_data = 0;
|
||||||
filterSupplier = null;
|
filterSupplier = null;
|
||||||
filterCategory = null;
|
|
||||||
filterSubCategory = null;
|
filterSubCategory = null;
|
||||||
visibleModalProduct = false;
|
visibleModalProduct = false;
|
||||||
visibleModalFilterProduct = false;
|
visibleModalFilterProduct = false;
|
||||||
|
@ -31,7 +30,7 @@ export class Product {
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
try {
|
try {
|
||||||
const response = await http.get(`/product/all?supplier=${this.filterSupplier}&category=${this.filterCategory}&sub-category=${this.filterSubCategory}&page=${this.page}&pageSize=${this.pageSize}`);
|
const response = await http.get(`/product/all?supplier=${this.filterSupplier}&sub-category=${this.filterSubCategory}&page=${this.page}&pageSize=${this.pageSize}`);
|
||||||
this.data = response.body.data.map((item, idx) => {
|
this.data = response.body.data.map((item, idx) => {
|
||||||
item.key = idx;
|
item.key = idx;
|
||||||
return item
|
return item
|
||||||
|
|
Loading…
Reference in New Issue
Block a user