From 796a8dccd2807890abdff7c8dacf8b2246eb265e Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sat, 6 Sep 2025 09:00:46 -0500 Subject: [PATCH] refactor(silo card): changes to allow viewers to see and able to attach and detach --- .../logistics/siloAdjustments/SiloCard.tsx | 185 +++++++++++------- 1 file changed, 109 insertions(+), 76 deletions(-) diff --git a/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx b/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx index 67b4b63..1b788f1 100644 --- a/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx +++ b/frontend/src/components/logistics/siloAdjustments/SiloCard.tsx @@ -21,13 +21,28 @@ import { toast } from "sonner"; import ChartData from "./ChartData"; import { AttachSilo } from "./AttachSilo"; import { DetachSilo } from "./DetachSilo"; +import { useSessionStore } from "@/lib/store/sessionStore"; +import { useModuleStore } from "@/lib/store/useModuleStore"; +import { useGetUserRoles } from "@/lib/store/useGetRoles"; export default function SiloCard(data: any) { const token = localStorage.getItem("auth_token"); const [submitting, setSubmitting] = useState(false); const { refetch } = useQuery(getStockSilo()); + const { user } = useSessionStore(); + const { userRoles } = useGetUserRoles(); + const { modules } = useModuleStore(); const silo = data.silo; + // roles that can do the silo adjustments + const roles = ["systemAdmin", "technician", "admin", "manager"]; + + const module = modules.filter((n) => n.name === "logistics"); + + const accessRoles = userRoles.filter( + (n) => n.module_id === module[0]?.module_id + ) as any; + const form = useForm({ defaultValues: { newLevel: "", @@ -46,7 +61,7 @@ export default function SiloCard(data: any) { dataToSubmit, { headers: { Authorization: `Bearer ${token}` } } ); - console.log(res.data); + //console.log(res.data); if (res.data.success) { toast.success(res.data.message); @@ -70,6 +85,8 @@ export default function SiloCard(data: any) { } }, }); + + console.log(accessRoles); return (
@@ -109,82 +126,98 @@ export default function SiloCard(data: any) {
) : ( -
{ - e.preventDefault(); - e.stopPropagation(); - }} - > - - value.length > 1 - ? undefined - : "You must enter a value greate than 1", - }} - children={(field) => { - return ( -
-
- -
- -
-
-
- - field.handleChange( - e.target.value - ) - } - /> - -
+ <> + {user && + roles.includes(accessRoles[0]?.role) && ( + { + e.preventDefault(); + e.stopPropagation(); + }} + > + + value.length > 1 + ? undefined + : "You must enter a value greate than 1", + }} + children={(field) => { + return ( +
+
+ +
+ +
+
+
+ + field.handleChange( + e + .target + .value + ) + } + /> + +
- {field.state.meta.errors - .length ? ( - - {field.state.meta.errors.join( - "," - )} - - ) : null} -
- ); - }} - /> - + {field.state.meta + .errors + .length ? ( + + {field.state.meta.errors.join( + "," + )} + + ) : null} +
+ ); + }} + /> + + )} + )}