mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2025-05-12 09:31:07 +08:00
Made current session stats widget in dashboard functional
This commit is contained in:
parent
fd7891359c
commit
6619163abe
5 changed files with 60 additions and 3 deletions
|
@ -5,10 +5,16 @@ import IsNumber from "../IsNumber/IsNumber";
|
|||
import { UpdateProduct } from "../../Api/Api";
|
||||
import { useQueryClient, useMutation } from "react-query";
|
||||
import { Product } from "../../../Interfaces/Interfaces";
|
||||
import { useDispatch } from "react-redux";
|
||||
import {
|
||||
this_session_increment_removed,
|
||||
this_session_increment_added,
|
||||
} from "../../../Features/Redux/Slices/TransactionsThisSessionSlice/TransactionsThisSessionSlice";
|
||||
|
||||
export default function StockRenderer(product: Product) {
|
||||
const [stock, setStock] = useState(product.quantity);
|
||||
const [valueChanged, setValueChanged] = useState(false);
|
||||
const dispatch = useDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: UpdateProduct,
|
||||
|
@ -23,6 +29,15 @@ export default function StockRenderer(product: Product) {
|
|||
name: product.name,
|
||||
quantity: stock,
|
||||
});
|
||||
if (stock > product.quantity) {
|
||||
dispatch(
|
||||
this_session_increment_added(Math.abs(stock - product.quantity))
|
||||
);
|
||||
} else {
|
||||
dispatch(
|
||||
this_session_increment_removed(Math.abs(stock - product.quantity))
|
||||
);
|
||||
}
|
||||
setValueChanged(false);
|
||||
}
|
||||
useEffect(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue