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): new signups can start with demo data (#1730)

Anshul sharma2231a5ed90e7
diff --git a/apps/erp/app/modules/agent/kb/docs/platform/demo-data.md b/apps/erp/app/modules/agent/kb/docs/platform/demo-data.md
index 43e835c3e0..e88e36b15a 100644
--- a/apps/erp/app/modules/agent/kb/docs/platform/demo-data.md
+++ b/apps/erp/app/modules/agent/kb/docs/platform/demo-data.md
@@ -50,10 +50,10 @@ If a revert seems stuck, the card says so after a few minutes and offers "Retry
## Demo data at sign-up
-The same templates power onboarding. When Carbon staff create a new company, the data step asks **"How would you like to start?"**:
+The same templates power onboarding. When anyone creates a new company, the data step asks **"How would you like to start?"**:
- **Use a demo template**: Sets up sample customers, suppliers, parts and orders for the industry you pick. They appear shortly after you finish.
- - **Restore from a backup**: Sets the new company up from an uploaded Carbon `docs/platform/backups` of another company.
+ - **Restore from a backup**: Sets the new company up from an uploaded `docs/platform/backups` of another Carbon company environment. Carbon staff only.
- **I don't need data**: Starts with a clean, empty environment.
Choosing a template then asks **"Which best describes your company?"** and seeds the matching industry. See `docs/reference/onboarding` for the rest of the wizard.
diff --git a/apps/erp/app/modules/agent/kb/docs/reference/onboarding.md b/apps/erp/app/modules/agent/kb/docs/reference/onboarding.md
index bf23654aad..b4020397e5 100644
--- a/apps/erp/app/modules/agent/kb/docs/reference/onboarding.md
+++ b/apps/erp/app/modules/agent/kb/docs/reference/onboarding.md
@@ -8,11 +8,13 @@ A brand-new account has no company yet, so Carbon holds you in the setup wizard
**Your profile.** First and last name, both required.
-**Company.** The substantive step: company name, full address, base currency, optional website. Submitting creates the company and everything a usable tenant needs.
+**Company.** Company name, full address, base currency, optional website.
-Two steps appear conditionally: **Industry** (internal Carbon staff only: offers a `docs/platform/demo-data` or a `docs/platform/backups` restore) and **Plan** (Carbon Cloud only: Stripe checkout; self-hosted installs go straight to the app).
+**Industry.** How to start: a `docs/platform/demo-data` for your industry, or a clean, empty company. Carbon staff also get a `docs/platform/backups` restore option. Submitting creates the company and everything a usable tenant needs.
-Saving the company also creates a **"Headquarters"** location from your address, links you as an employee, and seeds the baseline: chart of accounts, posting accounts, numbering sequences, payment terms, units of measure. Fiscal year, periods, and sequences are deliberately *not* asked for — they come pre-seeded and you tune them later under `docs/reference/company-settings`.
+One step appears conditionally: **Plan** (Carbon Cloud only: Stripe checkout; self-hosted installs go straight to the app).
+
+Creating the company also creates a **"Headquarters"** location from your address, links you as an employee, and seeds the baseline: chart of accounts, posting accounts, numbering sequences, payment terms, units of measure. Fiscal year, periods, and sequences are deliberately *not* asked for — they come pre-seeded and you tune them later under `docs/reference/company-settings`.
## Where to go next
@@ -23,9 +25,9 @@ The wizard's job is a working tenant, not a configured one. Refine the seeded se
The completion gate is the layout loader (`routes/onboarding+/_layout.tsx:33-44`); step order is `utils/path.ts:2103-2109`; conditional steps at `_layout.tsx:49-53`. Theme validator `settings.models.ts:306-311`; profile `onboardingUserValidator` (`account.models.ts:12-17`); company `addressValidator` (`settings.models.ts:95-107`). Provisioning runs `provisionOnboardingCompany` (`services/onboarding.server.ts`) with the seed via `seedCompany` (`settings.service.ts:751-765`).
### Stuck in the setup wizard / keeps redirecting to /onboarding
-The company lacks a name or a location — there is no `onboarded` flag. Complete the Company step; it creates both at once.
+The company lacks a name or a location — there is no `onboarded` flag. Complete the Company and Industry steps; the Industry step creates both at once.
-### The Industry step isn't showing
+### "Restore from a backup" isn't offered on the Industry step
Internal Carbon staff accounts only. Its absence for regular sign-ups is expected.
### The Plan step isn't showing
diff --git a/apps/erp/app/modules/agent/kb/manifest.json b/apps/erp/app/modules/agent/kb/manifest.json
index 1281c534e3..56dbf793e3 100644
--- a/apps/erp/app/modules/agent/kb/manifest.json
+++ b/apps/erp/app/modules/agent/kb/manifest.json
@@ -1036,7 +1036,7 @@
"Where to go next",
"Internals and troubleshooting",
"Stuck in the setup wizard / keeps redirecting to /onboarding",
- "The Industry step isn't showing",
+ "\"Restore from a backup\" isn't offered on the Industry step",
"The Plan step isn't showing"
]
},
diff --git a/apps/erp/app/routes/onboarding+/_layout.tsx b/apps/erp/app/routes/onboarding+/_layout.tsx
index 0482dde938..77dcfcdd43 100644
--- a/apps/erp/app/routes/onboarding+/_layout.tsx
+++ b/apps/erp/app/routes/onboarding+/_layout.tsx
@@ -2,7 +2,7 @@ import { CarbonEdition } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { TooltipProvider } from "@carbon/react";
import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";
-import { Edition, isInternalEmail } from "@carbon/utils";
+import { Edition } from "@carbon/utils";
import type {
LoaderFunctionArgs,
ShouldRevalidateFunction
@@ -16,11 +16,7 @@ import { onboardingSequence, path } from "~/utils/path";
export const shouldRevalidate: ShouldRevalidateFunction = () => true;
export async function loader({ request }: LoaderFunctionArgs) {
- const { client, companyId, userId, email } = await requirePermissions(
- request,
- {}
- );
- const isInternal = isInternalEmail(email);
+ const { client, companyId, userId } = await requirePermissions(request, {});
const [company, stripeCustomer, locations] = await Promise.all([
getCompany(client, companyId),
@@ -43,12 +39,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
}
}
- // The data-choice step (demo template / backup import) is internal-only; the
- // plan step is Cloud-only. Everyone else creates their company in the company
- // step directly.
+ // The plan step is Cloud-only.
const onboardingSteps = onboardingSequence.filter((p) => {
if (p === path.to.onboarding.plan) return CarbonEdition === Edition.Cloud;
- if (p === path.to.onboarding.industry) return isInternal;
return true;
});
diff --git a/apps/erp/app/routes/onboarding+/company.tsx b/apps/erp/app/routes/onboarding+/company.tsx
index 1fe1f8a9f3..be2ad81a50 100644
--- a/apps/erp/app/routes/onboarding+/company.tsx
+++ b/apps/erp/app/routes/onboarding+/company.tsx
@@ -1,8 +1,5 @@
import { assertIsPost } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
-import { getCarbonServiceRole } from "@carbon/auth/client.server";
-import { setCompanyId } from "@carbon/auth/company.server";
-import { updateCompanySession } from "@carbon/auth/session.server";
import { ValidatedForm, validationError, validator } from "@carbon/form";
import {
Button,
@@ -12,7 +9,6 @@ import {
HStack,
VStack
} from "@carbon/react";
-import { isInternalEmail } from "@carbon/utils";
import { getLocalTimeZone } from "@internationalized/date";
import {
type ActionFunctionArgs,
@@ -35,7 +31,6 @@ import {
} from "~/components/Form";
import { useOnboarding } from "~/hooks";
import { addressValidator, getCompany } from "~/modules/settings";
-import { provisionOnboardingCompany } from "~/services/onboarding.server";
import {
getOnboardingDraft,
setOnboardingDraft
@@ -60,7 +55,7 @@ export async function loader({ request }: ActionFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { client, userId, email } = await requirePermissions(request, {});
+ await requirePermissions(request, {});
const formData = await request.formData();
@@ -72,44 +67,14 @@ export async function action({ request }: ActionFunctionArgs) {
const { next, ...companyData } = validation.data;
- // Internal users get a dedicated data-choice step (demo template / backup
- // import) that creates the company; stash this step's input for it.
- if (isInternalEmail(email)) {
- const draftCookie = await setOnboardingDraft(request, {
- company: companyData
- });
-
- throw redirect(next, {
- headers: [["Set-Cookie", draftCookie]]
- });
- }
-
- // Public signups skip the data-choice step and create a clean company here.
- const serviceRole = getCarbonServiceRole();
- const companyId = await provisionOnboardingCompany(serviceRole, client, {
- userId,
- companyData,
- backup: null,
- template: null
+ // The next (data-choice) step creates the company; stash this step's input
+ // for it.
+ const draftCookie = await setOnboardingDraft(request, {
+ company: companyData
});
- const companyRecord = await serviceRole
- .from("company")
- .select("companyGroupId")
- .eq("id", companyId)
- .single();
- const sessionCookie = await updateCompanySession(
- request,
- companyId,
- companyRecord.data?.companyGroupId ?? ""
- );
- const companyIdCookie = setCompanyId(companyId);
-
throw redirect(next, {
- headers: [
- ["Set-Cookie", sessionCookie],
- ["Set-Cookie", companyIdCookie]
- ]
+ headers: [["Set-Cookie", draftCookie]]
});
}
diff --git a/apps/erp/app/routes/onboarding+/industry.tsx b/apps/erp/app/routes/onboarding+/industry.tsx
index 5038a1f500..8e6ce4d397 100644
--- a/apps/erp/app/routes/onboarding+/industry.tsx
+++ b/apps/erp/app/routes/onboarding+/industry.tsx
@@ -94,11 +94,9 @@ function appendDraftCompany(
export async function loader({ request }: ActionFunctionArgs) {
const { client, companyId, email } = await requirePermissions(request, {});
- // The data-choice step is internal-only; public signups create their company
- // in the company step. Guard direct navigation to this route.
- if (!isInternalEmail(email)) {
- throw redirect(path.to.onboarding.company);
- }
+ // Restoring from a backup stays internal-only; the demo template and a clean
+ // start are open to every signup.
+ const canRestoreBackup = isInternalEmail(email);
const company = await getCompany(client, companyId);
const draft = await getOnboardingDraft(request);
@@ -110,21 +108,16 @@ export async function loader({ request }: ActionFunctionArgs) {
const industries = allIndustries.filter((i) => datasetForIndustry(i.id));
if (company.error || !company.data) {
- return { company: null, draft, industries };
+ return { company: null, draft, industries, canRestoreBackup };
}
- return { company: company.data, draft, industries };
+ return { company: company.data, draft, industries, canRestoreBackup };
}
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId, email } = await requirePermissions(request, {});
- // Internal-only step — reject direct POSTs from public signups.
- if (!isInternalEmail(email)) {
- throw redirect(path.to.onboarding.company);
- }
-
// Get draft data from previous step (company)
const draft = await getOnboardingDraft(request);
@@ -141,6 +134,11 @@ export async function action({ request }: ActionFunctionArgs) {
const { dataChoice } = industryValidation.data;
+ // Backup restore is internal-only — reject direct POSTs from public signups.
+ if (dataChoice === "import" && !isInternalEmail(email)) {
+ throw redirect(path.to.onboarding.industry);
+ }
+
// Carry forward the company data captured in the previous (company) step.
if (draft?.company) appendDraftCompany(formData, draft.company);
@@ -214,7 +212,8 @@ export async function action({ request }: ActionFunctionArgs) {
type Step = "data-question" | "industry-selection" | "import-upload";
export default function OnboardingIndustry() {
- const { company, industries } = useLoaderData<typeof loader>();
+ const { company, industries, canRestoreBackup } =
+ useLoaderData<typeof loader>();
const { next, previous } = useOnboarding();
// Determine initial step based on existing company data
@@ -274,12 +273,17 @@ export default function OnboardingIndustry() {
}
]
: []),
- {
- value: "import" as const,
- title: "Restore from a backup",
- description: "Set up from a Carbon backup of another company",
- icon: <LuUpload className="h-5 w-5" />
- },
+ ...(canRestoreBackup
+ ? [
+ {
+ value: "import" as const,
+ title: "Restore from a backup",
+ description:
+ "Set up from a backup of another Carbon company environment",
+ icon: <LuUpload className="h-5 w-5" />
+ }
+ ]
+ : []),
{
value: "none",
title: "I don't need data",
diff --git a/apps/erp/app/services/onboarding.server.ts b/apps/erp/app/services/onboarding.server.ts
index 5d8378545b..7304becd31 100644
--- a/apps/erp/app/services/onboarding.server.ts
+++ b/apps/erp/app/services/onboarding.server.ts
@@ -124,8 +124,8 @@ async function startCompanyTemplate(
/**
* Insert-or-update the onboarding company, provision its data, and create the
* headquarters location plus the owner's employee job. Returns the companyId.
- * Shared by the public company step (clean seed, `backup: null`) and the
- * internal data-choice step (restore from an uploaded backup, or a demo template).
+ * Called by the data-choice step: a clean seed, a demo template, or (internal
+ * only) a restore from an uploaded backup.
*/
export async function provisionOnboardingCompany(
serviceRole: ServiceRole,
diff --git a/docs/content/docs/platform/demo-data.mdx b/docs/content/docs/platform/demo-data.mdx
index 2f5f712a60..ccb0385799 100644
--- a/docs/content/docs/platform/demo-data.mdx
+++ b/docs/content/docs/platform/demo-data.mdx
@@ -61,17 +61,17 @@ If a revert seems stuck, the card says so after a few minutes and offers "Retry
## Demo data at sign-up
-The same templates power onboarding. When Carbon staff create a new company, the data step asks **"How would you like to start?"**:
+The same templates power onboarding. When anyone creates a new company, the data step asks **"How would you like to start?"**:
<FieldTable>
<Field name="Use a demo template">Sets up sample customers, suppliers, parts and orders for the industry you pick. They appear shortly after you finish.</Field>
- <Field name="Restore from a backup">Sets the new company up from an uploaded Carbon [backup](/docs/platform/backups) of another company.</Field>
+ <Field name="Restore from a backup">Sets the new company up from an uploaded [backup](/docs/platform/backups) of another Carbon company environment. Carbon staff only.</Field>
<Field name="I don't need data">Starts with a clean, empty environment.</Field>
</FieldTable>
Choosing a template then asks **"Which best describes your company?"** and seeds the matching industry. See [Getting started](/docs/reference/onboarding) for the rest of the wizard.
-<Callout type="info" title="Who can see this page">
+<Callout type="info" title="Who can see the Demo Data page">
Demo Data sits behind the same gate as Backups, since it replaces a company's data wholesale. On production deployments it is currently limited to Carbon staff; on a local development stack it is open to everyone.
</Callout>
diff --git a/docs/content/docs/reference/onboarding.mdx b/docs/content/docs/reference/onboarding.mdx
index 4bca82cf23..0c8fc862a5 100644
--- a/docs/content/docs/reference/onboarding.mdx
+++ b/docs/content/docs/reference/onboarding.mdx
@@ -15,14 +15,17 @@ A brand-new account has no company yet, so Carbon holds you in the setup wizard
**Your profile.** First and last name, both required.
</Step>
<Step>
-**Company.** The substantive step: company name, full address, base currency, optional website. Submitting creates the company and everything a usable tenant needs.
+**Company.** Company name, full address, base currency, optional website.
+</Step>
+<Step>
+**Industry.** How to start: a [demo-data template](/docs/platform/demo-data) for your industry, or a clean, empty company. Carbon staff also get a [backup](/docs/platform/backups) restore option. Submitting creates the company and everything a usable tenant needs.
</Step>
</Steps>
-Two steps appear conditionally: **Industry** (internal Carbon staff only: offers a [demo-data template](/docs/platform/demo-data) or a [backup](/docs/platform/backups) restore) and **Plan** (Carbon Cloud only: Stripe checkout; self-hosted installs go straight to the app).
+One step appears conditionally: **Plan** (Carbon Cloud only: Stripe checkout; self-hosted installs go straight to the app).
-<Callout type="note" title="The company step does a lot of quiet work">
-Saving the company also creates a **"Headquarters"** location from your address, links you as an employee, and seeds the baseline: chart of accounts, posting accounts, numbering sequences, payment terms, units of measure. Fiscal year, periods, and sequences are deliberately *not* asked for — they come pre-seeded and you tune them later under [company settings](/docs/reference/company-settings).
+<Callout type="note" title="Creating the company does a lot of quiet work">
+Creating the company also creates a **"Headquarters"** location from your address, links you as an employee, and seeds the baseline: chart of accounts, posting accounts, numbering sequences, payment terms, units of measure. Fiscal year, periods, and sequences are deliberately *not* asked for — they come pre-seeded and you tune them later under [company settings](/docs/reference/company-settings).
</Callout>
## Where to go next
@@ -35,9 +38,9 @@ The wizard's job is a working tenant, not a configured one. Refine the seeded se
The completion gate is the layout loader (`routes/onboarding+/_layout.tsx:33-44`); step order is `utils/path.ts:2103-2109`; conditional steps at `_layout.tsx:49-53`. Theme validator `settings.models.ts:306-311`; profile `onboardingUserValidator` (`account.models.ts:12-17`); company `addressValidator` (`settings.models.ts:95-107`). Provisioning runs `provisionOnboardingCompany` (`services/onboarding.server.ts`) with the seed via `seedCompany` (`settings.service.ts:751-765`).
### Stuck in the setup wizard / keeps redirecting to /onboarding
-The company lacks a name or a location — there is no `onboarded` flag. Complete the Company step; it creates both at once.
+The company lacks a name or a location — there is no `onboarded` flag. Complete the Company and Industry steps; the Industry step creates both at once.
-### The Industry step isn't showing
+### "Restore from a backup" isn't offered on the Industry step
Internal Carbon staff accounts only. Its absence for regular sign-ups is expected.
### The Plan step isn't showing