Cleaned up new delete/new product query refresh and added search to products page

This commit is contained in:
keannu125 2023-03-09 17:05:15 +08:00
parent c51c36c367
commit 46ddb25709
3 changed files with 73 additions and 6 deletions

View file

@ -10,6 +10,7 @@ export interface props {}
export default function ViewManager(props: ProductList) { export default function ViewManager(props: ProductList) {
const [tableView, toggleTableView] = useState(true); const [tableView, toggleTableView] = useState(true);
const [searchTerm, setSearchTerm] = useState("");
if (props.Products.length === 0) { if (props.Products.length === 0) {
return ( return (
<div style={{ ...styles.content_column, ...{ alignItems: "center" } }}> <div style={{ ...styles.content_column, ...{ alignItems: "center" } }}>
@ -22,15 +23,81 @@ export default function ViewManager(props: ProductList) {
if (tableView) { if (tableView) {
return ( return (
<div> <div>
<Switch onClick={() => toggleTableView(!tableView)} /> <div style={styles.content_row}>
<TableView Products={props.Products} /> <Switch
style={{ flex: 1 }}
onClick={() => toggleTableView(!tableView)}
/>
<div style={{ flex: 8 }} />
<div
style={{
...styles.content_row,
...{ flex: 1, justifyContent: "flex-end" },
}}
>
<p style={{ ...styles.text_white, ...styles.text_S }}>
Search&nbsp;
</p>
<input
style={{
...{
flex: 5,
height: "2rem",
},
...styles.text_S,
}}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(e.target.value);
}}
maxLength={20}
/>
</div>
</div>
<TableView
Products={props.Products.filter((Product) =>
Product.name.toLowerCase().includes(searchTerm)
)}
/>
</div> </div>
); );
} else { } else {
return ( return (
<div> <div>
<Switch onClick={() => toggleTableView(!tableView)} /> <div style={styles.content_row}>
<BlobView Products={props.Products} /> <Switch
style={{ flex: 1 }}
onClick={() => toggleTableView(!tableView)}
/>
<div style={{ flex: 8 }} />
<div
style={{
...styles.content_row,
...{ flex: 1, justifyContent: "flex-end" },
}}
>
<p style={{ ...styles.text_white, ...styles.text_S }}>
Search&nbsp;
</p>
<input
style={{
...{
flex: 5,
height: "2rem",
},
...styles.text_S,
}}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(e.target.value);
}}
maxLength={20}
/>
</div>
</div>
<BlobView
Products={props.Products.filter((Product) =>
Product.name.toLowerCase().includes(searchTerm)
)}
/>
</div> </div>
); );
} }

View file

@ -14,7 +14,7 @@ export default function NewProduct() {
mutationFn: AddProduct, mutationFn: AddProduct,
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries("products"); queryClient.invalidateQueries("products");
queryClient.invalidateQueries("logs"); queryClient.invalidateQueries("product");
queryClient.invalidateQueries("logs"); queryClient.invalidateQueries("logs");
}, },
}); });

View file

@ -1,4 +1,4 @@
import React from "react"; import React, { useState } from "react";
import styles from "../../styles"; import styles from "../../styles";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import ProductsIcon from "../../Components/Icons/ProductsIcon/ProductsIcon"; import ProductsIcon from "../../Components/Icons/ProductsIcon/ProductsIcon";