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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: don't block on open time entries check
Brad Barbin18bc062a6fa5
diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsxindex 1d0f6eb43a..63a38d2644 100644--- a/apps/erp/app/routes/x+/_layout.tsx+++ b/apps/erp/app/routes/x+/_layout.tsx@@ -16,11 +16,13 @@ import { ItarPopup, useKeyboardWedge, useNProgress } from "@carbon/remix";import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";import { Edition } from "@carbon/utils";import posthog from "posthog-js";+import { Suspense } from "react";import type {LoaderFunctionArgs,ShouldRevalidateFunction} from "react-router";import {+ Await,data,Outlet,redirect,@@ -91,8 +93,7 @@ export async function loader({ request }: LoaderFunctionArgs) {user,claims,groups,- defaults,- openClockEntry+ defaults] = await Promise.all([getCompanies(client, userId),getStripeCustomerByCompanyId(companyId, userId),@@ -103,8 +104,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getUser(client, userId),getUserClaims(userId, companyId),getUserGroups(client, userId),- getUserDefaults(client, userId, companyId),- getOpenClockEntry(client, userId, companyId)+ getUserDefaults(client, userId, companyId)]);if (!claims || user.error || !user.data || !groups.data) {@@ -150,8 +150,8 @@ export async function loader({ request }: LoaderFunctionArgs) {role: claims?.role,user: user.data,savedViews: savedViews.data ?? [],- openClockEntry: openClockEntry.data- ? { id: openClockEntry.data.id, clockIn: openClockEntry.data.clockIn }+ openClockEntry: companySettings.data?.timeCardEnabled+ ? getOpenClockEntry(client, userId, companyId): null});}@@ -210,7 +210,22 @@ export default function AuthenticatedRoute() {onDismiss={dismiss}/>{companySettings?.timeCardEnabled && (- <TimeCardWarning openClockEntry={openClockEntry} />+ <Suspense fallback={null}>+ <Await resolve={openClockEntry}>+ {(resolved) => (+ <TimeCardWarning+ openClockEntry={+ resolved?.data+ ? {+ id: resolved.data.id,+ clockIn: resolved.data.clockIn+ }+ : null+ }+ />+ )}+ </Await>+ </Suspense>)}</TooltipProvider></RealtimeDataProvider>diff --git a/apps/mes/app/components/AppSidebar.tsx b/apps/mes/app/components/AppSidebar.tsxindex faa4af2dfa..ebe5a1342d 100644--- a/apps/mes/app/components/AppSidebar.tsx+++ b/apps/mes/app/components/AppSidebar.tsx@@ -34,7 +34,7 @@ import {} from "@carbon/react";import { ItarDisclosure, useMode } from "@carbon/remix";import type { ComponentProps } from "react";-import { useRef } from "react";+import { Suspense, useRef } from "react";import { BsFillHexagonFill } from "react-icons/bs";import {LuActivity,@@ -51,7 +51,7 @@ import {LuUser,LuWrench} from "react-icons/lu";-import { Form, Link, useFetcher, useLocation } from "react-router";+import { Await, Form, Link, useFetcher, useLocation } from "react-router";import { useUser } from "~/hooks";import type { action } from "~/root";import type { Location } from "~/services/types";@@ -79,7 +79,9 @@ export function AppSidebar({location: string;locations: Location[];timeCardEnabled?: boolean;- openClockEntry?: { id: string; clockIn: string } | null;+ openClockEntry?: Promise<{+ data: { id: string; clockIn: string; [key: string]: unknown } | null;+ }> | null;}) {return (<Sidebar collapsible="icon" {...props}>@@ -96,7 +98,22 @@ export function AppSidebar({<SidebarFooter>{timeCardEnabled && (<SidebarMenu>- <TimeCardButton openClockEntry={openClockEntry ?? null} />+ <Suspense fallback={<TimeCardButton openClockEntry={null} />}>+ <Await resolve={openClockEntry}>+ {(resolved) => (+ <TimeCardButton+ openClockEntry={+ resolved?.data+ ? {+ id: resolved.data.id,+ clockIn: resolved.data.clockIn+ }+ : null+ }+ />+ )}+ </Await>+ </Suspense></SidebarMenu>)}<UserNavdiff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsxindex 0e901e205f..6dee82e040 100644--- a/apps/mes/app/routes/x+/_layout.tsx+++ b/apps/mes/app/routes/x+/_layout.tsx@@ -16,12 +16,14 @@ import { ItarPopup, useKeyboardWedge, useNProgress } from "@carbon/remix";import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";import { Edition } from "@carbon/utils";import posthog from "posthog-js";+import { Suspense } from "react";import type {LoaderFunctionArgs,MiddlewareFunction,ShouldRevalidateFunction} from "react-router";import {+ Await,data,Outlet,redirect,@@ -82,7 +84,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {// Get the location from middleware contextconst locationId = context.get(userContext)?.locationId;- let [companyPlan, locations, activeEvents, companySettings, openClockEntry] =+ let [companyPlan, locations, activeEvents, companySettings] =await Promise.all([getStripeCustomerByCompanyId(companyId, userId),getLocationsByCompany(client, companyId),@@ -94,8 +96,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {.from("companySettings").select("timeCardEnabled").eq("id", companyId)- .single(),- getOpenClockEntry(client, userId, companyId)+ .single()]);// Get active maintenance count after we have the location@@ -127,8 +128,8 @@ export async function loader({ request, context }: LoaderFunctionArgs) {plan: companyPlan?.planId,user: user.data,timeCardEnabled: companySettings.data?.timeCardEnabled ?? false,- openClockEntry: openClockEntry.data- ? { id: openClockEntry.data.id, clockIn: openClockEntry.data.clockIn }+ openClockEntry: companySettings.data?.timeCardEnabled+ ? getOpenClockEntry(client, userId, companyId): null});}@@ -195,7 +196,22 @@ export default function AuthenticatedRoute() {/><Outlet />{timeCardEnabled && (- <TimeCardWarning openClockEntry={openClockEntry} />+ <Suspense fallback={null}>+ <Await resolve={openClockEntry}>+ {(resolved) => (+ <TimeCardWarning+ openClockEntry={+ resolved?.data+ ? {+ id: resolved.data.id,+ clockIn: resolved.data.clockIn+ }+ : null+ }+ />+ )}+ </Await>+ </Suspense>)}</TooltipProvider></SidebarProvider>diff --git a/packages/auth/src/services/users.server.ts b/packages/auth/src/services/users.server.tsindex dc00cceeb0..4e064063dc 100644--- a/packages/auth/src/services/users.server.ts+++ b/packages/auth/src/services/users.server.ts@@ -172,7 +172,7 @@ export async function deactivateEmployee(const groupIds = companyGroups.data?.map((g) => g.id) ?? [];- const [updatePermissions, userToCompanyDelete, employeeDelete] =+ const [updatePermissions, userToCompanyDelete, employeeDeactivate] =await Promise.all([serviceRole.from("userPermission")@@ -185,7 +185,7 @@ export async function deactivateEmployee(.eq("companyId", companyId),serviceRole.from("employee")- .delete()+ .update({ active: false }).eq("id", userId).eq("companyId", companyId),serviceRole@@ -215,8 +215,8 @@ export async function deactivateEmployee();}- if (employeeDelete.error) {- return error(employeeDelete.error, "Failed to remove employee");+ if (employeeDeactivate.error) {+ return error(employeeDeactivate.error, "Failed to deactivate employee");}return success("Sucessfully deactivated employee");