Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add job list and job detail view

Brad Barbin9c2d3df2a516
diff --git a/apps/carbon/app/assets/icons/AlmostDoneIcon.tsx b/apps/carbon/app/assets/icons/AlmostDoneIcon.tsx
index f03b54160f..921e44a27f 100644
--- a/apps/carbon/app/assets/icons/AlmostDoneIcon.tsx
+++ b/apps/carbon/app/assets/icons/AlmostDoneIcon.tsx
@@ -14,9 +14,9 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
r="6"
fill="none"
stroke="#26a544"
- stroke-width="2"
- stroke-dasharray="3.14 0"
- stroke-dashoffset="-0.7"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
></circle>
<circle
cx="7"
@@ -24,9 +24,9 @@ export function AlmostDoneIcon({ className }: { className?: string }) {
r="2"
fill="none"
stroke="#26a544"
- stroke-width="4"
- stroke-dasharray="9.377654070965532 100"
- stroke-dashoffset="0"
+ strokeWidth="4"
+ strokeDasharray="9.377654070965532 100"
+ strokeDashoffset="0"
transform="rotate(-90 7 7)"
></circle>
</svg>
diff --git a/apps/carbon/app/assets/icons/InProgressStatusIcon.tsx b/apps/carbon/app/assets/icons/InProgressStatusIcon.tsx
index 3063a28852..17b4632108 100644
--- a/apps/carbon/app/assets/icons/InProgressStatusIcon.tsx
+++ b/apps/carbon/app/assets/icons/InProgressStatusIcon.tsx
@@ -14,9 +14,9 @@ export function InProgressStatusIcon({ className }: { className?: string }) {
r="6"
fill="none"
stroke="#f2be00"
- stroke-width="2"
- stroke-dasharray="3.14 0"
- stroke-dashoffset="-0.7"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
></circle>
<circle
className="progress"
@@ -25,9 +25,9 @@ export function InProgressStatusIcon({ className }: { className?: string }) {
r="2"
fill="none"
stroke="#f2be00"
- stroke-width="4"
- stroke-dasharray="6.2517693806436885 100"
- stroke-dashoffset="0"
+ strokeWidth="4"
+ strokeDasharray="6.2517693806436885 100"
+ strokeDashoffset="0"
transform="rotate(-90 7 7)"
></circle>
</svg>
diff --git a/apps/carbon/app/assets/icons/LowPriorityIcon.tsx b/apps/carbon/app/assets/icons/LowPriorityIcon.tsx
index d91e4698c9..b05e94e861 100644
--- a/apps/carbon/app/assets/icons/LowPriorityIcon.tsx
+++ b/apps/carbon/app/assets/icons/LowPriorityIcon.tsx
@@ -11,14 +11,14 @@ export function LowPriorityIcon({ className }: { className?: string }) {
focusable="false"
>
<rect x="1.5" y="8" width="3" height="6" rx="1"></rect>
- <rect x="6.5" y="5" width="3" height="9" rx="1" fill-opacity="0.4"></rect>
+ <rect x="6.5" y="5" width="3" height="9" rx="1" fillOpacity="0.4"></rect>
<rect
x="11.5"
y="2"
width="3"
height="12"
rx="1"
- fill-opacity="0.4"
+ fillOpacity="0.4"
></rect>
</svg>
);
diff --git a/apps/carbon/app/assets/icons/MediumPriorityIcon.tsx b/apps/carbon/app/assets/icons/MediumPriorityIcon.tsx
index 2af03b2975..296884ae02 100644
--- a/apps/carbon/app/assets/icons/MediumPriorityIcon.tsx
+++ b/apps/carbon/app/assets/icons/MediumPriorityIcon.tsx
@@ -18,7 +18,7 @@ export function MediumPriorityIcon({ className }: { className?: string }) {
width="3"
height="12"
rx="1"
- fill-opacity="0.4"
+ fillOpacity="0.4"
></rect>
</svg>
);
diff --git a/apps/carbon/app/assets/icons/TodoStatusIcon.tsx b/apps/carbon/app/assets/icons/TodoStatusIcon.tsx
index 1b83430342..58458ad63c 100644
--- a/apps/carbon/app/assets/icons/TodoStatusIcon.tsx
+++ b/apps/carbon/app/assets/icons/TodoStatusIcon.tsx
@@ -14,9 +14,9 @@ export function TodoStatusIcon({ className }: { className?: string }) {
r="6"
fill="none"
stroke="#e2e2e2"
- stroke-width="2"
- stroke-dasharray="3.14 0"
- stroke-dashoffset="-0.7"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
></circle>
<circle
className="progress"
@@ -25,9 +25,9 @@ export function TodoStatusIcon({ className }: { className?: string }) {
r="2"
fill="none"
stroke="#e2e2e2"
- stroke-width="4"
- stroke-dasharray="0 100"
- stroke-dashoffset="0"
+ strokeWidth="4"
+ strokeDasharray="0 100"
+ strokeDashoffset="0"
transform="rotate(-90 7 7)"
></circle>
</svg>
diff --git a/apps/carbon/app/routes/x+/scheduling+/kanban.tsx b/apps/carbon/app/routes/x+/scheduling+/kanban.tsx
index c05db49c8f..209c1e6bc5 100644
--- a/apps/carbon/app/routes/x+/scheduling+/kanban.tsx
+++ b/apps/carbon/app/routes/x+/scheduling+/kanban.tsx
@@ -20,13 +20,13 @@ export async function loader({ request }: LoaderFunctionArgs) {
return typedjson({
columns: [
{
- id: getRandomBetweenRange(1, 2),
+ id: "1",
type: "assembly",
title: "Assembly Station 1",
active: true,
},
{
- id: getRandomBetweenRange(1, 2),
+ id: "2",
type: "assembly",
title: "Assembly Station 2",
},
@@ -282,7 +282,7 @@ export default function KanbanView() {
variant="secondary"
onClick={revalidator.revalidate}
>
- Reschedule
+ Rebalance
</Button>
</HStack>
</HStack>
diff --git a/apps/mes/package.json b/apps/mes/package.json
index b46458c652..eb972c1302 100644
--- a/apps/mes/package.json
+++ b/apps/mes/package.json
@@ -16,6 +16,7 @@
"@carbon/tsconfig": "*",
"@hookform/resolvers": "^3.4.2",
"@supabase/supabase-js": "^2.40.0",
+ "class-variance-authority": "0.7.0",
"localforage": "^1.10.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/apps/mes/src/assets/icons/AlmostDoneIcon.tsx b/apps/mes/src/assets/icons/AlmostDoneIcon.tsx
new file mode 100644
index 0000000000..921e44a27f
--- /dev/null
+++ b/apps/mes/src/assets/icons/AlmostDoneIcon.tsx
@@ -0,0 +1,34 @@
+export function AlmostDoneIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 14 14"
+ fill="none"
+ color="currentColor"
+ className={className}
+ >
+ <circle
+ cx="7"
+ cy="7"
+ r="6"
+ fill="none"
+ stroke="#26a544"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
+ ></circle>
+ <circle
+ cx="7"
+ cy="7"
+ r="2"
+ fill="none"
+ stroke="#26a544"
+ strokeWidth="4"
+ strokeDasharray="9.377654070965532 100"
+ strokeDashoffset="0"
+ transform="rotate(-90 7 7)"
+ ></circle>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/AttemptIcon.tsx b/apps/mes/src/assets/icons/AttemptIcon.tsx
new file mode 100644
index 0000000000..9fd9d7f6eb
--- /dev/null
+++ b/apps/mes/src/assets/icons/AttemptIcon.tsx
@@ -0,0 +1,29 @@
+export function AttemptIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <g clipPath="url(#clip0_9964_113464)">
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M16 0H0V16H16V0ZM7.09906 4.4L4.53906 11.5H6.11906L6.63906 10H9.35906L9.87906 11.5H11.4591L8.89906 4.4H7.09906ZM7.99906 6L8.92906 8.73H7.06906L7.99906 6Z"
+ fill="currentColor"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_9964_113464">
+ <path
+ d="M0 2C0 0.895431 0.895431 0 2 0H14C15.1046 0 16 0.895431 16 2V14C16 15.1046 15.1046 16 14 16H2C0.895431 16 0 15.1046 0 14V2Z"
+ fill="white"
+ />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/HighPriorityIcon.tsx b/apps/mes/src/assets/icons/HighPriorityIcon.tsx
new file mode 100644
index 0000000000..e138e67e38
--- /dev/null
+++ b/apps/mes/src/assets/icons/HighPriorityIcon.tsx
@@ -0,0 +1,18 @@
+export function HighPriorityIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ aria-label="High Priority"
+ className={className}
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="currentColor"
+ role="img"
+ focusable="false"
+ >
+ <rect x="1.5" y="8" width="3" height="6" rx="1"></rect>
+ <rect x="6.5" y="5" width="3" height="9" rx="1"></rect>
+ <rect x="11.5" y="2" width="3" height="12" rx="1"></rect>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/InProgressStatusIcon.tsx b/apps/mes/src/assets/icons/InProgressStatusIcon.tsx
new file mode 100644
index 0000000000..17b4632108
--- /dev/null
+++ b/apps/mes/src/assets/icons/InProgressStatusIcon.tsx
@@ -0,0 +1,35 @@
+export function InProgressStatusIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 14 14"
+ fill="none"
+ color="currentColor"
+ className={className}
+ >
+ <circle
+ cx="7"
+ cy="7"
+ r="6"
+ fill="none"
+ stroke="#f2be00"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
+ ></circle>
+ <circle
+ className="progress"
+ cx="7"
+ cy="7"
+ r="2"
+ fill="none"
+ stroke="#f2be00"
+ strokeWidth="4"
+ strokeDasharray="6.2517693806436885 100"
+ strokeDashoffset="0"
+ transform="rotate(-90 7 7)"
+ ></circle>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/LowPriorityIcon.tsx b/apps/mes/src/assets/icons/LowPriorityIcon.tsx
new file mode 100644
index 0000000000..b05e94e861
--- /dev/null
+++ b/apps/mes/src/assets/icons/LowPriorityIcon.tsx
@@ -0,0 +1,25 @@
+export function LowPriorityIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ aria-label="Low Priority"
+ className={className}
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="currentColor"
+ role="img"
+ focusable="false"
+ >
+ <rect x="1.5" y="8" width="3" height="6" rx="1"></rect>
+ <rect x="6.5" y="5" width="3" height="9" rx="1" fillOpacity="0.4"></rect>
+ <rect
+ x="11.5"
+ y="2"
+ width="3"
+ height="12"
+ rx="1"
+ fillOpacity="0.4"
+ ></rect>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/MediumPriorityIcon.tsx b/apps/mes/src/assets/icons/MediumPriorityIcon.tsx
new file mode 100644
index 0000000000..296884ae02
--- /dev/null
+++ b/apps/mes/src/assets/icons/MediumPriorityIcon.tsx
@@ -0,0 +1,25 @@
+export function MediumPriorityIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ aria-label="Medium Priority"
+ className={className}
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="currentColor"
+ role="img"
+ focusable="false"
+ >
+ <rect x="1.5" y="8" width="3" height="6" rx="1"></rect>
+ <rect x="6.5" y="5" width="3" height="9" rx="1"></rect>
+ <rect
+ x="11.5"
+ y="2"
+ width="3"
+ height="12"
+ rx="1"
+ fillOpacity="0.4"
+ ></rect>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/ShowParentIcon.tsx b/apps/mes/src/assets/icons/ShowParentIcon.tsx
new file mode 100644
index 0000000000..656f311124
--- /dev/null
+++ b/apps/mes/src/assets/icons/ShowParentIcon.tsx
@@ -0,0 +1,35 @@
+export function ShowParentIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M3.125 16H3.625H4.125V15H3.125H2C1.89733 15 1.8 14.9848 1.70919 14.9573L1.19765 14.8024L1.04267 14.2908C1.01515 14.2 1 14.1027 1 14V12.875V11.875H0V12.375V12.875V14C0 14.202 0.0299409 14.397 0.0856265 14.5808C0.135047 14.7439 0.204744 14.8982 0.291786 15.0407C0.363386 15.158 0.446722 15.2673 0.540161 15.3671C0.570065 15.399 0.601004 15.4299 0.632924 15.4598C0.732663 15.5533 0.841982 15.6366 0.95925 15.7082C1.10181 15.7953 1.25612 15.865 1.41923 15.9144C1.60303 15.9701 1.79802 16 2 16H3.125ZM10.125 15V16H9.625H9.125H6.875H6.375H5.875V15H6.875H9.125H10.125ZM15 5.875H16V6.375V6.875V9.125V9.625V10.125H15V9.125V6.875V5.875ZM5.875 1V0H6.375H6.875H9.125H9.625H10.125V1H9.125H6.875H5.875ZM1 10.125H0V9.625V9.125V6.875V6.375V5.875H1V6.875V9.125V10.125ZM0 3.625V4.125H1V3.125V2C1 1.89733 1.01515 1.8 1.04267 1.70919L1.19765 1.19765L1.70919 1.04267C1.8 1.01515 1.89733 1 2 1H3.125H4.125V0H3.625H3.125H2C1.79802 0 1.60303 0.0299409 1.41923 0.0856264C1.25612 0.135047 1.10181 0.204744 0.95925 0.291786C0.841983 0.363386 0.732663 0.446722 0.632924 0.540161C0.601004 0.570065 0.570065 0.601004 0.540161 0.632924C0.446722 0.732663 0.363386 0.841982 0.291786 0.95925C0.204744 1.10181 0.135047 1.25612 0.0856265 1.41923C0.0299409 1.60303 0 1.79802 0 2V3.125V3.625ZM12.375 0H11.875V1H12.875H14C14.1027 1 14.2 1.01515 14.2908 1.04267L14.8024 1.19765L14.9573 1.70919C14.9848 1.8 15 1.89733 15 2V3.125V4.125H16V3.625V3.125V2C16 1.79802 15.9701 1.60303 15.9144 1.41923C15.865 1.25612 15.7953 1.10181 15.7082 0.95925C15.6366 0.841982 15.5533 0.732663 15.4598 0.632924C15.4299 0.601004 15.399 0.570065 15.3671 0.540161C15.2673 0.446722 15.158 0.363386 15.0407 0.291786C14.8982 0.204744 14.7439 0.135047 14.5808 0.0856265C14.397 0.0299409 14.202 0 14 0H12.875H12.375ZM16 12.375V11.875H15V12.875V14C15 14.1027 14.9848 14.2 14.9573 14.2908L14.8024 14.8024L14.2908 14.9573C14.2 14.9848 14.1027 15 14 15H12.875H11.875V16H12.375H12.875H14C14.202 16 14.397 15.9701 14.5808 15.9144C14.7439 15.865 14.8982 15.7953 15.0407 15.7082C15.158 15.6366 15.2673 15.5533 15.3671 15.4598C15.399 15.4299 15.4299 15.399 15.4598 15.3671C15.5533 15.2673 15.6366 15.158 15.7082 15.0407C15.7953 14.8982 15.865 14.7439 15.9144 14.5808C15.9701 14.397 16 14.202 16 14V12.875V12.375ZM8.75 6.26758L10.4523 7.96991C10.7452 8.26281 11.2201 8.26281 11.513 7.96991C11.8059 7.67702 11.8059 7.20215 11.513 6.90925L8.59099 3.98725C8.43431 3.83057 8.22556 3.7577 8.02045 3.76865C7.81604 3.75834 7.60821 3.83124 7.45209 3.98736L4.53009 6.90937C4.23719 7.20226 4.23719 7.67713 4.53009 7.97003C4.82298 8.26292 5.29785 8.26292 5.59075 7.97003L7.25 6.31077L7.25 11.25C7.25 11.6642 7.58579 12 8 12C8.41421 12 8.75 11.6642 8.75 11.25L8.75 6.26758Z"
+ />
+ </svg>
+ );
+}
+
+export function ShowParentIconSelected({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M2 0C0.895431 0 0 0.895431 0 2V14C0 15.1046 0.895431 16 2 16H14C15.1046 16 16 15.1046 16 14V2C16 0.895431 15.1046 0 14 0H2ZM8.75 6.26758L10.4523 7.96991C10.7452 8.26281 11.2201 8.26281 11.513 7.96991C11.8059 7.67702 11.8059 7.20215 11.513 6.90925L8.59099 3.98725C8.43344 3.8297 8.22324 3.7569 8.01703 3.76884C7.8138 3.75958 7.60752 3.83254 7.45234 3.98773L4.53033 6.90973C4.23744 7.20263 4.23744 7.6775 4.53033 7.97039C4.82322 8.26329 5.2981 8.26329 5.59099 7.97039L7.25 6.31138L7.25 11.25C7.25 11.6642 7.58579 12 8 12C8.41421 12 8.75 11.6642 8.75 11.25L8.75 6.26758Z"
+ />
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/TaskIcon.tsx b/apps/mes/src/assets/icons/TaskIcon.tsx
new file mode 100644
index 0000000000..48d9c4181d
--- /dev/null
+++ b/apps/mes/src/assets/icons/TaskIcon.tsx
@@ -0,0 +1,29 @@
+export function TaskIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ className={className}
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <g clipPath="url(#clip0_9221_99732)">
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M16 0H0V16H16V0ZM10.8901 5.73995V4.44995H5.11011V5.73995H7.23011V11.55H8.77011V5.73995H10.8901Z"
+ fill="currentColor"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_9221_99732">
+ <path
+ d="M0 2C0 0.895431 0.895431 0 2 0H14C15.1046 0 16 0.895431 16 2V14C16 15.1046 15.1046 16 14 16H2C0.895431 16 0 15.1046 0 14V2Z"
+ fill="white"
+ />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/assets/icons/TodoStatusIcon.tsx b/apps/mes/src/assets/icons/TodoStatusIcon.tsx
new file mode 100644
index 0000000000..58458ad63c
--- /dev/null
+++ b/apps/mes/src/assets/icons/TodoStatusIcon.tsx
@@ -0,0 +1,35 @@
+export function TodoStatusIcon({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 14 14"
+ fill="none"
+ color="currentColor"
+ className="className"
+ >
+ <circle
+ cx="7"
+ cy="7"
+ r="6"
+ fill="none"
+ stroke="#e2e2e2"
+ strokeWidth="2"
+ strokeDasharray="3.14 0"
+ strokeDashoffset="-0.7"
+ ></circle>
+ <circle
+ className="progress"
+ cx="7"
+ cy="7"
+ r="2"
+ fill="none"
+ stroke="#e2e2e2"
+ strokeWidth="4"
+ strokeDasharray="0 100"
+ strokeDashoffset="0"
+ transform="rotate(-90 7 7)"
+ ></circle>
+ </svg>
+ );
+}
diff --git a/apps/mes/src/components/Authentication.tsx b/apps/mes/src/components/Authentication.tsx
index eb000cfb2f..3952218011 100644
--- a/apps/mes/src/components/Authentication.tsx
+++ b/apps/mes/src/components/Authentication.tsx
@@ -1,21 +1,27 @@
+import { Spinner, useMount } from "@carbon/react";
import type { Session } from "@supabase/supabase-js";
-import { useEffect, useState } from "react";
-import { Outlet } from "react-router-dom";
+import { useCallback, useState } from "react";
+import { Outlet, useLocation, useNavigate } from "react-router-dom";
+import { path } from "~/config";
import { supabase } from "~/lib/supabase";
-import { Login } from "../routes/login";
+import { Login } from "~/routes/login";
+import { getUser } from "~/services";
+import type { User } from "~/types";
export function Authentication() {
+ const [initializing, setInitializing] = useState(true);
const [session, setSession] = useState<Session | null>(null);
- useEffect(() => {
+ useMount(() => {
supabase.auth.getSession().then(({ data: { session } }) => {
setSession(session);
+ setInitializing(false);
});
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session);
});
- }, []);
+ });
return (
<>
@@ -24,9 +30,58 @@ export function Authentication() {
</div>
<div className="relative z-10">
<div className="flex flex-col min-w-screen h-screen min-h-0">
- {!session ? <Login /> : <Outlet context={{ session }} />}
+ {initializing ? (
+ <Loading />
+ ) : !session ? (
+ <Login />
+ ) : (
+ <Protected session={session} />
+ )}
</div>
</div>
</>
);
}
+
+function Loading() {
+ return (
+ <div className="flex items-center justify-center h-full">
+ <Spinner className="h-8 w-8" />
+ </div>
+ );
+}
+
+function Protected({ session }: { session: Session }) {
+ if (!session) throw new Error("Session is not defined");
+
+ const location = useLocation();
+ const navigate = useNavigate();
+ const [user, setUser] = useState<User>(null);
+
+ const getUserData = async () => {
+ const { data, error } = await getUser(supabase, session.user.id);
+ if (error || !data) {
+ throw new Error("User not found");
+ }
+
+ setUser(data);
+ };
+
+ useMount(() => {
+ if (location.pathname === path.to.root) {
+ navigate(path.to.jobs);
+ }
+ getUserData();
+ });
+
+ const signOut = useCallback(async () => {
+ await supabase.auth.signOut();
+ navigate(path.to.root);
+ }, [navigate]);
+
+ return (
+ <main className="flex flex-col h-full w-full">
+ <Outlet context={{ user, signOut }} />
+ </main>
+ );
+}
diff --git a/apps/mes/src/components/Jobs/JobCard.tsx b/apps/mes/src/components/Jobs/JobCard.tsx
new file mode 100644
index 0000000000..2c578e4dd1
--- /dev/null
+++ b/apps/mes/src/components/Jobs/JobCard.tsx
@@ -0,0 +1,228 @@
+import {
+ Card,
+ CardContent,
+ CardHeader,
+ HStack,
+ Progress,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ cn,
+} from "@carbon/react";
+import {
+ convertDateStringToIsoString,
+ formatDurationMilliseconds,
+ formatRelativeTime,
+} from "@carbon/utils";
+
+import { BsExclamationSquareFill } from "react-icons/bs";
+import {
+ LuCheckCircle,
+ LuClipboardCheck,
+ LuTimer,
+ LuXCircle,
+} from "react-icons/lu";
+import { useNavigate } from "react-router-dom";
+
+import { AlmostDoneIcon } from "~/assets/icons/AlmostDoneIcon";
+import { HighPriorityIcon } from "~/assets/icons/HighPriorityIcon";
+import { InProgressStatusIcon } from "~/assets/icons/InProgressStatusIcon";
+import { LowPriorityIcon } from "~/assets/icons/LowPriorityIcon";
+import { MediumPriorityIcon } from "~/assets/icons/MediumPriorityIcon";
+import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
+// import CustomerAvatar from "~/components/CustomerAvatar";
+// import EmployeeAvatarGroup from "~/components/EmployeeAvatarGroup";
+
+import type { Job, JobSettings } from "~/types";
+
+type JobCardProps = {
+ job: Job;
+ isSelected?: boolean;
+} & JobSettings;
+
+export function JobCard({
+ job,
+ isSelected = false,
+ showCustomer,
+ showDescription,
+ showDueDate,
+ showDuration,
+ showEmployee,
+ showProgress,
+ showStatus,
+}: JobCardProps) {
+ const navigate = useNavigate();
+ const isOverdue =
+ job.deadlineType !== "NO_DEADLINE" && job.dueDate
+ ? new Date(job.dueDate) < new Date()
+ : false;
+
+ console.log({ job, isSelected });
+
+ return (
+ <Card
+ onClick={() => navigate(job.id)}
+ className={cn("cursor-pointer", isSelected && "from-muted to-muted")}
+ >
+ <CardHeader className={cn("max-w-full p-3 border-b relative")}>
+ <div className="flex w-full max-w-full justify-between">
+ <div className="flex flex-col space-y-0">
+ {job.part && (
+ <span className="text-xs text-muted-foreground truncate">
+ {job.part}
+ </span>
+ )}
+ <span className="mr-auto font-semibold truncate">
+ {job.readableId}
+ </span>
+ </div>
+ </div>
+
+ {showProgress &&
+ ["PAUSED", "DONE", "IN_PROGRESS"].includes(job.status!) && (
+ <Progress
+ indicatorClassName={
+ job.status === "PAUSED" ? "bg-yellow-500" : ""
+ }
+ leftLabel={
+ job.progress ? formatDurationMilliseconds(job.progress) : ""
+ }
+ rightLabel={
+ job.duration ? formatDurationMilliseconds(job.duration) : ""
+ }
+ value={
+ job.progress && job.duration
+ ? (job.progress / job.duration) * 100
+ : 0
+ }
+ />
+ )}
+ </CardHeader>
+ <CardContent className="p-3 space-y-2 text-left whitespace-pre-wrap text-sm">
+ {showDescription && job.description && (
+ <HStack className="justify-start space-x-2">
+ <LuClipboardCheck className="text-muted-foreground" />
+ <span className="text-sm">{job.description}</span>
+ </HStack>
+ )}
+ {showStatus && job.status && (
+ <HStack className="justify-start space-x-2">
+ {getStatusIcon(job.status)}
+ <span className="text-sm">{getStatusText(job.status)}</span>
+ </HStack>
+ )}
+ {showDuration && job.duration && (
+ <HStack className="justify-start space-x-2">
+ <LuTimer className="text-muted-foreground" />
+ <span className="text-sm">
+ {formatDurationMilliseconds(job.duration)}
+ </span>
+ </HStack>
+ )}
+ {showDueDate && job.deadlineType && (
+ <HStack className="justify-start space-x-2">
+ {getDeadlineIcon(job.deadlineType, isOverdue)}
+ <Tooltip>
+ <TooltipTrigger>
+ <span
+ className={cn("text-sm", isOverdue ? "text-red-500" : "")}
+ >
+ {["ASAP", "NO_DEADLINE"].includes(job.deadlineType)
+ ? getDeadlineText(job.deadlineType)
+ : job.dueDate
+ ? `Due ${formatRelativeTime(
+ convertDateStringToIsoString(job.dueDate)
+ )}`
+ : "–"}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="right">
+ {getDeadlineText(job.deadlineType)}
+ </TooltipContent>
+ </Tooltip>
+ </HStack>
+ )}
+
+ {/* {showCustomer && job.customerId && (
+ <HStack className="justify-start space-x-2">
+ <LuFactory className="text-muted-foreground" />
+ <CustomerAvatar customerId={job.customerId} />
+ </HStack>
+ )}
+
+ {showEmployee && job.employeeIds && (
+ <HStack className="justify-start space-x-2">
+ <LuUsers className="text-muted-foreground" />
+ <EmployeeAvatarGroup employeeIds={job.employeeIds} />
+ </HStack>
+ )} */}
+ </CardContent>
+ </Card>
+ );
+}
+
+function getStatusIcon(status: Job["status"]) {
+ switch (status) {
+ case "READY":
+ case "TODO":
+ return <TodoStatusIcon className="text-foreground" />;
+ case "WAITING":
+ case "CANCELED":
+ return <LuXCircle className="text-muted-foreground" />;
+ case "DONE":
+ return <LuCheckCircle className="text-blue-600" />;
+ case "IN_PROGRESS":
+ return <AlmostDoneIcon />;
+ case "PAUSED":
+ return <InProgressStatusIcon />;
+ default:
+ return null;
+ }
+}
+
+function getStatusText(status: Job["status"], overdue: boolean = false) {
+ switch (status) {
+ case "READY":
+ return "Ready";
+ case "TODO":
+ return "Todo";
+ case "WAITING":
+ return "Waiting";
+ case "CANCELED":
+ return "Canceled";
+ case "DONE":
+ return "Done";
+ case "IN_PROGRESS":
+ return "In progress";
+ case "PAUSED":
+ return "Paused";
+ }
+}
+
+function getDeadlineIcon(deadlineType: Job["deadlineType"], overdue: boolean) {
+ switch (deadlineType) {
+ case "ASAP":
+ return <BsExclamationSquareFill className="text-red-500" />;
+ case "HARD_DEADLINE":
+ return <HighPriorityIcon className={cn(overdue ? "text-red-500" : "")} />;
+ case "SOFT_DEADLINE":
+ return (
+ <MediumPriorityIcon className={cn(overdue ? "text-red-500" : "")} />
+ );
+ case "NO_DEADLINE":
+ return <LowPriorityIcon />;
+ }
+}
+
+function getDeadlineText(deadlineType: Job["deadlineType"]) {
+ switch (deadlineType) {
+ case "ASAP":
+ return "ASAP";
+ case "HARD_DEADLINE":
+ return "Hard deadline";
+ case "SOFT_DEADLINE":
+ return "Soft deadline";
+ case "NO_DEADLINE":
+ return "No deadline";
+ }
+}
diff --git a/apps/mes/src/components/Jobs/JobsList.tsx b/apps/mes/src/components/Jobs/JobsList.tsx
new file mode 100644
index 0000000000..b667aa751b
--- /dev/null
+++ b/apps/mes/src/components/Jobs/JobsList.tsx
@@ -0,0 +1,27 @@
+import { ScrollArea } from "@carbon/react";
+import { useParams } from "react-router-dom";
+import type { Job, JobSettings } from "~/types";
+import { JobCard } from "./JobCard";
+
+type JobsListProps = JobSettings & {
+ jobs: Job[];
+};
+
+export function JobsList({ jobs, ...settings }: JobsListProps) {
+ const { operationId } = useParams();
+
+ return (
+ <ScrollArea className="h-[calc(100vh-120px)]">
+ <div className="flex flex-col gap-2 p-4 pt-0">
+ {jobs.map((job) => (
+ <JobCard
+ key={job.id}
+ job={job}
+ isSelected={operationId == job.id}
+ {...settings}
+ />
+ ))}
+ </div>
+ </ScrollArea>
+ );
+}
diff --git a/apps/mes/src/components/Jobs/WorkCellSelect.tsx b/apps/mes/src/components/Jobs/WorkCellSelect.tsx
new file mode 100644
index 0000000000..4c2a223a82
--- /dev/null
+++ b/apps/mes/src/components/Jobs/WorkCellSelect.tsx
@@ -0,0 +1,47 @@
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@carbon/react";
+import { useNavigate, useParams } from "react-router-dom";
+import { path } from "~/config";
+import type { WorkCell } from "~/lib/data";
+
+interface WorkCellSelectProps {
+ value: string;
+ onChange: (value: string) => void;
+ workCells: WorkCell[];
+}
+
+export function WorkCellSelect({
+ value,
+ workCells,
+ onChange,
+}: WorkCellSelectProps) {
+ const navigate = useNavigate();
+ const { operationId } = useParams();
+ return (
+ <Select
+ value={value}
+ onValueChange={(value) => {
+ onChange(value);
+ if (operationId) navigate(path.to.jobs);
+ }}
+ >
+ <SelectTrigger aria-label="Select work cell">
+ <SelectValue placeholder="Select a work cell">
+ {workCells.find((cell) => cell.id === value)?.title}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ {workCells.map((cell) => (
+ <SelectItem key={cell.id} value={cell.id}>
+ {cell.title}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ );
+}
diff --git a/apps/mes/src/components/Nav.tsx b/apps/mes/src/components/Nav.tsx
new file mode 100644
index 0000000000..968f456f04
--- /dev/null
+++ b/apps/mes/src/components/Nav.tsx
@@ -0,0 +1,81 @@
+import type { IconType } from "react-icons";
+
+import {
+ Button,
+ IconButton,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ cn,
+} from "@carbon/react";
+import { Link } from "react-router-dom";
+
+interface NavProps {
+ isCollapsed: boolean;
+ links: {
+ title: string;
+ label?: string;
+ icon: IconType;
+ variant: "primary" | "ghost";
+ }[];
+}
+
+export function Nav({ links, isCollapsed }: NavProps) {
+ return (
+ <div
+ data-collapsed={isCollapsed}
+ className="group flex flex-col gap-4 py-2 data-[collapsed=true]:py-2 justify-between h-full"
+ >
+ <nav className="grid gap-1 px-2 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2">
+ {links.map((link, index) =>
+ isCollapsed ? (
+ <Tooltip key={index} delayDuration={0}>
+ <TooltipTrigger asChild>
+ <IconButton
+ aria-label={link.title}
+ icon={<link.icon className="h-4 w-4" />}
+ variant={link.variant}
+ />
+ </TooltipTrigger>
+ <TooltipContent side="right" className="flex items-center gap-4">
+ {link.title}
+ {link.label && (
+ <span className="ml-auto text-muted-foreground">
+ {link.label}
+ </span>
+ )}
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ <Button
+ key={index}
+ leftIcon={<link.icon />}
+ variant={link.variant}
+ className={cn(
+ link.variant === "primary" &&
+ "dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white",
+ "justify-start"
+ )}
+ asChild
+ >
+ <Link to="#">
+ {link.title}
+ {link.label && (
+ <span
+ className={cn(
+ "ml-auto",
+ link.variant === "primary" &&
+ "text-background dark:text-white"
+ )}
+ >
+ {link.label}
+ </span>
+ )}
+ </Link>
+ </Button>
+ )
+ )}
+ </nav>
+ </div>
+ );
+}
diff --git a/apps/mes/src/config.ts b/apps/mes/src/config.ts
index c937327c5f..546e086a23 100644
--- a/apps/mes/src/config.ts
+++ b/apps/mes/src/config.ts
@@ -1,5 +1,6 @@
export const path = {
to: {
- login: "/login",
+ root: "/",
+ jobs: "/jobs",
},
};
diff --git a/apps/mes/src/hooks/useRouteData.ts b/apps/mes/src/hooks/useRouteData.ts
new file mode 100644
index 0000000000..fd241d9027
--- /dev/null
+++ b/apps/mes/src/hooks/useRouteData.ts
@@ -0,0 +1,11 @@
+import { useMemo } from "react";
+import { useMatches } from "react-router-dom";
+
+export function useRouteData<T>(path: string): T | undefined {
+ const matchingRoutes = useMatches();
+ const route = useMemo(
+ () => matchingRoutes.find((route) => route.pathname === path),
+ [matchingRoutes, path]
+ );
+ return (route?.data as T) || undefined;
+}
diff --git a/apps/mes/src/lib/auth.ts b/apps/mes/src/lib/auth.ts
new file mode 100644
index 0000000000..e585c0bf9e
--- /dev/null
+++ b/apps/mes/src/lib/auth.ts
@@ -0,0 +1,7 @@
+import { redirect } from "react-router-dom";
+import { supabase } from "./supabase";
+
+export async function requireAuthentication() {
+ const { data, error } = await supabase.auth.getSession();
+ if (error || !data.session) throw redirect("/");
+}
diff --git a/apps/mes/src/lib/data.tsx b/apps/mes/src/lib/data.tsx
new file mode 100644
index 0000000000..3dead00c6b
--- /dev/null
+++ b/apps/mes/src/lib/data.tsx
@@ -0,0 +1,173 @@
+import type { Job } from "~/types";
+
+export const jobs = [
+ {
+ id: "item0",
+ workCenterId: "4",
+ workCenterTypeId: "grinder",
+ readableId: "1503",
+ part: "F011432",
+ description: "Grind",
+ customerId: "ca2f11f8-1464-4753-9690-00107f141f3a",
+ dueDate: "2024-05-28",
+ duration: 30 * 60 * 1000,
+ deadlineType: "HARD_DEADLINE",
+ progress: 5 * 60 * 1000,
+ status: "IN_PROGRESS",
+ },
+ {
+ id: "item1",
+ workCenterId: "3",
+ workCenterTypeId: "saw",
+ readableId: "1032",
+ part: "F011432",
+ description: "Cut",
+ dueDate: "2024-05-30",
+ duration: 2 * 60 * 60 * 1000,
+ deadlineType: "SOFT_DEADLINE",
+ status: "PAUSED",
+ progress: 1.3 * 60 * 60 * 1000,
+ },
+ {
+ id: "item2",
+ workCenterId: "3",
+ workCenterTypeId: "saw",
+ readableId: "1023",
+ part: "F011432",
+ description: "Cut",
+ dueDate: "2024-05-20",
+ duration: 2 * 60 * 60 * 1000,
+ deadlineType: "ASAP",
+ customerId: "ca2f11f8-1464-4753-9690-00107f141f3a",
+ status: "READY",
+ },
+ {
+ id: "item3",
+ workCenterId: "3",
+ workCenterTypeId: "saw",
+ readableId: "1022",
+ part: "F011432",
+ description: "Cut",
+ duration: 10 * 60 * 1000,
+ deadlineType: "NO_DEADLINE",
+ status: "READY",
+ },
+ {
+ id: "item6",
+ workCenterId: "assembly1",
+ workCenterTypeId: "assembly",
+ readableId: "1013",
+ part: "F011432",
+ description: "Assemble",
+ deadlineType: "NO_DEADLINE",
+ duration: 2 * 60 * 60 * 1000,
+ employeeIds: ["52cdefed-f4b7-45b1-9ec8-701473671fb7"],
+ status: "IN_PROGRESS",
+ progress: 35 * 60 * 1000,
+ },
+ {
+ id: "item4",
+ workCenterId: "assembly1",
+ workCenterTypeId: "assembly",
+ readableId: "1492",
+ part: "F011432",
+ description: "Assemble",
+ duration: 4 * 60 * 60 * 1000,
+ deadlineType: "NO_DEADLINE",
+ status: "WAITING",
+ },
+ {
+ id: "item5",
+ workCenterId: "assembly2",
+ workCenterTypeId: "assembly",
+ readableId: "1109",
+ part: "F011432",
+ description: "Assemble",
+ dueDate: "2024-05-20",
+ duration: 4 * 60 * 60 * 1000,
+ deadlineType: "SOFT_DEADLINE",
+ status: "WAITING",
+ },
+
+ {
+ id: "item7",
+ workCenterId: "assembly2",
+ workCenterTypeId: "assembly",
+ readableId: "1014",
+ part: "F011432",
+ description: "Assemble",
+ dueDate: "2024-06-20",
+ duration: 20 * 60 * 1000,
+ deadlineType: "HARD_DEADLINE",
+ customerId: "bcbe0bca-6516-4a6c-bb8a-b3942f1a9a33",
+ status: "TODO",
+ },
+ {
+ id: "item8",
+ workCenterId: "assembly2",
+ workCenterTypeId: "assembly",
+ readableId: "1032",
+ part: "F011432",
+ description: "Assemble",
+ dueDate: "2024-05-24",
+ duration: 2 * 60 * 60 * 1000,
+ deadlineType: "SOFT_DEADLINE",
+ customerId: "ca2f11f8-1464-4753-9690-00107f141f3a",
+ status: "TODO",
+ },
+ {
+ id: "item9",
+ workCenterId: "assembly2",
+ workCenterTypeId: "assembly",
+ readableId: "1010",
+ part: "F011432",
+ description: "Assemble",
+ dueDate: "2024-05-20",
+ duration: 32 * 1000,
+ deadlineType: "ASAP",
+ status: "TODO",
+ },
+ {
+ id: "item10",
+ workCenterId: "assembly1",
+ workCenterTypeId: "assembly",
+ readableId: "1403",
+ part: "F011432",
+ description: "Assemble",
+ dueDate: "2024-05-20",
+ duration: 6 * 60 * 60 * 1000,
+ deadlineType: "NO_DEADLINE",
+ customerId: "bcbe0bca-6516-4a6c-bb8a-b3942f1a9a33",
+ status: "TODO",
+ },
+] satisfies Job[];
+
+export const workCells = [
+ {
+ id: "assembly1",
+ type: "assembly",
+ title: "Assembly Station 1",
+ },
+ {
+ id: "assembly2",
+ type: "assembly",
+ title: "Assembly Station 2",
+ },
+ {
+ id: "3",
+ type: "saw",
+ title: "Band Saw",
+ },
+ {
+ id: "4",
+ type: "grinder",
+ title: "Bench Grinder",
+ },
+ {
+ id: "5",
+ title: "CNC Mill 1",
+ type: "cnc",
+ },
+];
+
+export type WorkCell = (typeof workCells)[number];
diff --git a/apps/mes/src/lib/supabase.ts b/apps/mes/src/lib/supabase.ts
index 3e06b2fcf7..fd2a6ebf7f 100644
--- a/apps/mes/src/lib/supabase.ts
+++ b/apps/mes/src/lib/supabase.ts
@@ -1,6 +1,7 @@
+import type { Database } from "@carbon/database";
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
-export const supabase = createClient(supabaseUrl, supabaseAnonKey);
+export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey);
diff --git a/apps/mes/src/main.tsx b/apps/mes/src/main.tsx
index 40744752d2..0432089fa5 100644
--- a/apps/mes/src/main.tsx
+++ b/apps/mes/src/main.tsx
@@ -1,27 +1,33 @@
-import React from "react";
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { Authentication } from "~/components/Authentication";
import Error from "~/components/Error";
+import { path } from "~/config";
import "~/index.css";
-import { Home } from "./routes";
+import { Job } from "~/routes/job";
+import { Jobs, loader as jobsLoader } from "~/routes/jobs";
const router = createBrowserRouter([
{
- path: "/",
+ path: path.to.root,
element: <Authentication />,
errorElement: <Error />,
children: [
{
- path: "/",
- element: <Home />,
+ path: path.to.jobs,
+ loader: jobsLoader,
+ element: <Jobs navCollapsedSize={4} />,
+ children: [
+ {
+ path: ":operationId",
+ element: <Job />,
+ },
+ ],
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")!).render(
- <React.StrictMode>
- <RouterProvider router={router} />
- </React.StrictMode>
+ <RouterProvider router={router} />
);
diff --git a/apps/mes/src/routes/index.tsx b/apps/mes/src/routes/index.tsx
deleted file mode 100644
index 77a877b2fe..0000000000
--- a/apps/mes/src/routes/index.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import { Button } from "@carbon/react";
-import { supabase } from "~/lib/supabase";
-
-export const Home = () => {
- const signOut = async () => {
- await supabase.auth.signOut();
- };
-
- return (
- <div className="flex flex-col items-center justify-center h-screen space-y-4">
- <Button size="lg" onClick={signOut}>
- Sign Out
- </Button>
- </div>
- );
-};
diff --git a/apps/mes/src/routes/job.tsx b/apps/mes/src/routes/job.tsx
new file mode 100644
index 0000000000..21b9c8b271
--- /dev/null
+++ b/apps/mes/src/routes/job.tsx
@@ -0,0 +1,269 @@
+import {
+ Button,
+ Heading,
+ IconButton,
+ Modal,
+ ModalContent,
+ Popover,
+ PopoverClose,
+ PopoverContent,
+ PopoverTrigger,
+ ResizableHandle,
+ ResizablePanel,
+ Separator,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@carbon/react";
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { useRef, useState, type ComponentProps, type ReactNode } from "react";
+import {
+ FaCheck,
+ FaOilCan,
+ FaPause,
+ FaPlay,
+ FaRedoAlt,
+ FaTrash,
+ FaTruckLoading,
+} from "react-icons/fa";
+import { LuChevronLeft, LuExpand } from "react-icons/lu";
+import { useNavigate, useParams } from "react-router-dom";
+import { path } from "~/config";
+import { useRouteData } from "~/hooks/useRouteData";
+import type { Job as JobType } from "~/types";
+import { defaultJobLayout } from "./jobs";
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ return null;
+}
+
+export function Job() {
+ const navigate = useNavigate();
+ const { operationId } = useParams();
+ const routeData = useRouteData<{ jobs: JobType[] }>(path.to.jobs);
+ const job = routeData?.jobs.find((job) => job.id === operationId);
+
+ const [fullScreen, setFullScreen] = useState(false);
+
+ if (!job) {
+ return null;
+ }
+
+ return (
+ <OptionallyFullscreen
+ isFullScreen={fullScreen}
+ onClose={() => setFullScreen(false)}
+ >
+ <Tabs defaultValue="details">
+ <div className="flex items-center justify-between px-4 py-2 h-[52px] bg-background">
+ <div className="flex items-start flex-grow gap-1">
+ {!fullScreen && (
+ <IconButton
+ aria-label="Back"
+ icon={<LuChevronLeft />}
+ variant="ghost"
+ onClick={() => navigate(path.to.jobs)}
+ />
+ )}
+ <Heading size="h2">{job.readableId}</Heading>
+ </div>
+ <div className="flex flex-shrink-0 items-center justify-end gap-2">
+ <TabsList className="ml-auto">
+ <TabsTrigger value="details">Details</TabsTrigger>
+ <TabsTrigger disabled value="model">
+ Model
+ </TabsTrigger>
+ <TabsTrigger disabled value="instructions">
+ Instructions
+ </TabsTrigger>
+ <TabsTrigger value="notes">Notes</TabsTrigger>
+ </TabsList>
+ {!fullScreen && (
+ <IconButton
+ aria-label="Expand"
+ icon={<LuExpand />}
+ variant="secondary"
+ onClick={() => setFullScreen(true)}
+ />
+ )}
+ </div>
+ </div>
+
+ {!fullScreen && <Separator />}
+
+ <TabsContent value="details"></TabsContent>
+ <TabsContent value="model"></TabsContent>
+ <TabsContent value="instructions"></TabsContent>
+ <TabsContent value="notes"></TabsContent>
+
+ <Controls>
+ <IconButtonWithTooltip
+ disabled
+ icon={
+ <FaOilCan className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Non-Conformance Report"
+ />
+ <IconButtonWithTooltip
+ icon={
+ <FaTrash className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Scrap"
+ />
+ <PlayButton
+ onStart={(type) => {
+ alert(type);
+ }}
+ />
+ <IconButtonWithTooltip
+ icon={
+ <FaRedoAlt className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Rework"
+ />
+ <IconButtonWithTooltip
+ icon={
+ <FaCheck className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Complete"
+ />
+ </Controls>
+ </Tabs>
+ </OptionallyFullscreen>
+ );
+}
+
+function OptionallyFullscreen({
+ children,
+ isFullScreen,
+ onClose,
+}: {
+ children: ReactNode;
+ isFullScreen: boolean;
+ onClose: () => void;
+}) {
+ return (
+ <>
+ <ResizableHandle withHandle />
+ <ResizablePanel defaultSize={defaultJobLayout[2]} className="relative">
+ {children}
+ </ResizablePanel>
+ {isFullScreen && (
+ <Modal
+ open={isFullScreen}
+ onOpenChange={(open) => {
+ if (!open) onClose();
+ }}
+ >
+ <ModalContent className="min-w-full h-screen">
+ {children}
+ </ModalContent>
+ </Modal>
+ )}
+ </>
+ );
+}
+
+function Controls({ children }: { children: ReactNode }) {
+ return (
+ <TooltipProvider>
+ <div className="flex items-center gap-4 absolute p-4 bottom-4 left-1/2 transform -translate-x-1/2">
+ {children}
+ </div>
+ </TooltipProvider>
+ );
+}
+
+function ButtonWithTooltip({
+ tooltip,
+ children,
+ ...props
+}: ComponentProps<"button"> & { tooltip: string }) {
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button {...props}>{children}</button>
+ </TooltipTrigger>
+ <TooltipContent>{tooltip}</TooltipContent>
+ </Tooltip>
+ );
+}
+
+function IconButtonWithTooltip({
+ icon,
+ tooltip,
+ ...props
+}: ComponentProps<"button"> & { icon: ReactNode; tooltip: string }) {
+ return (
+ <ButtonWithTooltip
+ {...props}
+ tooltip={tooltip}
+ className="w-12 h-12 flex flex-row items-center gap-2 justify-center bg-accent rounded-full shadow-lg hover:cursor-pointer hover:shadow-xl hover:accent hover:scale-105 transition-all disabled:cursor-not-allowed disabled:opacity-50"
+ >
+ {icon}
+ </ButtonWithTooltip>
+ );
+}
+
+function PauseButton({ className, ...props }: ComponentProps<"button">) {
+ return (
+ <ButtonWithTooltip
+ {...props}
+ tooltip="Pause"
+ className="group w-16 h-16 flex flex-row items-center gap-2 justify-center bg-red-500 rounded-full shadow-lg hover:cursor-pointer hover:drop-shadow-xl hover:bg-red-600 hover:scale-105 transition-all"
+ >
+ <FaPause className="text-accent group-hover:scale-125" />
+ </ButtonWithTooltip>
+ );
+}
+
+function PlayButton({
+ className,
+ onStart,
+ ...props
+}: ComponentProps<"button"> & { onStart: (type: "setup" | "run") => void }) {
+ const closeButtonRef = useRef<HTMLButtonElement>(null);
+
+ return (
+ <Popover>
+ <PopoverTrigger asChild>
+ <button
+ {...props}
+ className="group w-16 h-16 flex flex-row items-center gap-2 justify-center bg-emerald-500 rounded-full shadow-lg hover:cursor-pointer hover:drop-shadow-xl hover:bg-emerald-600 hover:scale-105 transition-all"
+ >
+ <FaPlay className="text-accent group-hover:scale-125" />
+ </button>
+ </PopoverTrigger>
+ <PopoverContent className="flex space-x-4 w-full justify-center">
+ <Button
+ leftIcon={<FaTruckLoading />}
+ size="lg"
+ variant="secondary"
+ onClick={() => {
+ onStart("setup");
+ closeButtonRef.current?.click();
+ }}
+ >
+ Setup
+ </Button>
+ <Button
+ leftIcon={<FaPlay />}
+ size="lg"
+ variant="primary"
+ onClick={() => {
+ onStart("run");
+ closeButtonRef.current?.click();
+ }}
+ >
+ Run
+ </Button>
+ <PopoverClose ref={closeButtonRef} className="sr-only" tabIndex={-1} />
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/apps/mes/src/routes/jobs.tsx b/apps/mes/src/routes/jobs.tsx
new file mode 100644
index 0000000000..e1281e8363
--- /dev/null
+++ b/apps/mes/src/routes/jobs.tsx
@@ -0,0 +1,250 @@
+import {
+ Avatar,
+ Button,
+ Heading,
+ IconButton,
+ Input,
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ Separator,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ TooltipProvider,
+ cn,
+ useDebounce,
+ useLocalStorage,
+} from "@carbon/react";
+
+import { useMemo, useState } from "react";
+import { AiOutlineFieldTime } from "react-icons/ai";
+import { LuCalendarClock, LuLogOut, LuSearch } from "react-icons/lu";
+import { Outlet, useLoaderData, useOutletContext } from "react-router-dom";
+import { JobsList } from "~/components/Jobs/JobsList";
+import { WorkCellSelect } from "~/components/Jobs/WorkCellSelect";
+import { Nav } from "~/components/Nav";
+import { requireAuthentication } from "~/lib/auth";
+import { jobs, workCells } from "~/lib/data";
+import type { Job, JobSettings, OutletContext } from "~/types";
+
+const jobSettings: JobSettings = {
+ showCustomer: false,
+ showDescription: true,
+ showDueDate: true,
+ showDuration: true,
+ showEmployee: false,
+ showProgress: false,
+ showStatus: true,
+};
+
+export async function loader() {
+ await requireAuthentication();
+
+ return {
+ jobs: jobs satisfies Job[],
+ jobSettings,
+ workCells,
+ };
+}
+
+interface JobsProps {
+ defaultLayout?: number[] | undefined;
+ defaultCollapsed?: boolean;
+ navCollapsedSize: number;
+}
+
+export const defaultJobLayout = [265, 440, 655];
+
+export function Jobs({
+ defaultLayout = defaultJobLayout,
+ defaultCollapsed = false,
+ navCollapsedSize = 50,
+}: JobsProps) {
+ const { user, signOut } = useOutletContext<OutletContext>();
+ const { jobs, jobSettings, workCells } = useLoaderData() as Awaited<
+ ReturnType<typeof loader>
+ >;
+
+ const [isCollapsed, setIsCollapsed] = useState(defaultCollapsed);
+
+ const [selectedWorkCell, setSelectedWorkCell] = useLocalStorage<string>(
+ `${user?.id}:workCell`,
+ workCells?.[0]?.id ?? ""
+ );
+
+ const [input, setInput] = useState("");
+ const [search, setSearch] = useState("");
+ const debounceSearch = useDebounce((input: string) => {
+ setSearch(input);
+ }, 500);
+ const onSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ setInput(e.target.value);
+ debounceSearch(e.target.value);
+ };
+
+ const workCellJobs = useMemo(
+ () =>
+ jobs.filter((job) => {
+ if (!search) return job.workCenterId === selectedWorkCell;
+
+ return (
+ job.workCenterId === selectedWorkCell &&
+ job.readableId.includes(search.toLowerCase())
+ );
+ }),
+ [jobs, search, selectedWorkCell]
+ );
+
+ return (
+ <TooltipProvider delayDuration={0}>
+ <ResizablePanelGroup
+ direction="horizontal"
+ className="h-full items-stretch"
+ >
+ <ResizablePanel
+ defaultSize={defaultLayout[0]}
+ collapsedSize={navCollapsedSize}
+ collapsible={true}
+ minSize={15}
+ maxSize={20}
+ onCollapse={() => {
+ setIsCollapsed(true);
+ }}
+ onExpand={() => {
+ setIsCollapsed(false);
+ }}
+ className={cn(
+ isCollapsed &&
+ "min-w-[50px] transition-all duration-300 ease-in-out"
+ )}
+ >
+ <div
+ className={cn(
+ "flex h-[52px] items-center justify-start bg-background",
+ isCollapsed ? "h-[52px]" : "px-2"
+ )}
+ >
+ <div
+ className={cn(
+ "flex items-center space-x-2 w-full",
+ isCollapsed ? "justify-center" : "justify-start"
+ )}
+ >
+ <Avatar
+ size="sm"
+ src={user?.avatarUrl ?? undefined}
+ name={user?.fullName ?? ""}
+ />
+ {!isCollapsed && (
+ <span className="text-sm truncate">{user?.fullName}</span>
+ )}
+ </div>
+ </div>
+ <div className="flex flex-col h-[calc(100%-52px)] justify-between overflow-y-auto">
+ <div className="flex flex-col">
+ <Separator />
+ <Nav
+ isCollapsed={isCollapsed}
+ links={[
+ {
+ title: "Jobs",
+ label: "128",
+ icon: LuCalendarClock,
+ variant: "primary",
+ },
+ {
+ title: "Active",
+ label: "1",
+ icon: AiOutlineFieldTime,
+ variant: "ghost",
+ },
+ ]}
+ />
+ {/* <Separator />
+ <Nav
+ isCollapsed={isCollapsed}
+ links={[
+ {
+ title: "Messages",
+ label: "972",
+ icon: LuMessageSquare,
+ variant: "ghost",
+ },
+ ]}
+ /> */}
+ </div>
+ <div
+ className={cn(
+ "flex flex-col p-2 w-full",
+ isCollapsed && "items-center justify-center "
+ )}
+ >
+ {isCollapsed ? (
+ <IconButton
+ aria-label="Sign out"
+ icon={<LuLogOut />}
+ onClick={signOut}
+ />
+ ) : (
+ <Button size="lg" onClick={signOut}>
+ Sign out
+ </Button>
+ )}
+ </div>
+ </div>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel defaultSize={defaultLayout[1]} minSize={30}>
+ <Tabs defaultValue="current">
+ <div className="flex items-center px-4 py-2 h-[52px] bg-background">
+ <Heading size="h2">Jobs</Heading>
+ <TabsList className="ml-auto">
+ <TabsTrigger value="current">Current</TabsTrigger>
+ <TabsTrigger value="all">All</TabsTrigger>
+ </TabsList>
+ </div>
+ <Separator />
+ <div className="bg-background/95 p-4 backdrop-blur supports-[backdrop-filter]:bg-background/60">
+ <div className="relative">
+ <div className="flex justify-between space-x-4">
+ <div className="flex flex-grow">
+ <LuSearch className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
+ <Input
+ value={input}
+ onChange={onSearchChange}
+ placeholder="Search"
+ className="pl-8"
+ />
+ </div>
+ <div className="flex flex-shrink">
+ <WorkCellSelect
+ workCells={workCells}
+ value={selectedWorkCell}
+ onChange={setSelectedWorkCell}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ <TabsContent value="current" className="m-0">
+ <JobsList
+ jobs={workCellJobs.filter((job) =>
+ ["IN_PROGRESS", "PAUSED", "READY", "TODO"].includes(
+ job.status
+ )
+ )}
+ {...jobSettings}
+ />
+ </TabsContent>
+ <TabsContent value="all" className="m-0">
+ <JobsList jobs={workCellJobs} {...jobSettings} />
+ </TabsContent>
+ </Tabs>
+ </ResizablePanel>
+ <Outlet />
+ </ResizablePanelGroup>
+ </TooltipProvider>
+ );
+}
diff --git a/apps/mes/src/services.tsx b/apps/mes/src/services.tsx
new file mode 100644
index 0000000000..a44c4dd93a
--- /dev/null
+++ b/apps/mes/src/services.tsx
@@ -0,0 +1,14 @@
+import type { Database } from "@carbon/database";
+import type { SupabaseClient } from "@supabase/supabase-js";
+
+export async function getUser(
+ client: SupabaseClient<Database>,
+ userId: string
+) {
+ return client
+ .from("user")
+ .select("*")
+ .eq("id", userId)
+ .eq("active", true)
+ .maybeSingle();
+}
diff --git a/apps/mes/src/types.ts b/apps/mes/src/types.ts
new file mode 100644
index 0000000000..133169ea9a
--- /dev/null
+++ b/apps/mes/src/types.ts
@@ -0,0 +1,49 @@
+import { z } from "zod";
+import type { getUser } from "./services";
+
+export type User = Awaited<ReturnType<typeof getUser>>["data"];
+export type OutletContext = {
+ user: User;
+ signOut: () => Promise<void>;
+};
+
+export type JobSettings = {
+ showCustomer: boolean;
+ showDescription: boolean;
+ showDueDate: boolean;
+ showDuration: boolean;
+ showEmployee: boolean;
+ showProgress: boolean;
+ showStatus: boolean;
+};
+
+const jobValidator = z.object({
+ id: z.string(),
+ workCenterId: z.string(),
+ workCenterTypeId: z.string(),
+ readableId: z.string(),
+ part: z.string().optional(),
+ customerId: z.string().optional(),
+ employeeIds: z.array(z.string()).optional(),
+ description: z.string().optional(),
+ dueDate: z.string().optional(), // 2024-05-28
+ duration: z.number().optional(), // miliseconds
+ deadlineType: z
+ .enum(["ASAP", "HARD_DEADLINE", "SOFT_DEADLINE", "NO_DEADLINE"])
+ .optional(),
+ progress: z.number().optional(), // miliseconds
+ order: z.number().optional(),
+ status: z
+ .enum([
+ "CANCELED",
+ "DONE",
+ "IN_PROGRESS",
+ "PAUSED",
+ "READY",
+ "TODO",
+ "WAITING",
+ ])
+ .optional(),
+});
+
+export type Job = z.infer<typeof jobValidator>;
diff --git a/package-lock.json b/package-lock.json
index 1a149c1db9..3c03277562 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -177,6 +177,7 @@
"@carbon/tsconfig": "*",
"@hookform/resolvers": "^3.4.2",
"@supabase/supabase-js": "^2.40.0",
+ "class-variance-authority": "0.7.0",
"localforage": "^1.10.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/packages/react/src/Popover.tsx b/packages/react/src/Popover.tsx
index 96ff1e7061..cda2abaadb 100644
--- a/packages/react/src/Popover.tsx
+++ b/packages/react/src/Popover.tsx
@@ -59,8 +59,11 @@ const PopoverFooter = forwardRef<
));
PopoverFooter.displayName = "PopoverFooter";
+const PopoverClose = PopoverPrimitive.Close;
+
export {
Popover,
+ PopoverClose,
PopoverContent,
PopoverFooter,
PopoverHeader,
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 135503fca1..3b9aaf9aed 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -186,6 +186,7 @@ import {
import { Paragraph } from "./Paragraph";
import {
Popover,
+ PopoverClose,
PopoverContent,
PopoverFooter,
PopoverHeader,
@@ -211,6 +212,7 @@ import {
SelectTrigger,
SelectValue,
} from "./Select";
+import { Separator } from "./Separator";
import { Skeleton } from "./Skeleton";
import { Slider } from "./Slider";
import { Spinner } from "./Spinner";
@@ -386,6 +388,7 @@ export {
NumberInputStepper,
Paragraph,
Popover,
+ PopoverClose,
PopoverContent,
PopoverFooter,
PopoverHeader,
@@ -409,6 +412,7 @@ export {
SelectSeparator,
SelectTrigger,
SelectValue,
+ Separator,
Skeleton,
Slider,
Spinner,