Simplified logs page and fixed session stats tracking

This commit is contained in:
Keannu Christian Bernasol 2023-03-07 22:11:03 +08:00
parent 3b5fb87099
commit 7fa1ddcd3a
5 changed files with 28 additions and 106 deletions

View file

@ -30,9 +30,7 @@ export default function StockRenderer(product: Product) {
quantity: stock,
});
if (stock > product.quantity) {
dispatch(
this_session_increment_added(Math.abs(stock - product.quantity))
);
dispatch(this_session_increment_added(stock - product.quantity));
} else {
dispatch(
this_session_increment_removed(Math.abs(stock - product.quantity))

View file

@ -1,99 +0,0 @@
import * as React from "react";
import {
OldSessionState,
ProductLogEntry,
} from "../../../Interfaces/Interfaces";
import styles from "../../../styles";
import { TableBody, TableRow, TableCell } from "@mui/material";
import { GetProduct, QueryUser } from "../../Api/Api";
import { useState } from "react";
import { useSelector } from "react-redux";
import { useQuery } from "react-query";
export default function RowRenderer(props: ProductLogEntry) {
const old_session_checked = useSelector(
(state: OldSessionState) => state.old_session_checked.value
);
const {
data: user,
isLoading,
error,
} = useQuery({
queryKey: ["user_select_id_" + props.Product.id, props.Product.id],
queryFn: () => QueryUser(props.Product.id),
});
if (isLoading || !old_session_checked) {
<TableRow
key={props.Product.id}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.name}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.quantity}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
Loading...
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_date}
</TableCell>
</TableRow>;
} else if (error) {
<TableRow
key={props.Product.id}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.name}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.quantity}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
Loading...
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_date}
</TableCell>
</TableRow>;
}
return (
<TableRow
key={props.Product.id}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.name}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.quantity}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{isLoading || user.username}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{props.Product.history_date}
</TableCell>
</TableRow>
);
}