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: onboarding with theme

Brad Barbince8061d64c0a
diff --git a/apps/carbon/app/modules/settings/settings.models.ts b/apps/carbon/app/modules/settings/settings.models.ts
index 36eded7ca2..cfd084c580 100644
--- a/apps/carbon/app/modules/settings/settings.models.ts
+++ b/apps/carbon/app/modules/settings/settings.models.ts
@@ -51,6 +51,9 @@ export type Theme = (typeof themes)[number];
export const themeValidator = withZod(
z.object({
- theme: z.enum(themes),
+ next: zfd.text(z.string().optional()),
+ theme: z.enum(themes, {
+ errorMap: (issue, ctx) => ({ message: "Theme is required" }),
+ }),
})
);
diff --git a/apps/carbon/app/routes/onboarding+/_layout.tsx b/apps/carbon/app/routes/onboarding+/_layout.tsx
index 7d0aeac470..b9220fcb38 100644
--- a/apps/carbon/app/routes/onboarding+/_layout.tsx
+++ b/apps/carbon/app/routes/onboarding+/_layout.tsx
@@ -1,12 +1,11 @@
-import { Avatar, ClientOnly, HStack, IconButton } from "@carbon/react";
import { redirect, type LoaderFunctionArgs } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
-import { BsFillHexagonFill } from "react-icons/bs";
import { getLocationsList } from "~/modules/resources";
import { getCompany } from "~/modules/settings";
import { requirePermissions } from "~/services/auth";
import { onboardingSequence, path } from "~/utils/path";
+import { VStack } from "@carbon/react";
import type { ShouldRevalidateFunction } from "@remix-run/react";
export const shouldRevalidate: ShouldRevalidateFunction = () => true;
@@ -46,43 +45,11 @@ export async function loader({ request }: LoaderFunctionArgs) {
export default function OnboardingLayout() {
return (
- // not sure why we need this ClientOnly, but things break without it
- <ClientOnly fallback={null}>
- {() => (
- <div className="bg-card grid grid-cols-[auto_1fr] h-screen w-screen">
- <SidebarPlaceholder />
- <div className="grid grid-rows-[auto_1fr] h-full w-full">
- <TopbarPlaceholder />
- <div>
- <Outlet />
- </div>
- </div>
- </div>
- )}
- </ClientOnly>
- );
-}
-
-function TopbarPlaceholder() {
- return (
- <div className="grid bg-background border-b border-border gap-4 grid-cols-1 sticky px-4 top-0 z-1">
- <HStack className="justify-end py-2" spacing={1}>
- <Avatar size="sm" />
- </HStack>
- </div>
- );
-}
-
-function SidebarPlaceholder() {
- return (
- <div className="h-full border-r border-border bg-background z-1">
- <IconButton
- aria-label="Home"
- icon={<BsFillHexagonFill />}
- variant="ghost"
- size="lg"
- className="rounded-none"
- />
- </div>
+ <VStack
+ spacing={4}
+ className="h-screen w-screen justify-center items-center p-4"
+ >
+ <Outlet />
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/onboarding+/company.tsx b/apps/carbon/app/routes/onboarding+/company.tsx
index ad7fd7d172..1373438e75 100644
--- a/apps/carbon/app/routes/onboarding+/company.tsx
+++ b/apps/carbon/app/routes/onboarding+/company.tsx
@@ -1,13 +1,12 @@
import {
Button,
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
HStack,
- Modal,
- ModalBody,
- ModalContent,
- ModalDescription,
- ModalFooter,
- ModalHeader,
- ModalTitle,
VStack,
} from "@carbon/react";
import { getLocalTimeZone } from "@internationalized/date";
@@ -132,48 +131,44 @@ export default function OnboardingUser() {
};
return (
- <Modal open>
- <ModalContent>
- <ValidatedForm
- validator={onboardingCompanyValidator}
- defaultValues={initialValues}
- method="post"
- >
- <ModalHeader>
- <ModalTitle>Now let's setup your company</ModalTitle>
- <ModalDescription>
- You can always change this later
- </ModalDescription>
- </ModalHeader>
- <ModalBody>
- <Hidden name="next" value={next} />
- <VStack spacing={4}>
- <Input name="name" label="Company Name" />
- <Input name="addressLine1" label="Address" />
- <Input name="city" label="City" />
- <Input name="state" label="State" />
- <Input name="postalCode" label="Zip Code" />
- </VStack>
- </ModalBody>
-
- <ModalFooter>
- <HStack>
- <Button
- variant="solid"
- isDisabled={!previous}
- size="md"
- onClick={() => {
- onPrevious?.();
- }}
- tabIndex={-1}
- >
- Previous
- </Button>
- <Submit>Next</Submit>
- </HStack>
- </ModalFooter>
- </ValidatedForm>
- </ModalContent>
- </Modal>
+ <Card className="max-w-lg">
+ <ValidatedForm
+ validator={onboardingCompanyValidator}
+ defaultValues={initialValues}
+ method="post"
+ >
+ <CardHeader>
+ <CardTitle>Now let's setup your company</CardTitle>
+ <CardDescription>You can always change this later</CardDescription>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="next" value={next} />
+ <VStack spacing={4}>
+ <Input name="name" label="Company Name" />
+ <Input name="addressLine1" label="Address" />
+ <Input name="city" label="City" />
+ <Input name="state" label="State" />
+ <Input name="postalCode" label="Zip Code" />
+ </VStack>
+ </CardContent>
+
+ <CardFooter>
+ <HStack>
+ <Button
+ variant="solid"
+ isDisabled={!previous}
+ size="md"
+ onClick={() => {
+ onPrevious?.();
+ }}
+ tabIndex={-1}
+ >
+ Previous
+ </Button>
+ <Submit>Next</Submit>
+ </HStack>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
);
}
diff --git a/apps/carbon/app/routes/onboarding+/index.tsx b/apps/carbon/app/routes/onboarding+/index.tsx
index d4c5596859..6402f0597e 100644
--- a/apps/carbon/app/routes/onboarding+/index.tsx
+++ b/apps/carbon/app/routes/onboarding+/index.tsx
@@ -1,6 +1,61 @@
-import { redirect } from "@remix-run/node";
+import { Button as _Button, Heading as _Heading, VStack } from "@carbon/react";
+import { Link } from "@remix-run/react";
+import { AnimatePresence, motion } from "framer-motion";
import { onboardingSequence } from "~/utils/path";
-export async function loader() {
- return redirect(onboardingSequence[0]);
+const Heading = motion(_Heading);
+const Button = motion(_Button);
+
+const fade = {
+ initial: { opacity: 0 },
+ animate: { opacity: 1 },
+};
+
+export default function GetStarted() {
+ return (
+ <AnimatePresence>
+ <VStack spacing={4} className="max-w-lg p-4 items-center text-center">
+ <motion.img
+ initial={{ opacity: 0, scale: 0.4 }}
+ animate={{ opacity: 1, scale: 1 }}
+ transition={{ duration: 2, ease: "easeInOut" }}
+ src="/carbon-logo-dark.png"
+ alt="Carbon Logo"
+ className="block dark:hidden max-w-[60px] mb-3"
+ />
+ <motion.img
+ initial={{ opacity: 0, scale: 0.4 }}
+ animate={{ opacity: 1, scale: 1 }}
+ transition={{ duration: 2, ease: "easeInOut" }}
+ src="/carbon-logo-light.png"
+ alt="Carbon Logo"
+ className="hidden dark:block max-w-[60px] mb-3"
+ />
+ <Heading
+ {...fade}
+ transition={{ duration: 1.2, ease: "easeInOut", delay: 1.5 }}
+ size="display"
+ className="m-0"
+ >
+ Welcome to Carbon ERP
+ </Heading>
+ <motion.p
+ {...fade}
+ transition={{ duration: 1.4, ease: "easeInOut", delay: 1.9 }}
+ className="text-muted-foreground text-sm pb-4"
+ >
+ Carbon is an open-source ERP for manufacturing
+ </motion.p>
+
+ <Button
+ {...fade}
+ transition={{ duration: 1, delay: 2.4 }}
+ size="lg"
+ asChild
+ >
+ <Link to={onboardingSequence[0]}>Get Started</Link>
+ </Button>
+ </VStack>
+ </AnimatePresence>
+ );
}
diff --git a/apps/carbon/app/routes/onboarding+/location.tsx b/apps/carbon/app/routes/onboarding+/location.tsx
deleted file mode 100644
index 46015915cc..0000000000
--- a/apps/carbon/app/routes/onboarding+/location.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function OnboardingLocation() {
- return null;
-}
diff --git a/apps/carbon/app/routes/onboarding+/theme.tsx b/apps/carbon/app/routes/onboarding+/theme.tsx
new file mode 100644
index 0000000000..bc12b77a15
--- /dev/null
+++ b/apps/carbon/app/routes/onboarding+/theme.tsx
@@ -0,0 +1,178 @@
+import {
+ Button,
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ HStack,
+ VStack,
+ cn,
+} from "@carbon/react";
+import { themes, type Theme } from "@carbon/utils";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { useLoaderData } from "@remix-run/react";
+import { useEffect, useState } from "react";
+import { RxCheck } from "react-icons/rx";
+import { ValidatedForm, validationError } from "remix-validated-form";
+import { Hidden, Submit } from "~/components/Form";
+import { useOnboarding } from "~/hooks";
+import { useMode } from "~/hooks/useMode";
+import type { Theme as ThemeValue } from "~/modules/settings";
+import { getTheme, themeValidator, updateTheme } from "~/modules/settings";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import type { Handle } from "~/utils/handle";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export const handle: Handle = {
+ breadcrumb: "Theme",
+ to: path.to.theme,
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "settings",
+ });
+
+ const theme = await getTheme(client);
+
+ return json({
+ theme: theme.data?.theme ?? "Carbon",
+ });
+}
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "settings",
+ });
+ const formData = await request.formData();
+
+ const validation = await themeValidator.validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { next, theme } = validation.data;
+ if (!next) throw new Error("Fatal: next is required");
+
+ const update = await updateTheme(client, {
+ theme,
+ updatedBy: userId,
+ });
+ if (update.error)
+ return json(
+ {},
+ await flash(request, error(update.error, "Failed to update theme"))
+ );
+
+ return redirect(next);
+}
+
+export default function OnboardingTheme() {
+ const { theme: initialTheme } = useLoaderData<typeof loader>();
+ console.log(initialTheme);
+
+ const [theme, setTheme] = useState<ThemeValue>(initialTheme);
+ const mode = useMode();
+
+ const onThemeChange = (t: Theme) => {
+ setTheme(t.name);
+
+ const variables = mode === "dark" ? t.cssVars.dark : t.cssVars.light;
+
+ Object.entries(variables).forEach(([key, value]) => {
+ document.body.style.setProperty(`--${key}`, value);
+ });
+ };
+
+ useEffect(() => {
+ const t = themes.find((t) => t.name === theme);
+ if (t) {
+ onThemeChange(t);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [mode]);
+
+ const { next, previous, onPrevious } = useOnboarding();
+
+ return (
+ <Card className="max-w-lg">
+ <ValidatedForm
+ method="post"
+ validator={themeValidator}
+ defaultValues={{ theme: initialTheme }}
+ >
+ <CardHeader>
+ <CardTitle>Choose your style</CardTitle>
+ <CardDescription>
+ You can change the UI style any time through the theme setting
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="next" value={next} />
+ <Hidden name="theme" value={theme} />
+ <VStack spacing={4}>
+ <div className="w-full grid grid-cols-3 gap-4">
+ {themes.map((t) => {
+ const isActive = theme === t.name;
+ return (
+ <Button
+ key={t.name}
+ variant="secondary"
+ onClick={() => onThemeChange(t)}
+ className={cn(
+ "justify-start",
+ isActive && "border-2 border-primary"
+ )}
+ style={
+ {
+ "--theme-primary": `hsl(${
+ t?.activeColor[mode === "dark" ? "dark" : "light"]
+ })`,
+ } as React.CSSProperties
+ }
+ >
+ <span
+ className={cn(
+ "mr-1 flex h-5 w-5 shrink-0 -translate-x-1 items-center justify-center rounded-full bg-[--theme-primary]"
+ )}
+ >
+ {isActive && <RxCheck className="h-4 w-4 text-white" />}
+ </span>
+ {t.label}
+ </Button>
+ );
+ })}
+ </div>
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ <HStack>
+ {previous && (
+ <Button
+ variant="solid"
+ isDisabled={!previous}
+ size="md"
+ onClick={() => {
+ onPrevious?.();
+ }}
+ tabIndex={-1}
+ >
+ Previous
+ </Button>
+ )}
+
+ <Submit>Next</Submit>
+ </HStack>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
+ );
+}
diff --git a/apps/carbon/app/routes/onboarding+/user.tsx b/apps/carbon/app/routes/onboarding+/user.tsx
index 31f7a102f1..8947478937 100644
--- a/apps/carbon/app/routes/onboarding+/user.tsx
+++ b/apps/carbon/app/routes/onboarding+/user.tsx
@@ -1,12 +1,11 @@
import {
Button,
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
HStack,
- Modal,
- ModalBody,
- ModalContent,
- ModalFooter,
- ModalHeader,
- ModalTitle,
VStack,
} from "@carbon/react";
import { redirect, type ActionFunctionArgs } from "@remix-run/node";
@@ -101,44 +100,42 @@ export default function OnboardingUser() {
}
return (
- <Modal open>
- <ModalContent>
- <ValidatedForm
- autoComplete="off"
- validator={onboardingUserValidator}
- defaultValues={initialValues}
- method="post"
- >
- <ModalHeader>
- <ModalTitle>First let's setup your account</ModalTitle>
- </ModalHeader>
- <ModalBody>
- <Hidden name="next" value={next} />
- <VStack spacing={4}>
- <Input name="firstName" label="First Name" />
- <Input name="lastName" label="Last Name" />
- <Input autoComplete="off" name="email" label="Email" />
- <Password autoComplete="off" name="password" label="Password" />
- </VStack>
- </ModalBody>
- <ModalFooter>
- <HStack>
- <Button
- variant="solid"
- isDisabled={!previous}
- size="md"
- onClick={() => {
- onPrevious?.();
- }}
- tabIndex={-1}
- >
- Previous
- </Button>
- <Submit>Next</Submit>
- </HStack>
- </ModalFooter>
- </ValidatedForm>
- </ModalContent>
- </Modal>
+ <Card className="max-w-lg">
+ <ValidatedForm
+ autoComplete="off"
+ validator={onboardingUserValidator}
+ defaultValues={initialValues}
+ method="post"
+ >
+ <CardHeader>
+ <CardTitle>Let's setup your account</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="next" value={next} />
+ <VStack spacing={4}>
+ <Input name="firstName" label="First Name" />
+ <Input name="lastName" label="Last Name" />
+ <Input autoComplete="off" name="email" label="Email" />
+ <Password autoComplete="off" name="password" label="Password" />
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ <HStack>
+ <Button
+ variant="solid"
+ isDisabled={!previous}
+ size="md"
+ onClick={() => {
+ onPrevious?.();
+ }}
+ tabIndex={-1}
+ >
+ Previous
+ </Button>
+ <Submit>Next</Submit>
+ </HStack>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
);
}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 6fb8d84354..02b6e4eb9d 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -56,6 +56,7 @@ export const path = {
company: `${onboarding}/company`,
location: `${onboarding}/location`,
root: `${onboarding}`,
+ theme: `${onboarding}/theme`,
user: `${onboarding}/user`,
},
authenticatedRoot: x,
@@ -485,6 +486,7 @@ export const path = {
} as const;
export const onboardingSequence = [
+ path.to.onboarding.theme,
path.to.onboarding.user,
path.to.onboarding.company,
] as const;