From 7b1c6e1361fcc93729c250db29e828d6d07ca387 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Thu, 27 Mar 2025 21:06:25 -0500 Subject: [PATCH] refactor(ocp): finished the dashboard and move logs and labels to a tab style --- .../components/production/ocp/LabelLog.tsx | 5 +- .../src/components/production/ocp/Lots.tsx | 6 +- .../ocp/ManualPrinting/ManualPrintForm.tsx | 203 +++++++++++------- .../ocp/ManualPrinting/ManualPrintLabel.ts | 10 +- .../src/components/production/ocp/OcpLogs.tsx | 153 ++++++++++++- .../src/components/production/ocp/OcpPage.tsx | 27 ++- .../src/utils/querys/production/labels.tsx | 2 +- frontend/src/utils/querys/production/lots.tsx | 2 +- .../src/utils/querys/production/ocpLogs.tsx | 22 ++ 9 files changed, 329 insertions(+), 101 deletions(-) create mode 100644 frontend/src/utils/querys/production/ocpLogs.tsx diff --git a/frontend/src/components/production/ocp/LabelLog.tsx b/frontend/src/components/production/ocp/LabelLog.tsx index b891d7c..f8efbc1 100644 --- a/frontend/src/components/production/ocp/LabelLog.tsx +++ b/frontend/src/components/production/ocp/LabelLog.tsx @@ -125,7 +125,10 @@ export default function LabelLog() { {label.runningNr} - {format(label.upd_date, "M/d/yyyy hh:mm")} + {format( + label?.upd_date.replace("Z", ""), + "M/d/yyyy hh:mm" + )} {label.status} diff --git a/frontend/src/components/production/ocp/Lots.tsx b/frontend/src/components/production/ocp/Lots.tsx index 83bdd7c..fcff5fd 100644 --- a/frontend/src/components/production/ocp/Lots.tsx +++ b/frontend/src/components/production/ocp/Lots.tsx @@ -70,8 +70,6 @@ export default function Lots() { const { settings } = useSettingStore(); const server = settings.filter((n) => n.name === "server")[0]?.value || ""; - console.log(data); - const roles = ["admin", "manager", "operator"]; if (user && roles.includes(user.role)) { @@ -234,9 +232,7 @@ export default function Lots() { server === "localhost" ? ( <> - + ) : ( diff --git a/frontend/src/components/production/ocp/ManualPrinting/ManualPrintForm.tsx b/frontend/src/components/production/ocp/ManualPrinting/ManualPrintForm.tsx index 2336302..bbff004 100644 --- a/frontend/src/components/production/ocp/ManualPrinting/ManualPrintForm.tsx +++ b/frontend/src/components/production/ocp/ManualPrinting/ManualPrintForm.tsx @@ -1,4 +1,4 @@ -import {Button} from "@/components/ui/button"; +import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, @@ -8,8 +8,8 @@ import { DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; -import {Input} from "@/components/ui/input"; -import {Label} from "@/components/ui/label"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; import { Select, SelectContent, @@ -19,81 +19,81 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import {Textarea} from "@/components/ui/textarea"; -import {useSessionStore} from "@/lib/store/sessionStore"; -import {useSettingStore} from "@/lib/store/useSettings"; -import {LotType} from "@/types/lots"; +import { Textarea } from "@/components/ui/textarea"; +import { useSettingStore } from "@/lib/store/useSettings"; import axios from "axios"; -import {Tag} from "lucide-react"; -import {useState} from "react"; -import {Controller, useForm} from "react-hook-form"; -import {toast} from "sonner"; -import {manualPrintLabels} from "./ManualPrintLabel"; +import { Tag } from "lucide-react"; +import { useState } from "react"; +import { Controller, useForm } from "react-hook-form"; +import { toast } from "sonner"; const printReason = [ - {key: "printerIssue", label: "Printer Related"}, - {key: "strapper", label: "Strapper Error"}, - {key: "manualCheck", label: "20th pallet check"}, - {key: "outOfSync", label: "Labeler Out of Sync"}, + { key: "printerIssue", label: "Printer Related" }, + { key: "missingRfidTag", label: "Missing or incorrect tag" }, + { key: "strapper", label: "Strapper Error" }, + { key: "manualCheck", label: "20th pallet check" }, + { key: "outOfSync", label: "Labeler Out of Sync" }, ]; -export default function ManualPrintForm({lot}: {lot: LotType}) { - const {user} = useSessionStore(); +export default function ManualPrintForm() { const token = localStorage.getItem("auth_token"); - const {settings} = useSettingStore(); + const { settings } = useSettingStore(); const [open, setOpen] = useState(false); const server = settings.filter((n) => n.name === "server")[0]?.value; // const serverPort = settings.filter((n) => n.name === "serverPort")[0]?.value; // const serverUrl = `http://${server}:${serverPort}`; + + // what is the dyco set to? rfid or dyco + const dyco = settings.filter((n) => n.name === "dycoPrint"); const { register, handleSubmit, //watch, - formState: {errors}, + formState: { errors }, reset, control, } = useForm(); - const handlePrintLabel = async (lot: LotType) => { - //console.log(lot); - const labels: any = await manualPrintLabels(lot, user); - - if (labels.success) { - toast.success(labels.message); - } else { - toast.error(labels.message); - } - }; - - const handleManualPrintLog = async (logData: any, lot: LotType) => { + const handleManualPrintLog = async (logData: any) => { // toast.success(`A new label was sent to printer: ${lot.PrinterName} for line ${lot.MachineDescription} `); - const logdataUrl = `/api/ocp/manualLabelLog`; + const logdataUrl = `/api/ocp/manuallabellog`; axios - .post(logdataUrl, logData, {headers: {Authorization: `Bearer ${token}`}}) - .then((d) => { - //console.log(d); - toast.success(d.data.message); - handlePrintLabel(lot); - reset(); - }) - .catch((e) => { - if (e.response.status === 500) { - toast.error(`Internal Server error please try again.`); - return {sucess: false}; - } + .post(logdataUrl, logData, { + headers: { Authorization: `Bearer ${token}` }, + }) + .then((d) => { + console.log(d); + if (d.data.success) { + toast.success(d.data.message); + } else { + toast.error(d.data.message); + } + reset(); + setOpen(false); + }) + .catch((e) => { + if (e.response.status === 500) { + toast.error(`Internal Server error please try again.`); + return { sucess: false }; + } - if (e.response.status === 401) { - //console.log(e.response); - toast.error(`You are not authorized to do this.`); - return {sucess: false}; - } - }); + if (e.response.status === 401) { + //console.log(e.response); + toast.error(`You are not authorized to do this.`); + return { sucess: false }; + } + }); }; const onSubmit = (data: any) => { - console.log(data); + //console.log(data); - handleManualPrintLog(data, lot); + handleManualPrintLog(data); + }; + + const closeForm = () => { + reset(); + setOpen(false); }; return ( Edit profile - Make changes to your profile here. Click save when you're done. + Make changes to your profile here. Click save when + you're done.

- To manually print a label you must complete all the required fields below. + To manually print a label you must complete all the + required fields below.
If you clicked this in error just click close

@@ -133,7 +135,7 @@ export default function ManualPrintForm({lot}: {lot: LotType}) { name="printReason" defaultValue={""} render={({ - field: {onChange}, + field: { onChange }, fieldState: {}, //formState, }) => ( @@ -143,35 +145,46 @@ export default function ManualPrintForm({lot}: {lot: LotType}) { - Print Reasons - {printReason.map((printReason: any) => ( - {printReason.label} - ))} + + Print Reasons + + {printReason.map( + (printReason: any) => ( + + {printReason.label} + + ) + )} )} /> ) : ( -
+
)} -
+
@@ -180,11 +193,11 @@ export default function ManualPrintForm({lot}: {lot: LotType}) { type="number" className={errors.line ? "border-red-500" : ""} aria-invalid={!!errors.line} - {...register("line", {required: true})} + {...register("line", { required: true })} />
-
+
@@ -192,23 +205,55 @@ export default function ManualPrintForm({lot}: {lot: LotType}) { //variant="underlined" //label="Enter intials" - {...register("initials", {required: true})} + {...register("initials", { required: true })} + /> +
+
+ {dyco[0].value === "0" && ( +
+

Enter the missing tag number.

+
+ + +
+ )} +
+