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: company switcher on mobile

Brad Barbin9a9cbdeb3dde
diff --git a/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx b/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
index fbd4828b72..228b484e37 100644
--- a/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
@@ -76,7 +76,7 @@ const Breadcrumbs = () => {
const logo = mode === "dark" ? company?.logoDarkIcon : company?.logoLightIcon;
return (
- <HStack className="items-center h-full -ml-2" spacing={0}>
+ <HStack className="items-center h-full hidden md:flex -ml-2" spacing={0}>
<Button isIcon asChild variant="ghost" size="lg">
<Link to="/">
{logo ? (
diff --git a/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx b/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx
new file mode 100644
index 0000000000..7df8ada44b
--- /dev/null
+++ b/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx
@@ -0,0 +1,133 @@
+import {
+ Avatar,
+ Badge,
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuItem,
+ DropdownMenuIcon,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ HStack,
+} from "@carbon/react";
+import { useMode } from "@carbon/remix";
+import { Form, Link } from "@remix-run/react";
+import { BsFillHexagonFill } from "react-icons/bs";
+import { LuChevronsUpDown, LuHouse } from "react-icons/lu";
+import { useRouteData, useUser } from "~/hooks";
+import type { Company } from "~/modules/settings";
+import { path } from "~/utils/path";
+
+const CompanySwitcher = () => {
+ const routeData = useRouteData<{ company: Company; companies: Company[] }>(
+ path.to.authenticatedRoot
+ );
+ const user = useUser();
+ const mode = useMode();
+
+ const hasMultipleCompanies = Boolean(
+ routeData?.companies && routeData?.companies.length > 1
+ );
+
+ const canSwitchCompany = hasMultipleCompanies;
+
+ if (!canSwitchCompany) {
+ // Just show the company logo without dropdown
+ const logo =
+ mode === "dark"
+ ? user.company?.logoDarkIcon
+ : user.company?.logoLightIcon;
+
+ return (
+ <Button isIcon asChild variant="ghost" size="lg">
+ <Link to="/">
+ {logo ? (
+ <img
+ src={logo}
+ alt={`${user.company.name} logo`}
+ className="w-full h-auto rounded"
+ />
+ ) : (
+ <BsFillHexagonFill />
+ )}
+ </Link>
+ </Button>
+ );
+ }
+
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
+ className="px-2 focus-visible:ring-transparent"
+ rightIcon={<LuChevronsUpDown />}
+ >
+ {(() => {
+ const logo =
+ mode === "dark"
+ ? user.company?.logoDarkIcon
+ : user.company?.logoLightIcon;
+ return logo ? (
+ <img
+ src={logo}
+ alt={`${user.company.name} logo`}
+ className="w-full h-auto rounded"
+ />
+ ) : (
+ <BsFillHexagonFill />
+ );
+ })()}
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="min-w-[240px]">
+ <DropdownMenuItem asChild>
+ <Link to={path.to.dashboard}>
+ <DropdownMenuIcon icon={<LuHouse />} />
+ Dashboard
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuLabel>Companies</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ <DropdownMenuGroup>
+ {routeData?.companies.map((c) => {
+ const logo = mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
+ const isCurrent = c.companyId === user.company.id;
+
+ return (
+ <Form
+ key={c.companyId}
+ method="post"
+ action={path.to.companySwitch(c.companyId!)}
+ >
+ <DropdownMenuItem
+ className="flex items-center justify-between w-full"
+ asChild
+ disabled={isCurrent}
+ >
+ <button type="submit">
+ <HStack>
+ <Avatar
+ size="xs"
+ name={c.name ?? undefined}
+ src={logo ?? undefined}
+ />
+ <span>{c.name}</span>
+ </HStack>
+ <Badge variant="secondary" className="ml-2">
+ {c.employeeType}
+ </Badge>
+ </button>
+ </DropdownMenuItem>
+ </Form>
+ );
+ })}
+ </DropdownMenuGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+};
+
+export default CompanySwitcher;
diff --git a/apps/erp/app/components/Layout/Topbar/Topbar.tsx b/apps/erp/app/components/Layout/Topbar/Topbar.tsx
index 319cdac090..242aaf1e82 100644
--- a/apps/erp/app/components/Layout/Topbar/Topbar.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Topbar.tsx
@@ -1,9 +1,9 @@
import { HStack, IconButton } from "@carbon/react";
import { LuSquarePen } from "react-icons/lu";
import { usePermissions, useUser } from "~/hooks";
-import { useFlags } from "~/hooks/useFlags";
import AvatarMenu from "../../AvatarMenu";
import Breadcrumbs from "./Breadcrumbs";
+import CompanySwitcher from "./CompanySwitcher";
import CreateMenu from "./CreateMenu";
import Feedback from "./Feedback";
import Notifications from "./Notifications";
@@ -14,14 +14,14 @@ const Topbar = () => {
const user = useUser();
const notificationsKey = `${user.id}:${user.company.id}`;
- const { isInternal, isControlledEnvironment } = useFlags();
- const canAccessAgent = isInternal && !isControlledEnvironment;
-
return (
<div className="h-[49px] grid grid-cols-[1fr_200px_1fr] bg-background text-foreground px-4 top-0 sticky z-10 items-center">
- <div className="flex-1">
+ <div className="flex-1 hidden md:block">
<Breadcrumbs />
</div>
+ <div className="flex-1 md:hidden">
+ <CompanySwitcher />
+ </div>
<div className="flex justify-center">
{permissions.is("employee") ? <Search /> : <div />}
</div>
@@ -38,6 +38,7 @@ const Topbar = () => {
/>
<Notifications key={notificationsKey} />
+
<AvatarMenu />
</HStack>
</div>