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.

style: developers site layout

Brad Barbin0fc5ffae8c25
diff --git a/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx b/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
index 9fa2389860..ae032e88ab 100644
--- a/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
@@ -13,6 +13,7 @@ import {
toast,
VStack,
} from "@carbon/react";
+import { SUPPORT_EMAIL } from "@carbon/utils";
import { useParams } from "@remix-run/react";
import { usePermissions } from "~/hooks";
import { integrations as availableIntegrations } from "~/integrations";
@@ -122,7 +123,10 @@ export function IntegrationForm({
software.Report any concerns about app content or behavior.
</p>
- <a href="mailto:[email protected]" className="text-sm text-red-500">
+ <a
+ href={`mailto:${SUPPORT_EMAIL}`}
+ className="text-sm text-red-500"
+ >
Report integration
</a>
</DrawerBody>
diff --git a/apps/developers/app/components/Breadcrumbs.tsx b/apps/developers/app/components/Breadcrumbs.tsx
new file mode 100644
index 0000000000..b40ff26794
--- /dev/null
+++ b/apps/developers/app/components/Breadcrumbs.tsx
@@ -0,0 +1,86 @@
+import { Button, cn, getValidChildren } from "@carbon/react";
+import type { LinkProps } from "@remix-run/react";
+import { Link } from "@remix-run/react";
+import type { ComponentProps } from "react";
+import { cloneElement, forwardRef } from "react";
+import { LuChevronRight } from "react-icons/lu";
+
+const Breadcrumbs = forwardRef<
+ HTMLElement,
+ ComponentProps<"nav"> & {
+ useReactRouter?: boolean;
+ }
+>(({ className, children, useReactRouter = true, ...props }, ref) => {
+ const validChildren = getValidChildren(children);
+ const count = validChildren.length;
+ const clones = validChildren.map((child, index) =>
+ cloneElement(child, {
+ isFirstChild: index === 0,
+ isLastChild: index === count - 1,
+ })
+ );
+ return (
+ <nav
+ aria-label="Breadcrumb"
+ ref={ref}
+ className={cn("reset flex", className)}
+ {...props}
+ >
+ <ol className="inline-flex items-center space-x-1">{clones}</ol>
+ </nav>
+ );
+});
+Breadcrumbs.displayName = "Breadcrumbs";
+
+const BreadcrumbItem = forwardRef<
+ HTMLLIElement,
+ ComponentProps<"li"> & {
+ isFirstChild?: boolean;
+ isLastChild?: boolean;
+ }
+>(({ className, children, isFirstChild, isLastChild, ...props }, ref) => (
+ <li
+ ref={ref}
+ className={cn("inline-flex items-center", className)}
+ {...props}
+ >
+ {!isFirstChild && (
+ <span className="text-muted-foreground">
+ <LuChevronRight />
+ </span>
+ )}
+ {children}
+ </li>
+));
+BreadcrumbItem.displayName = "BreadcrumbItem";
+
+const BreadcrumbLink = forwardRef<
+ HTMLAnchorElement,
+ LinkProps & {
+ isCurrentPage?: boolean;
+ }
+>(({ className, children, isCurrentPage, ...props }, ref) => {
+ return (
+ <Button
+ variant="ghost"
+ className={cn(
+ "px-2 outline-none focus-visible:ring-transparent",
+ className
+ )}
+ asChild
+ >
+ {isCurrentPage ? (
+ <span aria-current="page" ref={ref} {...props}>
+ {children}
+ </span>
+ ) : (
+ <Link ref={ref} {...props} prefetch="intent">
+ {children}
+ </Link>
+ )}
+ </Button>
+ );
+});
+BreadcrumbLink.displayName = "BreadcrumbLink";
+
+export { BreadcrumbItem, BreadcrumbLink, Breadcrumbs };
diff --git a/apps/developers/app/components/PrimaryNavigation.tsx b/apps/developers/app/components/PrimaryNavigation.tsx
index 46ed6efba1..cab7d14abe 100644
--- a/apps/developers/app/components/PrimaryNavigation.tsx
+++ b/apps/developers/app/components/PrimaryNavigation.tsx
@@ -1,164 +1,7 @@
-import { Button, VStack, cn, useDisclosure } from "@carbon/react";
-import { Link, useMatches } from "@remix-run/react";
-import { noop } from "@tanstack/react-table";
-import type { AnchorHTMLAttributes } from "react";
-import { forwardRef } from "react";
-import type { IconType } from "react-icons";
-import { BsFillHexagonFill } from "react-icons/bs";
-import { z } from "zod";
-import { useOptimisticLocation, useUser } from "~/hooks";
-
-export const ModuleHandle = z.object({
- module: z.string(),
-});
-
-type NavLink = {
- to: string;
- icon: IconType;
- name: string;
-};
-
-const links: NavLink[] = [];
-
const PrimaryNavigation = () => {
- const { company } = useUser();
-
- const navigationPanel = useDisclosure();
- const location = useOptimisticLocation();
- const currentModule = getModule(location.pathname);
-
- const matchedModules = useMatches().reduce((acc, match) => {
- if (match.handle) {
- const result = ModuleHandle.safeParse(match.handle);
- if (result.success) {
- acc.add(result.data.module);
- }
- }
-
- return acc;
- }, new Set<string>());
-
return (
- <div className="w-14 h-full flex-col z-50 hidden sm:flex">
- <nav
- data-state={navigationPanel.isOpen ? "expanded" : "collapsed"}
- className={cn(
- "bg-background group py-2 z-10 h-full w-14 data-[state=expanded]:w-[13rem]",
- "border-r border-border data-[state=expanded]:shadow-xl",
- "transition-width duration-200",
- "hide-scrollbar flex flex-col justify-between overflow-y-auto"
- )}
- onMouseEnter={navigationPanel.onOpen}
- onMouseLeave={navigationPanel.onClose}
- >
- <VStack
- spacing={1}
- className="flex flex-col justify-between h-full px-2"
- >
- <VStack spacing={1}>
- <Button isIcon asChild variant="ghost" size="lg">
- <Link to="/">
- {company?.logo ? (
- <img
- src={company.logo}
- alt={`${company.name} logo`}
- className="w-full h-auto rounded"
- />
- ) : (
- <BsFillHexagonFill />
- )}
- </Link>
- </Button>
- {links.map((link) => {
- const m = getModule(link.to);
-
- const moduleMatches = matchedModules.has(m);
-
- const isActive = currentModule === m || moduleMatches;
- return (
- <NavigationIconLink
- key={link.name}
- link={link}
- isActive={isActive}
- isOpen={navigationPanel.isOpen}
- onClick={navigationPanel.onClose}
- />
- );
- })}
- </VStack>
- </VStack>
- </nav>
- </div>
+ <aside className="flex flex-col h-full w-[210px] bg-background"></aside>
);
};
-interface NavigationIconButtonProps
- extends AnchorHTMLAttributes<HTMLAnchorElement> {
- link: NavLink;
- isActive?: boolean;
- isOpen?: boolean;
-}
-
-const NavigationIconLink = forwardRef<
- HTMLAnchorElement,
- NavigationIconButtonProps
->(
- (
- { link, isActive = false, isOpen = false, onClick = noop, ...props },
- ref
- ) => {
- const iconClasses = [
- "absolute left-3 top-3 flex rounded-md items-center justify-center",
- // Layout and sizing
- ];
-
- const classes = [
- "group relative",
- "h-10 w-10 group-data-[state=expanded]:w-full",
- "transition-all duration-200",
- "flex items-center rounded-md",
- "group-data-[state=collapsed]:justify-center",
- "group-data-[state=expanded]:-space-x-2",
- "hover:bg-active/80 hover:text-active-foreground",
- `${
- isActive
- ? "bg-active text-active-foreground shadow-sm hover:text-active-foreground hover:bg-active/90"
- : "hover:text-active-foreground"
- }`,
- "group/item",
- ];
-
- return (
- <Link
- role="button"
- aria-current={isActive}
- ref={ref}
- to={link.to}
- {...props}
- onClick={onClick}
- className={cn(classes, props.className)}
- prefetch="intent"
- >
- <link.icon className={cn(...iconClasses)} />
-
- <span
- aria-hidden={isOpen || undefined}
- className={cn(
- "min-w-[128px] text-sm",
- "absolute left-7 group-data-[state=expanded]:left-12",
- "opacity-0 group-data-[state=expanded]:opacity-100"
- )}
- >
- {link.name}
- </span>
- </Link>
- );
- }
-);
-NavigationIconLink.displayName = "NavigationIconLink";
-
export default PrimaryNavigation;
-
-function getModule(link: string) {
- return link.split("/")?.[2];
-}
diff --git a/apps/developers/app/components/Topbar/AvatarMenu.tsx b/apps/developers/app/components/Topbar/AvatarMenu.tsx
index 5ad274418d..4268d31107 100644
--- a/apps/developers/app/components/Topbar/AvatarMenu.tsx
+++ b/apps/developers/app/components/Topbar/AvatarMenu.tsx
@@ -6,34 +6,87 @@ import {
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
+ Switch,
} from "@carbon/react";
-import { Form } from "@remix-run/react";
-import { LuLogOut } from "react-icons/lu";
+import { Form, Link, useFetcher } from "@remix-run/react";
+import { useRef, useState } from "react";
+import { LuHome, LuLogOut, LuMoon, LuSun, LuUser } from "react-icons/lu";
import { Avatar } from "~/components";
import { useUser } from "~/hooks";
+import { useMode } from "~/hooks/useMode";
+import type { action } from "~/root";
import { path } from "~/utils/path";
const AvatarMenu = () => {
const user = useUser();
const name = `${user.firstName} ${user.lastName}`;
+ const mode = useMode();
+
+ const nextMode = mode === "dark" ? "light" : "dark";
+ const modeSubmitRef = useRef<HTMLButtonElement>(null);
+
+ const fetcher = useFetcher<typeof action>();
+ const [isOpen, setIsOpen] = useState(false);
+
return (
- <DropdownMenu>
+ <DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenuTrigger className="outline-none focus-visible:outline-none">
<Avatar path={user.avatarUrl} name={name} />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
<DropdownMenuLabel>Signed in as {name}</DropdownMenuLabel>
<DropdownMenuSeparator />
-
- <Form method="post" action={path.to.logout}>
- <DropdownMenuItem asChild>
- <button type="submit" className="w-full">
+ <DropdownMenuItem asChild>
+ <Link to={path.to.dashboard}>
+ <DropdownMenuIcon icon={<LuHome />} />
+ Dashboard
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem asChild>
+ <Link to={path.to.accountSettings}>
+ <DropdownMenuIcon icon={<LuUser />} />
+ Account Settings
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onSelect={(e) => e.preventDefault()}>
+ <div className="flex items-center justify-between w-full">
+ <div className="flex items-center justify-start">
+ <DropdownMenuIcon
+ icon={mode === "dark" ? <LuMoon /> : <LuSun />}
+ />
+ Dark Mode
+ </div>
+ <div>
+ <Switch
+ checked={mode === "dark"}
+ onCheckedChange={() => modeSubmitRef.current?.click()}
+ />
+ <fetcher.Form
+ action={path.to.root}
+ method="post"
+ onSubmit={() => {
+ document.body.removeAttribute("style");
+ }}
+ className="sr-only"
+ >
+ <input type="hidden" name="mode" value={nextMode} />
+ <button ref={modeSubmitRef} className="sr-only" type="submit" />
+ </fetcher.Form>
+ </div>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onSelect={(e) => e.preventDefault()}>
+ <Form method="post" action={path.to.logout}>
+ <button type="submit" className="w-full flex items-center">
<DropdownMenuIcon icon={<LuLogOut />} />
<span>Sign Out</span>
</button>
- </DropdownMenuItem>
- </Form>
+ </Form>
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
diff --git a/apps/developers/app/components/Topbar/Breadcrumbs.tsx b/apps/developers/app/components/Topbar/Breadcrumbs.tsx
new file mode 100644
index 0000000000..1ac9f69e61
--- /dev/null
+++ b/apps/developers/app/components/Topbar/Breadcrumbs.tsx
@@ -0,0 +1,157 @@
+import type { Company } from "@carbon/auth";
+import {
+ Avatar,
+ Badge,
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ HStack,
+ useWindowSize,
+} from "@carbon/react";
+import { Form, Link, useMatches } from "@remix-run/react";
+import { BsFillHexagonFill } from "react-icons/bs";
+import { LuChevronsUpDown } from "react-icons/lu";
+import { z } from "zod";
+import {
+ BreadcrumbItem,
+ BreadcrumbLink,
+ Breadcrumbs as BreadcrumbsBase,
+} from "~/components/Breadcrumbs";
+
+import { useRouteData } from "~/hooks";
+import { path } from "~/utils/path";
+
+export const BreadcrumbHandle = z.object({
+ breadcrumb: z.any(),
+ to: z.string().optional(),
+});
+export type BreadcrumbHandleType = z.infer<typeof BreadcrumbHandle>;
+
+const BreadcrumbHandleMatch = z.object({
+ handle: BreadcrumbHandle,
+});
+
+const Breadcrumbs = () => {
+ const matches = useMatches();
+
+ const breadcrumbs = matches
+ .map((m) => {
+ const result = BreadcrumbHandleMatch.safeParse(m);
+ if (!result.success || !result.data.handle.breadcrumb) return null;
+
+ return {
+ breadcrumb: result.data.handle.breadcrumb,
+ to: result.data.handle?.to ?? m.pathname,
+ };
+ })
+ .filter(Boolean);
+
+ const { width } = useWindowSize();
+
+ return (
+ <HStack className="items-center h-full -ml-2" spacing={0}>
+ <BreadcrumbsBase className="line-clamp-1">
+ {width && width <= 640 ? (
+ <BreadcrumbItem>
+ <Button isIcon asChild variant="ghost">
+ <Link to="/">
+ <BsFillHexagonFill />
+ </Link>
+ </Button>
+ </BreadcrumbItem>
+ ) : (
+ <CompanyBreadcrumb />
+ )}
+ {breadcrumbs.map((breadcrumb, i) => (
+ <BreadcrumbItem key={i}>
+ <BreadcrumbLink
+ isCurrentPage={!breadcrumb?.to}
+ to={breadcrumb?.to ?? ""}
+ >
+ {breadcrumb?.breadcrumb}
+ </BreadcrumbLink>
+ </BreadcrumbItem>
+ ))}
+ </BreadcrumbsBase>
+ </HStack>
+ );
+};
+
+function CompanyBreadcrumb() {
+ const routeData = useRouteData<{ company: Company; companies: Company[] }>(
+ path.to.authenticatedRoot
+ );
+
+ const hasMultipleCompanies = Boolean(
+ routeData?.companies && routeData?.companies.length > 1
+ );
+
+ const hasCompanyMenu = hasMultipleCompanies;
+
+ return (
+ <>
+ <BreadcrumbItem isFirstChild>
+ <BreadcrumbLink to="/">Developers</BreadcrumbLink>
+ </BreadcrumbItem>
+ <BreadcrumbItem>
+ {hasCompanyMenu ? (
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ aria-current="page"
+ variant="ghost"
+ className="px-2 focus-visible:ring-transparent"
+ rightIcon={<LuChevronsUpDown />}
+ >
+ {routeData?.company.name}
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="min-w-[240px]">
+ <DropdownMenuLabel>Companies</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ <DropdownMenuGroup>
+ {routeData?.companies.map((c) => (
+ <Form
+ key={c.companyId}
+ method="post"
+ action={path.to.companySwitch(c.companyId!)}
+ >
+ <DropdownMenuItem
+ className="flex items-center justify-between w-full"
+ asChild
+ >
+ <button type="submit">
+ <HStack>
+ <Avatar
+ size="xs"
+ name={c.name ?? undefined}
+ src={c.logo ?? undefined}
+ />
+ <span>{c.name}</span>
+ </HStack>
+ <Badge variant="secondary" className="ml-2">
+ {c.employeeType}
+ </Badge>
+ </button>
+ </DropdownMenuItem>
+ </Form>
+ ))}
+ </DropdownMenuGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </>
+ ) : (
+ <BreadcrumbLink to="/">{routeData?.company.name}</BreadcrumbLink>
+ )}
+ </BreadcrumbItem>
+ </>
+ );
+}
+
+export default Breadcrumbs;
diff --git a/apps/developers/app/components/Topbar/ModeSwitcher.tsx b/apps/developers/app/components/Topbar/ModeSwitcher.tsx
deleted file mode 100644
index b7ea337ed7..0000000000
--- a/apps/developers/app/components/Topbar/ModeSwitcher.tsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import { IconButton } from "@carbon/react";
-import { useFetcher } from "@remix-run/react";
-import { BiLaptop, BiMoon, BiSun } from "react-icons/bi";
-import { useMode } from "~/hooks/useMode";
-import type { action } from "~/root";
-import { path } from "~/utils/path";
-
-const ModeSwitcher = () => {
- const mode = useMode();
- const nextMode = mode === "dark" ? "light" : "dark";
- const modeLabel = {
- light: <BiSun />,
- dark: <BiMoon />,
- system: <BiLaptop />,
- };
-
- const fetcher = useFetcher<typeof action>();
-
- return (
- <fetcher.Form
- action={path.to.root}
- method="post"
- onSubmit={() => {
- document.body.removeAttribute("style");
- }}
- className="hidden sm:block"
- >
- <input type="hidden" name="mode" value={nextMode} />
-
- <IconButton
- icon={modeLabel[nextMode]}
- aria-label="Light Mode"
- variant="ghost"
- type="submit"
- />
- </fetcher.Form>
- );
-};
-
-export default ModeSwitcher;
diff --git a/apps/developers/app/components/Topbar/Topbar.tsx b/apps/developers/app/components/Topbar/Topbar.tsx
index edc853cde0..1c5c22c90f 100644
--- a/apps/developers/app/components/Topbar/Topbar.tsx
+++ b/apps/developers/app/components/Topbar/Topbar.tsx
@@ -1,15 +1,14 @@
import { HStack } from "@carbon/react";
import AvatarMenu from "./AvatarMenu";
-import ModeSwitcher from "./ModeSwitcher";
+import Breadcrumbs from "./Breadcrumbs";
const Topbar = () => {
return (
- <div className="flex bg-background text-foreground border-b border-border px-4 top-0 sticky z-10 space-x-4 justify-between items-center">
- <span className="font-mono font-bold uppercase">Developers</span>
+ <div className="flex bg-background text-foreground pl-4 pr-2 top-0 sticky z-10 gap-x-4 justify-between items-center">
+ <Breadcrumbs />
<HStack spacing={2} className="justify-end py-2">
- <ModeSwitcher />
<AvatarMenu />
</HStack>
</div>
diff --git a/apps/developers/app/root.tsx b/apps/developers/app/root.tsx
index 7e8e4b5e5c..41f3b936ec 100644
--- a/apps/developers/app/root.tsx
+++ b/apps/developers/app/root.tsx
@@ -111,7 +111,7 @@ function Document({
<title>{title}</title>
<Links />
</head>
- <body className="h-full bg-background antialiased selection:bg-[#00cc9937] selection:text-[#007763fd] dark:selection:bg-[#00fff61d] dark:selection:text-[#67ffded2]">
+ <body className="h-full bg-background antialiased selection:bg-primary/10 selection:text-primary">
{children}
<ScrollRestoration />
diff --git a/apps/developers/app/routes/_public+/login.tsx b/apps/developers/app/routes/_public+/login.tsx
index 87ac9c940b..be3bf13935 100644
--- a/apps/developers/app/routes/_public+/login.tsx
+++ b/apps/developers/app/routes/_public+/login.tsx
@@ -99,7 +99,7 @@ export default function LoginRoute() {
Developers
</h3>
</div>
- <div className="rounded-lg bg-card border border-border shadow-lg p-8 w-[380px]">
+ <div className="p-8 w-[380px]">
<ValidatedForm
validator={loginValidator}
defaultValues={{ redirectTo }}
diff --git a/apps/developers/app/routes/_public+/request-access.tsx b/apps/developers/app/routes/_public+/request-access.tsx
index 04278d8494..53243e924b 100644
--- a/apps/developers/app/routes/_public+/request-access.tsx
+++ b/apps/developers/app/routes/_public+/request-access.tsx
@@ -1,5 +1,6 @@
import { VERCEL_URL } from "@carbon/auth";
import { Button } from "@carbon/react";
+import { SUPPORT_EMAIL } from "@carbon/utils";
import type { MetaFunction } from "@vercel/remix";
export const ERP_URL = VERCEL_URL?.includes("localhost")
@@ -34,7 +35,7 @@ export default function RequestAccessRoute() {
</div>
<div className="rounded-lg bg-card flex flex-col gap-4 border border-border shadow-lg p-8 w-[380px]">
<p>
- Request access to the developer portal by emailing [email protected]
+ Request access to the developer portal by emailing {SUPPORT_EMAIL}
</p>
<Button size="lg" asChild>
<a href={ERP_URL}>Return to App</a>
diff --git a/apps/developers/app/routes/x+/_layout.tsx b/apps/developers/app/routes/x+/_layout.tsx
index 63fcf80407..31745a2aef 100644
--- a/apps/developers/app/routes/x+/_layout.tsx
+++ b/apps/developers/app/routes/x+/_layout.tsx
@@ -86,13 +86,17 @@ export default function AuthenticatedRoute() {
<div className="flex-none" />
<div className="h-screen min-h-[0px] basis-0 flex-1">
<div className="flex h-full">
- <PrimaryNavigation />
<div className="flex w-full h-full">
<div className="w-full h-full flex-1 overflow-hidden">
- <main className="h-full flex flex-col flex-1 max-w-[100vw] sm:max-w-[calc(100vw-56px)] overflow-x-hidden bg-muted">
+ <main className="h-full flex flex-col flex-1 max-w-screen sm:max-w-screen overflow-x-hidden bg-background">
<Topbar />
- <main className="flex-1 overflow-y-auto max-h-[calc(100vh-49px)]">
- <Outlet />
+ <main className="grid grid-cols-[auto_1fr] overflow-hidden h-[calc(100vh-49px)]">
+ <PrimaryNavigation />
+ <main className="flex-1 h-[calc(100vh-49px)] w-full overflow-hidden p-2 pt-0">
+ <div className="flex-1 h-full w-full overflow-y-auto border-border border bg-muted rounded-lg">
+ <Outlet />
+ </div>
+ </main>
</main>
</main>
</div>
diff --git a/apps/developers/app/routes/x+/company.switch.$companyId.tsx b/apps/developers/app/routes/x+/company.switch.$companyId.tsx
new file mode 100644
index 0000000000..81d6ff1e8b
--- /dev/null
+++ b/apps/developers/app/routes/x+/company.switch.$companyId.tsx
@@ -0,0 +1,40 @@
+import { error, getCompanies } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import {
+ destroyAuthSession,
+ flash,
+ updateCompanySession,
+} from "@carbon/auth/session.server";
+import { redirect, type ActionFunctionArgs } from "@vercel/remix";
+
+import { path, requestReferrer } from "~/utils/path";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { client, userId } = await requirePermissions(request, {});
+ const companies = await getCompanies(client, userId);
+
+ if (companies.error) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.authenticatedRoot,
+ await flash(request, error(companies.error, "Failed to get companies"))
+ );
+ }
+
+ const companyId = params.companyId;
+ if (!companies.data?.find((company) => company.id === companyId)) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.authenticatedRoot,
+ await flash(request, error(null, "Company not found"))
+ );
+ }
+
+ if (!companyId) {
+ await destroyAuthSession(request);
+ }
+
+ throw redirect(path.to.authenticatedRoot, {
+ headers: {
+ "Set-Cookie": await updateCompanySession(request, companyId!),
+ },
+ });
+}
diff --git a/apps/developers/app/utils/path.ts b/apps/developers/app/utils/path.ts
index 0604a12cd8..9247429e02 100644
--- a/apps/developers/app/utils/path.ts
+++ b/apps/developers/app/utils/path.ts
@@ -1,11 +1,21 @@
import { SUPABASE_API_URL } from "@carbon/auth";
+import { generatePath } from "@remix-run/react";
const x = "/x"; // from ~/routes/x+ folder
+export const ERP_URL =
+ process.env.NODE_ENV === "development"
+ ? "http://localhost:3000"
+ : `https://app.carbonos.dev`;
+
export const path = {
to: {
authenticatedRoot: x,
+ accountSettings: `${ERP_URL}/x/account`,
callback: "/callback",
+ companySwitch: (companyId: string) =>
+ generatePath(`${x}/company/switch/${companyId}`),
+ dashboard: `${ERP_URL}/x`,
forgotPassword: "/forgot-password",
healthcheck: "/healthcheck",
login: "/login",
diff --git a/packages/utils/src/const.ts b/packages/utils/src/const.ts
new file mode 100644
index 0000000000..56f06c7d54
--- /dev/null
+++ b/packages/utils/src/const.ts
@@ -0,0 +1 @@
+export const SUPPORT_EMAIL = "[email protected]";
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index 440ec1edaa..6b40c815e4 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -2,6 +2,7 @@ export * from "./accounting";
export * from "./address";
export * from "./arrays";
export * from "./color";
+export * from "./const";
export * from "./date";
export * from "./duration";
export * from "./file";