Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Handle when user is not a member of any space (#1885)

Luke Velladc32569c85bd
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 53a814eca..004c1e49f 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -316,8 +316,6 @@
"unconfirmedEventsEmptyStateDescription": "Unconfirmed events will show up here.",
"canceledEventsEmptyStateTitle": "No Canceled Events",
"canceledEventsEmptyStateDescription": "Canceled events will show up here.",
- "setupFormTitle": "Setup",
- "setupFormDescription": "Finish setting up your account.",
"pending": "Pending",
"helpUsImprove": "Help us improve",
"helpUsImproveDesc": "Take a few minutes to share your feedback and help us shape the future of Rallly.",
@@ -459,5 +457,7 @@
"billingSettingsDescription": "View and manage your space's subscription and billing information.",
"planHobby": "Hobby",
"actionErrorServiceUnavailable": "The service required to perform this action is not available",
- "actionErrorPayloadTooLarge": "The file you uploaded is too large. Please try a smaller file."
+ "actionErrorPayloadTooLarge": "The file you uploaded is too large. Please try a smaller file.",
+ "spaceName": "Space Name",
+ "personal": "Personal"
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
index eb322cb5a..98cc376f1 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
@@ -1,10 +1,8 @@
import { SidebarInset } from "@rallly/ui/sidebar";
import type { Metadata } from "next";
-import { redirect } from "next/navigation";
-import { requireSpace, requireUser } from "@/auth/data";
+import { requireSpace } from "@/auth/data";
import { LicenseLimitWarning } from "@/features/licensing/components/license-limit-warning";
import { CommandMenu } from "@/features/navigation/command-menu";
-import { isUserOnboarded } from "@/features/setup/utils";
import { SpaceSidebar } from "./components/sidebar/space-sidebar";
import { SpaceSidebarProvider } from "./components/sidebar/space-sidebar-provider";
@@ -13,12 +11,6 @@ export default async function Layout({
}: {
children: React.ReactNode;
}) {
- const user = await requireUser();
-
- if (!isUserOnboarded(user)) {
- redirect("/setup");
- }
-
return (
<SpaceSidebarProvider>
<CommandMenu />
diff --git a/apps/web/src/app/[locale]/(space)/layout.tsx b/apps/web/src/app/[locale]/(space)/layout.tsx
index 2b41b0728..ebbe1cae7 100644
--- a/apps/web/src/app/[locale]/(space)/layout.tsx
+++ b/apps/web/src/app/[locale]/(space)/layout.tsx
@@ -1,16 +1,10 @@
-import { redirect } from "next/navigation";
import { requireSpace, requireUser } from "@/auth/data";
-import { isUserOnboarded } from "@/features/setup/utils";
import { SpaceProvider } from "@/features/space/client";
import { TimezoneProvider } from "@/lib/timezone/client/context";
async function loadData() {
const [user, space] = await Promise.all([requireUser(), requireSpace()]);
- if (!isUserOnboarded(user)) {
- redirect("/setup");
- }
-
return {
user,
space,
diff --git a/apps/web/src/app/[locale]/setup/page.tsx b/apps/web/src/app/[locale]/setup/page.tsx
index 8525f85cb..53ee0141e 100644
--- a/apps/web/src/app/[locale]/setup/page.tsx
+++ b/apps/web/src/app/[locale]/setup/page.tsx
@@ -1,18 +1,17 @@
import type { Metadata } from "next";
import { redirect } from "next/navigation";
-import { ProfilePicture } from "@/app/[locale]/(space)/account/profile/profile-picture";
import { requireUser } from "@/auth/data";
import { Logo } from "@/components/logo";
import { Trans } from "@/components/trans";
-import { SetupForm } from "@/features/setup/components/setup-form";
-import { isUserOnboarded } from "@/features/setup/utils";
+import { CreateSpaceForm } from "@/features/setup/components/create-space-form";
+import { userHasSpaces } from "@/features/setup/utils";
import { getTranslation } from "@/i18n/server";
export default async function SetupPage() {
const user = await requireUser();
- if (isUserOnboarded(user)) {
+ if (await userHasSpaces(user.id)) {
redirect("/");
}
@@ -25,24 +24,17 @@ export default async function SetupPage() {
</div>
<header className="text-center">
<h1 className="font-bold text-2xl">
- <Trans i18nKey="setupFormTitle" defaults="Setup" />
+ <Trans i18nKey="createSpace" defaults="Create Space" />
</h1>
<p className="mt-1 text-muted-foreground">
<Trans
- i18nKey="setupFormDescription"
- defaults="Finish setting up your account."
+ i18nKey="createSpaceDescription"
+ defaults="Create a space to organize your polls and events."
/>
</p>
</header>
- <main className="space-y-4">
- <ProfilePicture name={user.name} image={user.image ?? undefined} />
- <SetupForm
- defaultValues={{
- name: user.name ?? undefined,
- timeZone: user.timeZone ?? undefined,
- locale: user.locale ?? undefined,
- }}
- />
+ <main>
+ <CreateSpaceForm />
</main>
</article>
</div>
@@ -53,8 +45,8 @@ export default async function SetupPage() {
export async function generateMetadata(): Promise<Metadata> {
const { t } = await getTranslation();
return {
- title: t("setupFormTitle", {
- defaultValue: "Setup",
+ title: t("createSpace", {
+ defaultValue: "Create Space",
}),
};
}
diff --git a/apps/web/src/auth/data.ts b/apps/web/src/auth/data.ts
index 2569e5239..7a1ba1c6c 100644
--- a/apps/web/src/auth/data.ts
+++ b/apps/web/src/auth/data.ts
@@ -129,10 +129,7 @@ export const requireSpace = cache(async () => {
});
if (!spaceMember) {
- throw new AppError({
- code: "NOT_FOUND",
- message: "User does not belong to any spaces",
- });
+ redirect("/setup");
}
return createSpaceDTO({
diff --git a/apps/web/src/features/setup/actions.ts b/apps/web/src/features/setup/actions.ts
deleted file mode 100644
index 10f30012d..000000000
--- a/apps/web/src/features/setup/actions.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-"use server";
-import { prisma } from "@rallly/database";
-import { redirect } from "next/navigation";
-
-import { authActionClient } from "@/lib/safe-action/server";
-import { setupSchema } from "./schema";
-
-export const completeSetupAction = authActionClient
- .metadata({ actionName: "complete_setup" })
- .inputSchema(setupSchema)
- .action(async ({ parsedInput, ctx }) => {
- const { name, timeZone, locale } = parsedInput;
-
- await prisma.user.update({
- where: { id: ctx.user.id },
- data: {
- name,
- timeZone,
- locale,
- },
- });
-
- ctx.captureProperties({
- $set: {
- name,
- timeZone,
- locale,
- },
- });
-
- redirect("/");
- });
diff --git a/apps/web/src/features/setup/components/create-space-form.tsx b/apps/web/src/features/setup/components/create-space-form.tsx
new file mode 100644
index 000000000..b685ef4ef
--- /dev/null
+++ b/apps/web/src/features/setup/components/create-space-form.tsx
@@ -0,0 +1,95 @@
+"use client";
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Button } from "@rallly/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@rallly/ui/form";
+import { Input } from "@rallly/ui/input";
+import { useRouter } from "next/navigation";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+
+import { Trans } from "@/components/trans";
+import { createSpaceAction } from "@/features/space/actions";
+import { useTranslation } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+const createSpaceFormSchema = z.object({
+ name: z.string().min(1).max(100),
+});
+
+type CreateSpaceFormValues = z.infer<typeof createSpaceFormSchema>;
+
+export function CreateSpaceForm() {
+ const { t } = useTranslation();
+ const router = useRouter();
+
+ const form = useForm<CreateSpaceFormValues>({
+ resolver: zodResolver(createSpaceFormSchema),
+ defaultValues: {
+ name: t("personal", { defaultValue: "Personal" }),
+ },
+ });
+
+ const createSpace = useSafeAction(createSpaceAction, {
+ onSuccess: () => {
+ // Redirect to the main dashboard after successful space creation
+ router.push("/");
+ },
+ onError: (error) => {
+ console.error("Failed to create space:", error);
+ },
+ });
+
+ return (
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(({ name }) => {
+ createSpace.execute({ name });
+ })}
+ className="space-y-4"
+ >
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ <Trans i18nKey="spaceName" defaults="Space Name" />
+ </FormLabel>
+ <FormControl>
+ <Input
+ data-1p-ignore="true"
+ placeholder={t("spaceNamePlaceholder", {
+ defaultValue: "e.g. Acme Corp",
+ })}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {createSpace.result?.serverError && (
+ <FormMessage>{createSpace.result.serverError}</FormMessage>
+ )}
+
+ <Button
+ type="submit"
+ variant="primary"
+ loading={createSpace.isExecuting}
+ className="w-full"
+ >
+ <Trans i18nKey="createSpace" defaults="Create Space" />
+ </Button>
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/features/setup/components/setup-form.tsx b/apps/web/src/features/setup/components/setup-form.tsx
deleted file mode 100644
index cbf18b766..000000000
--- a/apps/web/src/features/setup/components/setup-form.tsx
+++ /dev/null
@@ -1,129 +0,0 @@
-"use client";
-
-import { zodResolver } from "@hookform/resolvers/zod";
-import { Button } from "@rallly/ui/button";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@rallly/ui/form";
-import { Input } from "@rallly/ui/input";
-import { useForm } from "react-hook-form";
-
-import { LanguageSelect } from "@/components/poll/language-selector";
-import { TimeZoneSelect } from "@/components/time-zone-picker/time-zone-select";
-import { Trans } from "@/components/trans";
-import { useTranslation } from "@/i18n/client";
-import { useSafeAction } from "@/lib/safe-action/client";
-import { useTimezone } from "@/lib/timezone";
-
-import { completeSetupAction } from "../actions";
-import type { SetupFormValues } from "../schema";
-import { setupSchema } from "../schema";
-
-interface SetupFormProps {
- defaultValues?: Partial<SetupFormValues>;
-}
-
-export function SetupForm({ defaultValues }: SetupFormProps) {
- const { timezone } = useTimezone();
- const { i18n } = useTranslation();
- const completeSetup = useSafeAction(completeSetupAction);
-
- const form = useForm<SetupFormValues>({
- resolver: zodResolver(setupSchema),
- defaultValues: {
- name: defaultValues?.name ?? "",
- timeZone: defaultValues?.timeZone || timezone,
- locale: defaultValues?.locale || i18n.language,
- },
- });
-
- return (
- <Form {...form}>
- <form
- onSubmit={form.handleSubmit(async (data) => {
- await completeSetup.executeAsync(data);
- })}
- >
- <div className="space-y-4">
- <FormField
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- <Trans i18nKey="name" defaults="Name" />
- </FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="timeZone"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- <Trans i18nKey="timeZone" defaults="Time Zone" />
- </FormLabel>
- <FormControl>
- <TimeZoneSelect
- className="w-full"
- value={field.value}
- onValueChange={field.onChange}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="locale"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- <Trans i18nKey="language" defaults="Language" />
- </FormLabel>
-
- <FormControl>
- <LanguageSelect
- className="w-full"
- value={field.value}
- onChange={(value) => {
- field.onChange(value);
- i18n.changeLanguage(value);
- }}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- {completeSetup.result.serverError && (
- <FormMessage>{completeSetup.result.serverError}</FormMessage>
- )}
- </div>
- <div className="mt-6">
- <Button
- variant="primary"
- type="submit"
- loading={form.formState.isSubmitting}
- className="w-full"
- >
- <Trans i18nKey="save" defaults="Save" />
- </Button>
- </div>
- </form>
- </Form>
- );
-}
diff --git a/apps/web/src/features/setup/schema.ts b/apps/web/src/features/setup/schema.ts
deleted file mode 100644
index b0fafd7fc..000000000
--- a/apps/web/src/features/setup/schema.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { z } from "zod";
-
-export const setupSchema = z.object({
- name: z.string().min(1),
- timeZone: z.string().min(1),
- locale: z.string().min(1),
-});
-
-export type SetupFormValues = z.infer<typeof setupSchema>;
-
-export const onboardedUserSchema = z.object({
- name: z.string().min(1),
- timeZone: z.string().min(1),
- locale: z.string().min(1),
-});
-
-export type OnboardedUser = z.infer<typeof onboardedUserSchema>;
diff --git a/apps/web/src/features/setup/types.ts b/apps/web/src/features/setup/types.ts
deleted file mode 100644
index da1adf5ed..000000000
--- a/apps/web/src/features/setup/types.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// Assuming you have a base User type somewhere, e.g., in prisma types or a shared types file
-import type { User as BaseUser } from "@prisma/client"; // Or wherever your base User type is
-
-// Define the type for a user who has completed onboarding
-// It extends the base user but makes required onboarding fields non-nullable
-export interface OnboardedUser extends BaseUser {
- name: string; // Guaranteed to be a string
- timeZone: string; // Guaranteed to be a string
- locale: string; // Guaranteed to be a string
-}
-
-// You might also want a type for the potentially un-onboarded user,
-// which could just be your BaseUser type
-export type PotentiallyUnonboardedUser = BaseUser;
diff --git a/apps/web/src/features/setup/utils.ts b/apps/web/src/features/setup/utils.ts
index 531d32f0e..11067c84e 100644
--- a/apps/web/src/features/setup/utils.ts
+++ b/apps/web/src/features/setup/utils.ts
@@ -1,6 +1,10 @@
-import { onboardedUserSchema } from "@/features/setup/schema";
-import type { UserDTO } from "@/features/user/schema";
+import { prisma } from "@rallly/database";
-export const isUserOnboarded = (user: UserDTO) => {
- return onboardedUserSchema.safeParse(user).success;
+export const userHasSpaces = async (userId: string): Promise<boolean> => {
+ const spaceCount = await prisma.spaceMember.count({
+ where: {
+ userId: userId,
+ },
+ });
+ return spaceCount > 0;
};