refactor(quality): added some new options plus cancel button
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
vars {
|
||||
url: http://localhost:4200
|
||||
session_cookie:
|
||||
urlv2: http://localhost:3000
|
||||
urlv2: http://usmcd1vms036:3000
|
||||
jwtV2:
|
||||
userID:
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ export type UserRoles = {
|
||||
| "supervisor"
|
||||
| "manager"
|
||||
| "admin"
|
||||
| "systemAdmin";
|
||||
| "systemAdmin"
|
||||
| "user";
|
||||
};
|
||||
|
||||
type UserRoleState = {
|
||||
|
||||
@@ -42,8 +42,8 @@ export default function TableNoExpand({
|
||||
});
|
||||
return (
|
||||
<div className="p-4">
|
||||
<ScrollArea className="w-11/12 rounded-md border whitespace-nowrap">
|
||||
<Table>
|
||||
<Table className="table-fixed w-full">
|
||||
<ScrollArea className="w-full rounded-md border whitespace-nowrap">
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
@@ -89,7 +89,10 @@ export default function TableNoExpand({
|
||||
</React.Fragment>
|
||||
))}
|
||||
</TableBody>
|
||||
<ScrollBar orientation="horizontal" />
|
||||
</ScrollArea>
|
||||
</Table>
|
||||
|
||||
<div className="flex items-center justify-end space-x-2 py-4">
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -108,8 +111,6 @@ export default function TableNoExpand({
|
||||
Next
|
||||
</Button>
|
||||
</div>
|
||||
<ScrollBar orientation="horizontal" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ 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 { ArrowDown, ArrowUp, Trash2 } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
@@ -30,7 +32,6 @@ type Pallets = {
|
||||
durationToMove: null;
|
||||
qualityDurationToInspect: number;
|
||||
returnDurationToInspect: number;
|
||||
locationMovesTo: string;
|
||||
locationDropOff: string;
|
||||
palletStatus: number;
|
||||
palletStatusText: string;
|
||||
@@ -40,6 +41,8 @@ type Pallets = {
|
||||
add_user: string;
|
||||
upd_date: Date;
|
||||
upd_user: string;
|
||||
palletComplete: string;
|
||||
canceled: string;
|
||||
};
|
||||
|
||||
export default function QualityRequest() {
|
||||
@@ -50,35 +53,35 @@ export default function QualityRequest() {
|
||||
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);
|
||||
// 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);
|
||||
// //console.log(res.data);
|
||||
|
||||
if (res.data.success) {
|
||||
toast.success(res.data.message);
|
||||
refetch();
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
};
|
||||
// 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", {
|
||||
@@ -166,14 +169,14 @@ export default function QualityRequest() {
|
||||
);
|
||||
},
|
||||
}),
|
||||
columnHelper.accessor("locationMovesTo", {
|
||||
columnHelper.accessor("locationMovedTo", {
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||
>
|
||||
<span className="flex flex-row gap-2">Location At Request</span>
|
||||
<span className="flex flex-row gap-2">Location Moved to</span>
|
||||
{column.getIsSorted() === "asc" ? (
|
||||
<ArrowUp className="ml-2 h-4 w-4" />
|
||||
) : (
|
||||
@@ -227,7 +230,7 @@ export default function QualityRequest() {
|
||||
);
|
||||
},
|
||||
}),
|
||||
columnHelper.accessor("palletRequest", {
|
||||
columnHelper.accessor("palletComplete", {
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
@@ -245,15 +248,78 @@ export default function QualityRequest() {
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
// if pending
|
||||
|
||||
//const [p, setP] = useState(`${getValue()}`);
|
||||
const okToCompleteStats = [2, 4, 5];
|
||||
return (
|
||||
<>
|
||||
{okToCompleteStats.includes(row.original.palletStatus) ? (
|
||||
<Button variant="outline" onClick={() => palletCompleted(row)}>
|
||||
Check Complete
|
||||
</Button>
|
||||
<Select
|
||||
//value={"return to warehouse"}
|
||||
onValueChange={async (value) => {
|
||||
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(row.original.runningNr),
|
||||
palletStatusText: value,
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger
|
||||
// className={cn(
|
||||
// "w-[100px]",
|
||||
// active
|
||||
// ? "border-green-500 text-green-600"
|
||||
// : "border-gray-400 text-gray-500",
|
||||
// )}
|
||||
>
|
||||
<SelectValue placeholder="Complete Selection" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectLabel>Location to drop off</SelectLabel>
|
||||
<SelectItem value="return to warehouse">
|
||||
Return to Warehouse
|
||||
</SelectItem>
|
||||
<SelectItem value="rework">Rework</SelectItem>
|
||||
<SelectItem value="grind">Grind</SelectItem>
|
||||
<SelectItem value="scrap">Scrap</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
) : (
|
||||
<span>Pending to be completed</span>
|
||||
<span>Pending move</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@@ -262,7 +328,9 @@ export default function QualityRequest() {
|
||||
];
|
||||
|
||||
let adminColumns: any = [];
|
||||
if (userAccess("quality", ["systemAdmin", "admin", "supervisor"])) {
|
||||
if (
|
||||
userAccess("quality", ["systemAdmin", "admin", "supervisor", "manager"])
|
||||
) {
|
||||
adminColumns = [
|
||||
...columns,
|
||||
columnHelper.accessor("priority", {
|
||||
@@ -287,7 +355,6 @@ export default function QualityRequest() {
|
||||
// if pending
|
||||
|
||||
const [p, setP] = useState(`${getValue()}`);
|
||||
console.log(getValue());
|
||||
return (
|
||||
<>
|
||||
<Select
|
||||
@@ -343,6 +410,78 @@ export default function QualityRequest() {
|
||||
);
|
||||
},
|
||||
}),
|
||||
columnHelper.accessor("palletComplete", {
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
column.toggleSorting(column.getIsSorted() === "asc")
|
||||
}
|
||||
>
|
||||
<span className="flex flex-row gap-2">Cancel</span>
|
||||
{column.getIsSorted() === "asc" ? (
|
||||
<ArrowUp className="ml-2 h-4 w-4" />
|
||||
) : (
|
||||
<ArrowDown className="ml-2 h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
//value={"return to warehouse"}
|
||||
variant="destructive"
|
||||
onClick={async () => {
|
||||
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(row.original.runningNr),
|
||||
palletStatusText: "canceled",
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"/lst/old/api/quality/newrequest",
|
||||
data,
|
||||
);
|
||||
|
||||
//console.log(res.data);
|
||||
|
||||
if (res.data.success) {
|
||||
toast.success(
|
||||
`${row.original.runningNr} was just canceled`,
|
||||
);
|
||||
refetch();
|
||||
}
|
||||
|
||||
if (!res.data.success) {
|
||||
toast.error(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
toast.error("Encountered and error please try again");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Trash2 className="w-[24px] h-[24px]" />
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
},
|
||||
}),
|
||||
];
|
||||
}
|
||||
if (isLoading) {
|
||||
|
||||
@@ -13,6 +13,7 @@ export const Route = createFileRoute("/_old/old/quality/")({
|
||||
"admin",
|
||||
"manager",
|
||||
"supervisor",
|
||||
"user",
|
||||
],
|
||||
moduleName: "quality", // optional
|
||||
});
|
||||
|
||||
@@ -13,6 +13,10 @@ export const addNewPallet = async (data: any) => {
|
||||
* Post new pallets
|
||||
*/
|
||||
|
||||
const returnLabels = ["return to warehouse", "rework", "grind", "scrap"];
|
||||
|
||||
console.log(data, returnLabels.includes(data.palletStatusText));
|
||||
|
||||
if (parseInt(data.runningNr) <= 0) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -40,7 +44,7 @@ export const addNewPallet = async (data: any) => {
|
||||
const palletData: any = c;
|
||||
// if the pallet exist then tell the user to check on it
|
||||
const pStatus = [1, 4, 6];
|
||||
if (!data.priority) {
|
||||
if (!data.priority && data.palletStatusText !== "canceled") {
|
||||
if (palletData && pStatus.includes(palletData[0]?.palletStatus)) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -73,22 +77,39 @@ export const addNewPallet = async (data: any) => {
|
||||
upd_user: data.user,
|
||||
upd_date: sql`NOW()`,
|
||||
};
|
||||
} else {
|
||||
} else if (data.palletStatusText === "canceled") {
|
||||
pData = {
|
||||
warehouseAtRequest: p[0].warehouseAtRequest,
|
||||
locationAtRequest: p[0].locationAtRequest,
|
||||
warehouseAtRequest: null,
|
||||
locationAtRequest: null,
|
||||
warehouseMovedTo: null,
|
||||
locationMovedTo: null,
|
||||
palletStatus: data.palletStatusText === "return" ? 6 : 4,
|
||||
palletStatus: 5,
|
||||
//durationToMove: 0,
|
||||
palletStatusText:
|
||||
data.palletStatusText === "return" ? "return" : "reactivated",
|
||||
qualityDurationToInspect:
|
||||
data.palletStatusText === "return"
|
||||
palletStatusText: "canceled",
|
||||
qualityDurationToInspect: 0,
|
||||
locationDropOff: "canceled",
|
||||
palletRequest: palletData[0].palletStatus + 1,
|
||||
upd_user: data.user,
|
||||
upd_date: sql`NOW()`,
|
||||
};
|
||||
} else {
|
||||
pData = {
|
||||
warehouseAtRequest: p[0].warehouseAtRequest || "no longer on stock",
|
||||
locationAtRequest: p[0].locationAtRequest || "no longer on stock",
|
||||
warehouseMovedTo: null,
|
||||
locationMovedTo: null,
|
||||
palletStatus: returnLabels.includes(data.palletStatusText) ? 6 : 4,
|
||||
//durationToMove: 0,
|
||||
palletStatusText: returnLabels.includes(data.palletStatusText)
|
||||
? data.palletStatusText
|
||||
: "reactivated",
|
||||
|
||||
qualityDurationToInspect: returnLabels.includes(data.palletStatusText)
|
||||
? differenceInMinutes(new Date(Date.now()), p[0].lastMove)
|
||||
: 0,
|
||||
locationDropOff:
|
||||
data.palletStatusText === "return" ? "Return to warhouse" : "",
|
||||
locationDropOff: returnLabels.includes(data.palletStatusText)
|
||||
? data.palletStatusText
|
||||
: "No location Checked",
|
||||
palletRequest: palletData[0].palletStatus + 1,
|
||||
upd_user: data.user,
|
||||
upd_date: sql`NOW()`,
|
||||
|
||||
@@ -71,21 +71,21 @@ export const qualityCycle = async () => {
|
||||
const qDataPost = {
|
||||
warehouseMovedTo: prodData[0]?.warehouseAtRequest,
|
||||
locationMovedTo: prodData[0]?.locationAtRequest,
|
||||
// how ling did it take the warhouse to originally move the pallet
|
||||
// how ling did it take the warehouse to originally move the pallet
|
||||
durationToMove: warehouse.includes(lstQData[i].palletStatus)
|
||||
? differenceInMinutes(
|
||||
new Date(Date.now()),
|
||||
lstQData[i].upd_date,
|
||||
)
|
||||
: lstQData[i].durationToMove,
|
||||
// how long did it take warehouse to move the pallet back agian
|
||||
// how long did it take warehouse to move the pallet back again
|
||||
returnDurationToInspect:
|
||||
lstQData[i].palletStatus === 7
|
||||
? differenceInMinutes(
|
||||
new Date(Date.now()),
|
||||
lstQData[i].upd_date,
|
||||
)
|
||||
: lstQData[i].qualityDurationToInspect,
|
||||
: lstQData[i].returnDurationToInspect,
|
||||
palletStatus: 2,
|
||||
palletStatusText: "moved",
|
||||
upd_date: sql`NOW()`,
|
||||
|
||||
Reference in New Issue
Block a user