chore: organization onboarding refactor (#24381)
* feat: redirect to new onboarding flow * Getting started * Brand details * Preview organization brands * Orgs team pages * Invite team steps * Move to global zustand store * Few darkmdoe fixes * Wip onboarding + stripe flow * Default plan state Server Action for gettting slug satus of org * Remove onboardingId * Confirmation prompt * Update old onboarding flow handlers to handle new fields * update onboarding hook * Filter out organization section for none -company emails * Match placeholders to users domain * Drop migration * Wip new onboarding intent * WIP flow for self-hosted. Same service call just split logic * WIP * Add TODO * Use onboarding user type instead of trpc session * WIP * WIP * pass role and team name from onboarding to save in schema * Add test to ensure role + name + team are persisted into onboarding table * migrate roles to enum values * Update ENUM * Fix type error * Redirect if flag is disabled * Remove web * WIP * WIP * Fix migration * Fix calls * User onboarding User types instead of trpc session * Fix factory tests * Fix flow for self hoste * Type error * More type fixes * Fix handler tests * Fix enum return type being different * Use consistant types across the oganization stuff * Fix * Use TEAM_BILLING for e2e test * Refactor is not company email and add tests * Fix * Fix * Refactor flow to submit after form complete * Fix flow with billing disabled * Fix tests * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Rename and move test files * WIP * Fix types * Update repo paths + tests * Move to service folder * Fix tests * Fix types * Remove old test files * Restore lock * Fix path * Fix tests with new paths and factory logic * Fix updaetdAt * WIP onboardingID isolation * Fix e2e test * verify test * Code rabbit * Rename SelfHostedOnboardongService -> SelfHostedOrganizationOnboardingService * Fix stores * Fix type error * Fix types * remove tsignore * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * NITS * Add the logic to auto complete admin org when billing enabled * Fix store being weird * We need to return the parsed value * fixes * sync from db always * Add onboardingSgtore tests * fix test * remove step and status --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
48 files changed
+4959
-1813
No files matched your search
@@ -1,50 +1,79 @@
|
||||
"use client";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { useOnboarding } from "@calcom/features/ee/organizations/lib/onboardingStore";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
import { Alert } from "@calcom/ui/components/alert";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
export const AdminOnboardingHandover = () => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const session = useSession();
|
||||
const isAdmin = session.data?.user.role === "ADMIN";
|
||||
const { useOnboardingStore } = useOnboarding();
|
||||
const { onboardingId, orgOwnerEmail } = useOnboardingStore();
|
||||
|
||||
if (!isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const onboardingUrl = `${WEBAPP_URL}/settings/organizations/new`;
|
||||
// Admin handover page should ONLY use store data, not DB query
|
||||
// The DB query returns the admin's own onboarding, not the one being handed over
|
||||
if (!onboardingId) {
|
||||
return <Alert severity="error" title={t("error")} message="No onboarding ID found. Please try again." />;
|
||||
}
|
||||
|
||||
const onboardingUrl = `${WEBAPP_URL}/settings/organizations/new/resume?onboardingId=${onboardingId}`;
|
||||
|
||||
return (
|
||||
<div className="bg-subtle rounded-md p-4">
|
||||
<div className="flex-col items-center gap-2">
|
||||
<span className="text-emphasis font-medium">
|
||||
User can now continue onboarding with the following link
|
||||
</span>
|
||||
<div className="mt-2 flex items-center gap-2">
|
||||
<code
|
||||
data-testid="onboarding-url"
|
||||
className="bg-default text-default flex w-full items-center truncate rounded-md px-3 py-2 font-mono text-sm">
|
||||
{onboardingUrl}
|
||||
</code>
|
||||
<Button
|
||||
data-testid="copy-onboarding-url"
|
||||
type="button"
|
||||
variant="icon"
|
||||
color="secondary"
|
||||
className="h-9 w-9"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(onboardingUrl);
|
||||
showToast(t("link_copied"), "success");
|
||||
}}
|
||||
StartIcon="clipboard"
|
||||
tooltip={t("copy_to_clipboard")}
|
||||
/>
|
||||
<div className="space-y-6">
|
||||
{/* Instructions Card */}
|
||||
<div className="bg-subtle rounded-lg p-6">
|
||||
<h3 className="text-emphasis mb-2 text-lg font-medium">{t("next_steps")}</h3>
|
||||
<p className="text-default mb-4 text-sm">
|
||||
Send the following link to <strong>{orgOwnerEmail}</strong> so they can complete the organization
|
||||
setup:
|
||||
</p>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="bg-default flex items-center gap-2 rounded-md border p-3">
|
||||
<code className="text-default flex-1 truncate font-mono text-sm" data-testid="onboarding-url">
|
||||
{onboardingUrl}
|
||||
</code>
|
||||
<Button
|
||||
data-testid="copy-onboarding-url"
|
||||
type="button"
|
||||
size="sm"
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(onboardingUrl);
|
||||
showToast(t("link_copied"), "success");
|
||||
}}
|
||||
StartIcon="clipboard">
|
||||
{t("copy")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Button color="minimal" StartIcon="arrow-left" onClick={() => router.push("/settings/organizations")}>
|
||||
{t("back")}
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
router.push("/event-types");
|
||||
}}>
|
||||
{t("done")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -10,8 +10,7 @@ import { subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomain
|
||||
import { MINIMUM_NUMBER_OF_ORG_SEATS, IS_SELF_HOSTED } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { BillingPeriod, CreationSource, UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { Ensure } from "@calcom/types/utils";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
@@ -37,7 +36,7 @@ function extractDomainFromEmail(email: string) {
|
||||
export const CreateANewOrganizationForm = () => {
|
||||
const session = useSession();
|
||||
|
||||
const { isLoadingOrgOnboarding } = useOnboarding({ step: "start" });
|
||||
const { isLoadingOrgOnboarding } = useOnboarding();
|
||||
if (!session.data || isLoadingOrgOnboarding) {
|
||||
return null;
|
||||
}
|
||||
@@ -45,11 +44,6 @@ export const CreateANewOrganizationForm = () => {
|
||||
return <CreateANewOrganizationFormChild session={session} />;
|
||||
};
|
||||
|
||||
enum BillingPeriod {
|
||||
MONTHLY = "MONTHLY",
|
||||
ANNUALLY = "ANNUALLY",
|
||||
}
|
||||
|
||||
const CreateANewOrganizationFormChild = ({ session }: { session: Ensure<SessionContextValue, "data"> }) => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
@@ -57,7 +51,7 @@ const CreateANewOrganizationFormChild = ({ session }: { session: Ensure<SessionC
|
||||
const isAdmin = session.data.user.role === UserPermissionRole.ADMIN;
|
||||
// Let self-hosters create an organization with their own email. Hosted's Admin already has an organization for their email
|
||||
const defaultOrgOwnerEmail = (!isAdmin || IS_SELF_HOSTED ? session.data.user.email : null) ?? "";
|
||||
const { useOnboardingStore, isBillingEnabled } = useOnboarding({ step: "start" });
|
||||
const { useOnboardingStore, isBillingEnabled } = useOnboarding();
|
||||
const { slug, name, orgOwnerEmail, billingPeriod, pricePerSeat, seats, onboardingId, reset } =
|
||||
useOnboardingStore();
|
||||
|
||||
@@ -81,8 +75,6 @@ const CreateANewOrganizationFormChild = ({ session }: { session: Ensure<SessionC
|
||||
|
||||
const intentToCreateOrgMutation = trpc.viewer.organizations.intentToCreateOrg.useMutation({
|
||||
onSuccess: async (data) => {
|
||||
// TODO: To be moved to _invoice.paid.org.ts
|
||||
// telemetry.event(telemetryEventTypes.org_created);
|
||||
reset({
|
||||
onboardingId: data.organizationOnboardingId,
|
||||
billingPeriod: data.billingPeriod,
|
||||
@@ -93,9 +85,17 @@ const CreateANewOrganizationFormChild = ({ session }: { session: Ensure<SessionC
|
||||
slug: data.slug,
|
||||
});
|
||||
|
||||
if (isAdmin && data.userId !== session.data.user.id) {
|
||||
// Small delay to ensure Zustand persist middleware has time to write to localStorage
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
if (data.handoverUrl) {
|
||||
// Admin handover flow - redirect to handover page
|
||||
router.push("/settings/organizations/new/handover");
|
||||
} else if (data.organizationId) {
|
||||
// Self-hosted flow - org already created, redirect to organizations list
|
||||
router.push("/settings/organizations");
|
||||
} else {
|
||||
// Regular flow - continue to next step
|
||||
router.push("/settings/organizations/new/about");
|
||||
}
|
||||
},
|
||||
@@ -122,10 +122,30 @@ const CreateANewOrganizationFormChild = ({ session }: { session: Ensure<SessionC
|
||||
id="createOrg"
|
||||
handleSubmit={async (v) => {
|
||||
if (!needToCreateOnboarding) {
|
||||
// Resuming existing onboarding - just navigate to next step
|
||||
router.push("/settings/organizations/new/about");
|
||||
} else if (!intentToCreateOrgMutation.isPending) {
|
||||
setServerErrorMessage(null);
|
||||
intentToCreateOrgMutation.mutate({ ...v, creationSource: CreationSource.WEBAPP });
|
||||
} else {
|
||||
// Check if this is admin handover flow based on the submitted form value
|
||||
const isAdminHandoverFlow = isAdmin && v.orgOwnerEmail !== session.data.user.email;
|
||||
|
||||
if (isAdminHandoverFlow) {
|
||||
// Admin creating for someone else - submit immediately with just Step 1 data
|
||||
if (!intentToCreateOrgMutation.isPending) {
|
||||
setServerErrorMessage(null);
|
||||
intentToCreateOrgMutation.mutate({ ...v, creationSource: CreationSource.WEBAPP });
|
||||
}
|
||||
} else {
|
||||
// Regular user or admin creating for self - store locally and continue
|
||||
reset({
|
||||
billingPeriod: v.billingPeriod,
|
||||
pricePerSeat: v.pricePerSeat,
|
||||
seats: v.seats,
|
||||
orgOwnerEmail: v.orgOwnerEmail,
|
||||
name: v.name,
|
||||
slug: v.slug,
|
||||
});
|
||||
router.push("/settings/organizations/new/about");
|
||||
}
|
||||
}
|
||||
}}>
|
||||
<div>
|
||||
|
||||
Reference in new issue
Block a user