Simplified logs page and fixed session stats tracking

This commit is contained in:
keannu125 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, quantity: stock,
}); });
if (stock > product.quantity) { if (stock > product.quantity) {
dispatch( dispatch(this_session_increment_added(stock - product.quantity));
this_session_increment_added(Math.abs(stock - product.quantity))
);
} else { } else {
dispatch( dispatch(
this_session_increment_removed(Math.abs(stock - product.quantity)) 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>
);
}

View file

@ -8,10 +8,10 @@ export const TransactionsThisSessionSlice = createSlice({
}, },
reducers: { reducers: {
this_session_increment_added: (state, action) => { this_session_increment_added: (state, action) => {
state.added = action.payload; state.added += action.payload;
}, },
this_session_increment_removed: (state, action) => { this_session_increment_removed: (state, action) => {
state.removed = action.payload; state.removed += action.payload;
}, },
}, },
}); });

View file

@ -21,6 +21,7 @@ export interface ProductLogEntry {
quantity: string; quantity: string;
history_date: string; history_date: string;
history_user_id: number; history_user_id: number;
changed_by: string;
}; };
} }
@ -31,6 +32,7 @@ export interface ProductLog {
quantity: string; quantity: string;
history_date: string; history_date: string;
history_user_id: number; history_user_id: number;
changed_by: string;
} }
// Redux Interfaces // Redux Interfaces

View file

@ -15,7 +15,6 @@ import { useQuery } from "react-query";
import { GetLogs, UserInfo } from "../../Components/Api/Api"; import { GetLogs, UserInfo } from "../../Components/Api/Api";
import { OldSessionState, ProductLog } from "../../Interfaces/Interfaces"; import { OldSessionState, ProductLog } from "../../Interfaces/Interfaces";
import { useState } from "react"; import { useState } from "react";
import RowRenderer from "../../Components/LogsPage/RowRenderer/RowRenderer";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
export default function Logs() { export default function Logs() {
@ -92,7 +91,29 @@ export default function Logs() {
</TableHead> </TableHead>
<TableBody> <TableBody>
{logs.data.map((row: ProductLog, index: number) => ( {logs.data.map((row: ProductLog, index: number) => (
<RowRenderer key={index} Product={row} /> <TableRow
key={row.id}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.history_id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.id}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.name}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.quantity}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.changed_by}
</TableCell>
<TableCell style={{ ...styles.text_white, ...styles.text_S }}>
{row.history_date}
</TableCell>
</TableRow>
))} ))}
</TableBody> </TableBody>
</Table> </Table>