feat: handler modal dynamic
This commit is contained in:
parent
7edf7650ec
commit
7cf403f19d
|
@ -15,9 +15,8 @@ export const ProductComponent = observer((props) => {
|
|||
const {Option} = Select;
|
||||
const history = useHistory();
|
||||
const [idData, setIdData] = useState("");
|
||||
const [filterSupplier, setFilterSupplier] = useState(null);
|
||||
const [filterCategories, setFilterCategories] = useState(null);
|
||||
const [filterSubCategories, setFilterSubCategories] = useState(null);
|
||||
const [filterSupplier, setFilterSupplier] = useState([]);
|
||||
const [filterSubCategories, setFilterSubCategories] = useState([]);
|
||||
const modalLoader = useContext(ModalLoaderContext);
|
||||
|
||||
const handleEditButton = (data) => {
|
||||
|
@ -163,17 +162,17 @@ export const ProductComponent = observer((props) => {
|
|||
const handleRemoveFilter = async () => {
|
||||
store.product.filterSupplier = null;
|
||||
store.product.filterSubCategory = null;
|
||||
setFilterSupplier(null);
|
||||
setFilterCategories(null);
|
||||
setFilterSubCategories(null);
|
||||
setFilterSupplier([]);
|
||||
store.product.filterCategory = null;
|
||||
setFilterSubCategories([]);
|
||||
await store.product.getData();
|
||||
store.product.visibleModalFilterProduct = false;
|
||||
};
|
||||
|
||||
const handleCancelFilter = () => {
|
||||
setFilterSupplier(null);
|
||||
setFilterCategories(null);
|
||||
setFilterSubCategories(null);
|
||||
setFilterSupplier([]);
|
||||
store.product.filterCategory = null;
|
||||
setFilterSubCategories([]);
|
||||
store.product.visibleModalFilterProduct = false;
|
||||
};
|
||||
|
||||
|
@ -186,14 +185,24 @@ export const ProductComponent = observer((props) => {
|
|||
store.product.visibleModalFilterProduct = false;
|
||||
};
|
||||
|
||||
const handleFilterCategory = async (value) => {
|
||||
if (value) {
|
||||
store.product.filterCategory = value;
|
||||
await store.product.getDataSubCategories();
|
||||
} else {
|
||||
store.product.filterCategory = null;
|
||||
await store.product.getDataSubCategories();
|
||||
}
|
||||
};
|
||||
|
||||
const footerLayoutFilter = [
|
||||
<Button
|
||||
key={"remove"}
|
||||
onClick={handleRemoveFilter}
|
||||
style={{
|
||||
backgroundColor: "#e74e5e",
|
||||
color: "#fff",
|
||||
}}
|
||||
key={"remove"}
|
||||
onClick={handleRemoveFilter}
|
||||
style={{
|
||||
backgroundColor: "#e74e5e",
|
||||
color: "#fff",
|
||||
}}
|
||||
>
|
||||
Remove Filter
|
||||
</Button>,
|
||||
|
@ -403,17 +412,18 @@ export const ProductComponent = observer((props) => {
|
|||
Filter Supplier
|
||||
</Title>
|
||||
<Select
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Supplier"
|
||||
onChange={(val) => {
|
||||
setFilterSupplier(val);
|
||||
}}
|
||||
style={{ marginBottom: "20px", width: "100%" }}
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Supplier"
|
||||
onChange={(val) => {
|
||||
setFilterSupplier(val);
|
||||
}}
|
||||
style={{marginBottom: "20px", width: "100%"}}
|
||||
value={filterSupplier}
|
||||
>
|
||||
{store.supplier.data.map((item) => (
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
|
@ -422,19 +432,16 @@ export const ProductComponent = observer((props) => {
|
|||
Filter Categories
|
||||
</Title>
|
||||
<Select
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Category"
|
||||
onChange={async (val) => {
|
||||
setFilterCategories(val);
|
||||
store.product.filterByCategory = val;
|
||||
await store.product.getDataSubCategories();
|
||||
}}
|
||||
style={{ marginBottom: "20px", width: "100%" }}
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Category"
|
||||
onChange={async (val) => handleFilterCategory(val)}
|
||||
style={{marginBottom: "20px", width: "100%"}}
|
||||
value={store.product.filterCategory || []}
|
||||
>
|
||||
{store.category.data.map((item) => (
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
|
@ -443,17 +450,18 @@ export const ProductComponent = observer((props) => {
|
|||
Filter Sub-Categories
|
||||
</Title>
|
||||
<Select
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Sub-Category"
|
||||
onChange={(val) => {
|
||||
setFilterSubCategories(val);
|
||||
}}
|
||||
style={{ marginBottom: "20px", width: "100%" }}
|
||||
mode={"multiple"}
|
||||
placeholder="Choose Sub-Category"
|
||||
onChange={(val) => {
|
||||
setFilterSubCategories(val);
|
||||
}}
|
||||
style={{marginBottom: "20px", width: "100%"}}
|
||||
value={filterSubCategories}
|
||||
>
|
||||
{store.product.dataSubCategories.map((item) => (
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
<Option value={item.id} key={item.id}>
|
||||
{item.name}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
|
|
|
@ -21,7 +21,7 @@ export const Product = observer(() => {
|
|||
await Promise.allSettled([
|
||||
store.supplier.getData(),
|
||||
store.category.getData(),
|
||||
store.category.getDataSubCategories(),
|
||||
store.product.getDataSubCategories(),
|
||||
]);
|
||||
await store.product.getData();
|
||||
modalLoader.setLoading(false);
|
||||
|
|
|
@ -21,7 +21,7 @@ export class Product {
|
|||
pageSizeSubCategories = 10
|
||||
dataSubCategories = [];
|
||||
total_dataSubCategories = 0;
|
||||
filterByCategory = null;
|
||||
filterCategory = null;
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
|
@ -44,7 +44,7 @@ export class Product {
|
|||
|
||||
async getDataSubCategories() {
|
||||
try {
|
||||
const response = await http.get(`/product/sub-categories?category=${this.filterByCategory}&page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
|
||||
const response = await http.get(`/product/sub-categories?category=${this.filterCategory}&page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
|
||||
this.dataSubCategories = response.body.data.map((item, idx) => {
|
||||
item.key = idx;
|
||||
return item
|
||||
|
|
Loading…
Reference in New Issue
Block a user