import { useQuery } from "@tanstack/react-query"; import { useNavigate, useRouterState } from "@tanstack/react-router"; import { createColumnHelper } from "@tanstack/react-table"; import axios from "axios"; import { ArrowDown, ArrowUp } from "lucide-react"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useAuth, userAccess } from "@/lib/authClient"; import TableNoExpand from "@/lib/tableStuff/TableNoExpand"; import { getPallets } from "../../-utils/querys/quality/getPallets"; type Pallets = { request_id: string; article: string; description: string; runningNr: string; lotNr: string; warehouseAtRequest: string; locationAtRequest: string; warehouseMovedTo: string; locationMovedTo: string; durationToMove: null; qualityDurationToInspect: number; returnDurationToInspect: number; locationDropOff: string; palletStatus: number; palletStatusText: string; palletRequest: number; priority: number; add_date: Date; add_user: string; upd_date: Date; upd_user: string; }; export default function QualityRequest() { const { data, isLoading, refetch } = useQuery(getPallets()); const columnHelper = createColumnHelper(); const { session } = useAuth(); const navigate = useNavigate(); const router = useRouterState(); const currentPath = router.location.href; const palletCompleted = async (e: any) => { if (!session || !session.user) { toast.error("You are allowed to do this unless you are logged in"); navigate({ to: "/login", search: { redirect: currentPath } }); return; } const data = { username: session?.user.username, runningNr: Number(e.original.runningNr), palletStatusText: "return", }; try { const res = await axios.post("/lst/old/api/quality/newrequest", data); //console.log(res.data); if (res.data.success) { toast.success(res.data.message); refetch(); } if (!res.data.success) { toast.error(res.data.message); } } catch (error) { console.log(error); toast.error("Encountered and error please try again"); } }; const columns = [ columnHelper.accessor("article", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("description", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("runningNr", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("lotNr", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("locationAtRequest", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("locationDropOff", { header: ({ column }) => { return ( ); }, cell: ({ getValue }) => { return ( <> {getValue() ? getValue() : "missing dropoff location"} ); }, }), columnHelper.accessor("palletStatusText", { header: ({ column }) => { return ( ); }, }), columnHelper.accessor("palletRequest", { header: ({ column }) => { return ( ); }, cell: ({ row }) => { // if pending const okToCompleteStats = [2, 4, 5]; return ( <> {okToCompleteStats.includes(row.original.palletStatus) ? ( ) : ( Pending to be completed )} ); }, }), ]; let adminColumns: any = []; if (userAccess("quality", ["systemAdmin", "admin", "supervisor"])) { adminColumns = [ ...columns, columnHelper.accessor("priority", { header: ({ column }) => { return ( ); }, cell: ({ row, getValue }) => { // if pending const [p, setP] = useState(`${getValue()}`); console.log(getValue()); return ( <> ); }, }), ]; } if (isLoading) { return
Loading user data
; } return ; }