refactor(rfid): ratio resets implemeneted
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
//import { fixTime } from "@/utils/fixTime";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getReaders } from "@/utils/querys/rfid/getReaders";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns-tz";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
// This type is used to define the shape of our data.
|
||||
// You can use a Zod schema here if you want.
|
||||
@@ -94,4 +100,49 @@ export const readerColumns: ColumnDef<Readers>[] = [
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "reset",
|
||||
header: "Reset Reads",
|
||||
cell: ({ row }) => {
|
||||
const { refetch } = useQuery(getReaders());
|
||||
const [readerReset, setReaderReset] = useState(false);
|
||||
// const goodRatio =
|
||||
// (parseInt(row.getValue("goodReads")) /
|
||||
// (parseInt(row.getValue("goodReads")) +
|
||||
// parseInt(row.getValue("badReads")))) *
|
||||
// 100;
|
||||
const name = row.getValue("reader");
|
||||
const resetReads = async () => {
|
||||
setReaderReset(true);
|
||||
try {
|
||||
const res = await axios.post("/api/rfid/resetRatio", {
|
||||
reader: name,
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
toast.success(res.data.message);
|
||||
setReaderReset(false);
|
||||
} else {
|
||||
toast.error(res.data.message);
|
||||
setReaderReset(false);
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.error(error.data.message);
|
||||
setReaderReset(false);
|
||||
}
|
||||
refetch();
|
||||
};
|
||||
return (
|
||||
<div className="text-left font-medium">
|
||||
<Button
|
||||
className="h-4"
|
||||
onClick={resetReads}
|
||||
disabled={readerReset}
|
||||
>
|
||||
Reset Reads
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user