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.

Merge remote-tracking branch 'origin/main' into feat/mobile-redesign

aashud76b4864ab6d
diff --cc apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
index b684fbf22f,0000000000..4c391d623c
mode 100644,000000..100644
--- a/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
+++ b/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
@@@ -1,365 -1,0 +1,372 @@@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { CONTROLLED_ENVIRONMENT } from "@carbon/auth";
+import {
+ Avatar as AvatarBase,
+ BottomSheet,
+ BottomSheetBack,
+ BottomSheetBody,
+ BottomSheetContent,
+ BottomSheetHeader,
+ BottomSheetTitle,
+ cn,
+ ItarDisclosure,
+ PrefetchLink,
+ SheetSectionLabel,
+ sheetRowClassName,
+ useMode
+} from "@carbon/react";
+import { themes } from "@carbon/utils";
+import { Trans, useLingui } from "@lingui/react/macro";
+import type { ReactNode } from "react";
+import { Fragment, useEffect, useState } from "react";
+import { LuBell, LuBuilding2 } from "react-icons/lu";
+import { Form } from "react-router";
+import { Avatar } from "~/components";
+import type { AccountMenuItem } from "~/components/AvatarMenu";
+import { useAccountMenu } from "~/components/AvatarMenu";
+import { useUser } from "~/hooks";
+import { useNotifications } from "~/hooks/useNotifications";
++import { useRestoreBrowserNotifications } from "~/hooks/usePushSubscription";
+import { path } from "~/utils/path";
+import {
+ useCompanyGroups,
+ useCompanySwitchRedirect
+} from "../Topbar/CompanySwitcher";
- import { NotificationsPanel } from "../Topbar/Notifications";
++import { NotificationsPanel, usePushPublicKey } from "../Topbar/Notifications";
+import { SheetRowButton, SheetRowContent, SheetRowGroup } from "./SheetRow";
+
+/** Consecutive items with the same `group`, as the desktop separators split them. */
+function groupItems(items: AccountMenuItem[]) {
+ const groups: AccountMenuItem[][] = [];
+ for (const item of items) {
+ const last = groups[groups.length - 1];
+ if (last && last[0]!.group === item.group) last.push(item);
+ else groups.push([item]);
+ }
+ return groups;
+}
+
+type Screen =
+ | { id: "root" }
+ | { id: "notifications" }
+ | { id: "companies" }
+ | { id: "submenu"; item: AccountMenuItem };
+
+/**
+ * The tab bar's Profile sheet: the desktop account menu's items in order,
+ * plus Notifications and the company switcher, which live in the desktop top
+ * bar. Sub-menus drill in within the sheet.
+ */
+export function ProfileSheet({
+ open,
+ onOpenChange
+}: {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}) {
+ const { t } = useLingui();
+ const menu = useAccountMenu();
+ const user = useUser();
+ const mode = useMode();
+ const companyGroups = useCompanyGroups();
+ const switchRedirect = useCompanySwitchRedirect();
+ const notifications = useNotifications({
+ companyId: user.company.id,
+ userId: user.id
+ });
++ // Always mounted on phones, like the desktop bell: restores a signed-back-in
++ // user's browser notifications.
++ useRestoreBrowserNotifications({
++ publicKey: usePushPublicKey(),
++ userId: user.id
++ });
+ const unread = notifications.notifications.filter((n) => !n.read).length;
+ const companyCount = companyGroups.reduce(
+ (sum, group) => sum + group.companies.length,
+ 0
+ );
+
+ const [screen, setScreen] = useState<Screen>({ id: "root" });
+ const [notificationsTab, setNotificationsTab] = useState("inbox");
+
+ useEffect(() => {
+ if (!open) setScreen({ id: "root" });
+ }, [open]);
+
+ const back = () => setScreen({ id: "root" });
+
+ const renderItem = (item: AccountMenuItem) => {
+ switch (item.kind) {
+ case "link":
+ return (
+ <PrefetchLink to={item.to!} className={sheetRowClassName}>
+ <SheetRowContent
+ icon={item.icon}
+ label={item.label}
+ trailing="drill"
+ />
+ </PrefetchLink>
+ );
+ case "external":
+ return (
+ <a
+ href={item.to}
+ target="_blank"
+ rel="noreferrer"
+ className={sheetRowClassName}
+ >
+ <SheetRowContent
+ icon={item.icon}
+ label={item.label}
+ trailing="external"
+ />
+ </a>
+ );
+ case "mode":
+ return (
+ <div className="flex min-h-12 items-center gap-3 px-3">
+ <SheetRowContent icon={item.icon} label={item.label} />
+ <div
+ role="radiogroup"
+ aria-label={t`Appearance`}
+ className="flex shrink-0 rounded-lg bg-muted p-0.5"
+ >
+ {menu.modeOptions.map((option) => {
+ const selected = menu.modePreference === option.value;
+ return (
+ <button
+ key={option.value}
+ type="button"
+ role="radio"
+ aria-checked={selected}
+ onClick={() => menu.onModeChange(option.value)}
+ className={cn(
+ "hit-area flex h-9 min-w-11 items-center justify-center rounded-md px-2 text-sm text-muted-foreground",
+ selected &&
+ "bg-background text-foreground shadow-button-base"
+ )}
+ >
+ {option.label}
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ );
+ case "submenu":
+ return (
+ <SheetRowButton
+ onClick={() => setScreen({ id: "submenu", item })}
+ disabled={
+ item.id === "language" && menu.localeFetcher.state !== "idle"
+ }
+ >
+ <SheetRowContent
+ icon={item.icon}
+ label={item.label}
+ trailing="drill"
+ />
+ </SheetRowButton>
+ );
+ case "action":
+ if (item.id === "signOut") {
+ return (
+ <Form method="post" action={path.to.logout}>
+ <SheetRowButton type="submit">
+ <SheetRowContent icon={item.icon} label={item.label} />
+ </SheetRowButton>
+ </Form>
+ );
+ }
+ return (
+ <SheetRowButton onClick={menu.itarDisclosure.onOpen}>
+ <SheetRowContent icon={item.icon} label={item.label} />
+ </SheetRowButton>
+ );
+ }
+ };
+
+ const renderSubmenu = (item: AccountMenuItem): ReactNode => {
+ if (item.id === "theme") {
+ return themes.map((theme) => (
+ <SheetRowButton
+ key={theme.name}
+ onClick={() => menu.onThemeChange(theme.name)}
+ >
+ <span
+ className="size-5 shrink-0 rounded-full"
+ style={{
+ background: `hsl(${theme.activeColor[mode === "dark" ? "dark" : "light"]})`
+ }}
+ />
+ <SheetRowContent
+ label={theme.label}
+ trailing={menu.optimisticTheme === theme.name ? "check" : null}
+ />
+ </SheetRowButton>
+ ));
+ }
+ if (item.id === "language") {
+ return (
+ <menu.localeFetcher.Form method="post" action="/api/locale">
+ {menu.languageOptions.map((option) => (
+ <SheetRowButton
+ key={option.value}
+ type="submit"
+ name="locale"
+ value={option.value}
+ disabled={
+ menu.localeFetcher.state !== "idle" ||
+ option.value === menu.resolvedLocale
+ }
+ className="disabled:opacity-100"
+ >
+ <SheetRowContent
+ label={option.label}
+ trailing={option.value === menu.resolvedLocale ? "check" : null}
+ />
+ </SheetRowButton>
+ ))}
+ </menu.localeFetcher.Form>
+ );
+ }
+ return item.children?.map((child) => (
+ <a key={child.id} href={child.to} className={sheetRowClassName}>
+ <SheetRowContent
+ icon={child.icon}
+ label={child.label}
+ trailing="external"
+ />
+ </a>
+ ));
+ };
+
+ const title =
+ screen.id === "notifications" ? (
+ <Trans>Notifications</Trans>
+ ) : screen.id === "companies" ? (
+ <Trans>Switch company</Trans>
+ ) : screen.id === "submenu" ? (
+ screen.item.label
+ ) : (
+ <Trans>Profile</Trans>
+ );
+
+ return (
+ <>
+ <BottomSheet open={open} onOpenChange={onOpenChange}>
+ <BottomSheetContent>
+ <BottomSheetHeader>
+ {screen.id !== "root" && <BottomSheetBack onClick={back} />}
+ <BottomSheetTitle>{title}</BottomSheetTitle>
+ </BottomSheetHeader>
+ <BottomSheetBody
+ className={cn("px-2", screen.id === "notifications" && "px-0")}
+ >
+ {screen.id === "root" && (
+ <>
+ <div className="flex items-center gap-3 px-3 pb-3">
+ <Avatar path={menu.user.avatarUrl} name={menu.name} />
+ <span className="min-w-0 truncate text-sm text-muted-foreground">
+ {menu.signedInAs}
+ </span>
+ </div>
+ <SheetRowGroup>
+ <SheetRowButton
+ onClick={() => setScreen({ id: "notifications" })}
+ >
+ <SheetRowContent
+ icon={<LuBell />}
+ label={<Trans>Notifications</Trans>}
+ detail={unread > 0 ? unread : undefined}
+ trailing="drill"
+ />
+ </SheetRowButton>
+ {companyCount > 1 && (
+ <SheetRowButton
+ onClick={() => setScreen({ id: "companies" })}
+ >
+ <SheetRowContent
+ icon={<LuBuilding2 />}
+ label={<Trans>Switch company</Trans>}
+ detail={user.company.name}
+ trailing="drill"
+ />
+ </SheetRowButton>
+ )}
+ </SheetRowGroup>
+ {groupItems(menu.items).map((group) => (
+ <SheetRowGroup key={group[0]!.group}>
+ {group.map((item) => (
+ <Fragment key={item.id}>{renderItem(item)}</Fragment>
+ ))}
+ </SheetRowGroup>
+ ))}
+ </>
+ )}
+ {screen.id === "submenu" && renderSubmenu(screen.item)}
+ {screen.id === "notifications" && (
+ <NotificationsPanel
+ isOpen={open}
+ onClose={() => onOpenChange(false)}
+ activeTab={notificationsTab}
+ onActiveTabChange={setNotificationsTab}
+ notifications={notifications}
+ />
+ )}
+ {screen.id === "companies" &&
+ companyGroups.map((group) => (
+ <SheetRowGroup key={group.name}>
+ <SheetSectionLabel>{group.name}</SheetSectionLabel>
+ {group.companies.map((company) => {
+ const logo =
+ mode === "dark"
+ ? company.logoDarkIcon
+ : company.logoLightIcon;
+ const isCurrent = company.companyId === user.company.id;
+ return (
+ <Form
+ key={company.companyId}
+ method="post"
+ action={path.to.companySwitch(company.companyId!)}
+ >
+ {switchRedirect && (
+ <input
+ type="hidden"
+ name="redirectTo"
+ value={switchRedirect}
+ />
+ )}
+ <SheetRowButton
+ type="submit"
+ disabled={isCurrent}
+ className="disabled:opacity-100"
+ >
+ <AvatarBase
+ size="xs"
+ name={company.name ?? undefined}
+ src={logo ?? undefined}
+ />
+ <SheetRowContent
+ label={company.name}
+ detail={company.employeeType}
+ trailing={isCurrent ? "check" : null}
+ />
+ </SheetRowButton>
+ </Form>
+ );
+ })}
+ </SheetRowGroup>
+ ))}
+ </BottomSheetBody>
+ </BottomSheetContent>
+ </BottomSheet>
+ {CONTROLLED_ENVIRONMENT && (
+ <ItarDisclosure disclosure={menu.itarDisclosure} />
+ )}
+ </>
+ );
+}
diff --cc apps/erp/app/components/Layout/Topbar/Notifications.tsx
index 0916fe9a10,07e5fd8817..ac591498d6
--- a/apps/erp/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
@@@ -652,42 -655,39 +655,50 @@@ function DigestNotification(
);
}
-const Notifications = () => {
- const { t } = useLingui();
- const {
- id: userId,
- company: { id: companyId }
- } = useUser();
- const pushPublicKey =
++export function usePushPublicKey() {
++ return (
+ useRouteData<{ pushPublicKey: string | null }>(path.to.authenticatedRoot)
- ?.pushPublicKey ?? null;
- // The bell is always mounted, so it is where a signed-back-in user's
- // browser notifications come back.
- useRestoreBrowserNotifications({ publicKey: pushPublicKey, userId });
- const [isOpen, setOpen] = useState(false);
- const [activeTab, setActiveTab] = useState("inbox");
- // Loaded when the tab is opened, and again each time the popover reopens.
- const trainingsFetcher = useLoaderQuery<{ data: OutstandingTraining[] }>(
- isOpen && activeTab === "trainings"
- ? path.to.api.outstandingTrainings
- : null,
- { staleTime: 0 }
++ ?.pushPublicKey ?? null
+ );
++}
+
- const {
+/**
+ * The notification tabs (Inbox, Trainings, Archive). The desktop bell
+ * popover and the compact Profile sheet's Notifications drill-in both
+ * render it; the caller owns `useNotifications` so the unread badge and the
+ * panel share one subscription.
+ */
+export function NotificationsPanel({
+ isOpen,
+ onClose,
+ activeTab,
+ onActiveTabChange,
+ notifications: {
fetchDigestChildren,
hasUnseenNotifications,
notifications,
markMessageAsRead,
markAllMessagesAsSeen,
markAllMessagesAsRead
- } = useNotifications({
- companyId,
- userId
- });
+ }
+}: {
+ isOpen: boolean;
+ onClose: () => void;
+ /** Owned by the caller: the desktop popover unmounts the panel on close
+ * and reopens on the last tab. */
+ activeTab: string;
+ onActiveTabChange: (tab: string) => void;
+ notifications: ReturnType<typeof useNotifications>;
+}) {
+ const { t } = useLingui();
++ const pushPublicKey = usePushPublicKey();
+ // Loaded when the tab is opened, and again each time the popover reopens.
+ const trainingsFetcher = useLoaderQuery<{ data: OutstandingTraining[] }>(
+ isOpen && activeTab === "trainings"
+ ? path.to.api.outstandingTrainings
+ : null,
+ { staleTime: 0 }
+ );
const unreadNotifications = notifications.filter(
(notification) => !notification.read
@@@ -707,189 -707,6 +718,196 @@@
const outstandingTrainings = trainingsFetcher.data?.data ?? [];
const isLoadingTrainings = trainingsFetcher.isFetching;
+ return (
+ <Tabs
+ defaultValue="inbox"
+ value={activeTab}
+ onValueChange={onActiveTabChange}
+ >
+ <TabsList className="w-full border-b py-2 rounded-none bg-muted/50">
+ <TabsTrigger value="inbox" className="font-normal">
+ <Trans>Inbox</Trans>
+ </TabsTrigger>
+ <TabsTrigger value="trainings" className="font-normal">
+ <Trans>Trainings</Trans>
+ </TabsTrigger>
+ <TabsTrigger value="archive" className="font-normal">
+ <Trans>Archive</Trans>
+ </TabsTrigger>
+ </TabsList>
+
+ {/* <Link
+ to={path.to.notificationSettings}
+ className="absolute right-[11px] top-1.5"
+ >
+ <IconButton
+ aria-label={t`Settings`}
+ icon={<LuSettings />}
+ variant="ghost"
+ isIcon
+ className="rounded-full"
+ onClick={() => onClose()}
+ />
+ </Link> */}
+
+ <TabsContent value="inbox" className="relative mt-0">
+ {!unreadNotifications.length && (
- <EmptyState description={t`No new notifications`} />
++ <>
++ <EnableBrowserNotifications publicKey={pushPublicKey} />
++ <EmptyState description={t`No new notifications`} />
++ </>
+ )}
+
+ {unreadNotifications.length > 0 && (
+ <ScrollArea className="pb-12 h-[485px] max-md:h-auto">
++ <EnableBrowserNotifications publicKey={pushPublicKey} />
+ <div className="divide-y">
+ {unreadNotifications.map((notification) => {
+ const event = notification.payload.event as NotificationEvent;
+ if (event === NotificationEvent.Digest) {
+ return (
+ <DigestNotification
+ key={notification._id}
+ id={notification._id}
+ description={notification.payload.description as string}
+ markMessageAsRead={() =>
+ markMessageAsRead(notification._id)
+ }
+ onClose={() => onClose()}
+ fetchChildren={fetchDigestChildren}
+ />
+ );
+ }
+ return (
+ <GenericNotification
+ key={notification._id}
+ id={notification.payload.documentId as string}
+ createdAt={notification.createdAt}
+ description={notification.payload.description as string}
+ body={getNotificationBody(notification.payload, event)}
+ event={event}
+ from={notification.payload.from as string | undefined}
+ documentType={
+ notification.payload.documentType as
+ | ApprovalDocumentType
+ | undefined
+ }
+ markMessageAsRead={() =>
+ markMessageAsRead(notification._id)
+ }
+ onClose={() => onClose()}
+ />
+ );
+ })}
+ </div>
+ </ScrollArea>
+ )}
+
+ {unreadNotifications.length > 0 && (
+ <div className="h-12 w-full absolute bottom-0 flex items-center justify-center border-t">
+ <Button
+ variant="secondary"
+ className="bg-transparent"
+ onClick={markAllMessagesAsRead}
+ >
+ <Trans>Archive all</Trans>
+ </Button>
+ </div>
+ )}
+ </TabsContent>
+
+ <TabsContent value="trainings" className="mt-0">
+ {isLoadingTrainings && (
+ <div className="h-[460px] max-md:h-auto max-md:py-16 flex items-center justify-center">
+ <Spinner />
+ </div>
+ )}
+
+ {!isLoadingTrainings && outstandingTrainings.length === 0 && (
+ <EmptyState description={t`No outstanding trainings`} />
+ )}
+
+ {!isLoadingTrainings && outstandingTrainings.length > 0 && (
+ <ScrollArea className="h-[490px] max-md:h-auto">
+ <div className="divide-y">
+ {outstandingTrainings.map((training) => (
+ <TrainingItem
+ key={training.trainingAssignmentId}
+ training={training}
+ onClose={() => onClose()}
+ />
+ ))}
+ </div>
+ </ScrollArea>
+ )}
+ </TabsContent>
+
+ <TabsContent value="archive" className="mt-0">
+ {!archivedNotifications.length && (
+ <EmptyState description={t`Nothing in the archive`} />
+ )}
+
+ {archivedNotifications.length > 0 && (
+ <ScrollArea className="h-[490px] max-md:h-auto">
+ <div className="divide-y">
+ {archivedNotifications.map((notification) => {
+ const event = notification.payload.event as NotificationEvent;
+ if (event === NotificationEvent.Digest) {
+ return (
+ <DigestNotification
+ key={notification._id}
+ id={notification._id}
+ description={notification.payload.description as string}
+ onClose={() => onClose()}
+ fetchChildren={fetchDigestChildren}
+ />
+ );
+ }
+ return (
+ <GenericNotification
+ key={notification._id}
+ id={notification.payload.documentId as string}
+ createdAt={notification.createdAt}
+ description={notification.payload.description as string}
+ body={getNotificationBody(notification.payload, event)}
+ event={event}
+ from={notification.payload.from as string | undefined}
+ documentType={
+ notification.payload.documentType as
+ | ApprovalDocumentType
+ | undefined
+ }
+ onClose={() => onClose()}
+ />
+ );
+ })}
+ </div>
+ </ScrollArea>
+ )}
+ </TabsContent>
+ </Tabs>
+ );
+}
+
+const Notifications = () => {
+ const {
+ id: userId,
+ company: { id: companyId }
+ } = useUser();
++ // The bell is always mounted on desktop (the Profile sheet is on phones), so
++ // it is where a signed-back-in user's browser notifications come back.
++ useRestoreBrowserNotifications({ publicKey: usePushPublicKey(), userId });
+ const [isOpen, setOpen] = useState(false);
+ const [activeTab, setActiveTab] = useState("inbox");
+ const notificationsState = useNotifications({
+ companyId,
+ userId
+ });
+
+ const unreadNotifications = notificationsState.notifications.filter(
+ (notification) => !notification.read
+ );
+
return (
<Popover onOpenChange={setOpen} open={isOpen}>
<PopoverTrigger asChild>
diff --cc packages/jobs/manifests/schema.json
index cfd4c4e056,4ace66adbc..b961105847
--- a/packages/jobs/manifests/schema.json
+++ b/packages/jobs/manifests/schema.json
@@@ -1,11 -1,11 +1,11 @@@
{
"kind": "carbon-company-backup",
"version": 1,
-- "schemaVersion": "20261009141827",
++ "schemaVersion": "20261009163952",
"sourceCompanyId": "schema-baseline",
"sourceCompanyGroupId": null,
"sourceCompanyName": null,
-- "exportedAt": "2026-10-09T07:57:25.150Z",
++ "exportedAt": "2026-10-09T15:41:38.767Z",
"exportedBy": "schema-baseline",
"label": "schema baseline",
"includeStorage": "none",