Skip to content

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

✨ Add options to delete and leave space (#1887)

Luke Vella0524efab2890
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 004c1e49f..acdf58525 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -260,7 +260,7 @@
"subscriptionPriceMonthly": "{price} per month",
"subscriptionPriceYearly": "{price} per year",
"billingSubscriptionTitle": "Subscription",
- "billingSubscriptionDescription": "View and manage your current subscription plan",
+ "billingSubscriptionDescription": "Manage your current subscription plan.",
"billingSubscriptionNotActive": "You are not currently subscribed to a plan.",
"billingSubscriptionUpgradeToProDescription": "Upgrade to Pro to get access to all features and benefits.",
"billingSubscriptionUpgradeToPro": "Upgrade to Pro",
@@ -459,5 +459,25 @@
"actionErrorServiceUnavailable": "The service required to perform this action is not available",
"actionErrorPayloadTooLarge": "The file you uploaded is too large. Please try a smaller file.",
"spaceName": "Space Name",
- "personal": "Personal"
+ "personal": "Personal",
+ "deleteSpaceDialogTitle": "Delete Space",
+ "deleteSpaceDialogDescription": "This will permanently delete the space and all polls inside it. This action cannot be undone.",
+ "deleteSpaceInstruction": "Please type the space name to confirm:",
+ "deleteSpacePermanently": "Delete Space Permanently",
+ "deleteSpace": "Delete Space",
+ "deletedSpaceSuccess": "Space has been permanently deleted",
+ "spaceNameMismatch": "Space name does not match",
+ "leaveSpaceDialogTitle": "Leave Space",
+ "leaveSpaceDialogDescription": "Are you sure you want to leave this space?",
+ "leaveSpaceInstruction": "Please type the space name to confirm:",
+ "leaveSpace": "Leave Space",
+ "leftSpaceSuccess": "You have left the space",
+ "leaveSpaceDescription": "Remove yourself from this space.",
+ "deleteSpaceDescription": "Permanently delete this space and all its contents. This action cannot be undone.",
+ "spaceSettings": "Space Settings",
+ "spaces": "Spaces",
+ "inviteMembers": "Invite Members",
+ "accessDenied": "Access Denied",
+ "ownerPermissionsRequired": "Only space owners can access billing settings.",
+ "deleteSpacePermission": "You need to be the owner to delete a space."
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/billing/page.tsx
index 398a737ae..67321dcc8 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/billing/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/billing/page.tsx
@@ -1,19 +1,24 @@
import { Button } from "@rallly/ui/button";
import { DialogTrigger } from "@rallly/ui/dialog";
import { Icon } from "@rallly/ui/icon";
-import { TabsContent } from "@rallly/ui/page-tabs";
-import { DotIcon, SendIcon } from "lucide-react";
+import { DotIcon, SendIcon, ShieldXIcon } from "lucide-react";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import {
- PageContent,
PageSection,
PageSectionContent,
PageSectionDescription,
+ PageSectionGroup,
PageSectionHeader,
PageSectionTitle,
} from "@/app/components/page-layout";
import { requireSpace, requireUser } from "@/auth/data";
+import {
+ EmptyState,
+ EmptyStateDescription,
+ EmptyStateIcon,
+ EmptyStateTitle,
+} from "@/components/empty-state";
import { PayWallDialog } from "@/components/pay-wall-dialog";
import { StackedList, StackedListItem } from "@/components/stacked-list";
import { Trans } from "@/components/trans";
@@ -30,106 +35,127 @@ export default async function BillingSettingsPage() {
if (!isFeatureEnabled("billing")) {
notFound();
}
- const [space] = await Promise.all([requireSpace(), requireUser()]);
+ const [space, user] = await Promise.all([requireSpace(), requireUser()]);
+
+ // Check if user is owner - only owners can access billing
+ const isOwner = space.ownerId === user.id;
+
+ if (!isOwner) {
+ return (
+ <EmptyState>
+ <EmptyStateIcon>
+ <ShieldXIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle>
+ <Trans i18nKey="accessDenied" defaults="Access Denied" />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <Trans
+ i18nKey="ownerPermissionsRequired"
+ defaults="Only space owners can access billing settings."
+ />
+ </EmptyStateDescription>
+ </EmptyState>
+ );
+ }
+
const subscription = await getSpaceSubscription(space.id);
return (
- <TabsContent value="billing">
- <PageContent className="space-y-6">
- <PageSection>
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="billingPlanTitle" defaults="Plan" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="billingSubscriptionDescription"
- defaults="Manage your current subscription plan"
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <StackedList>
- <StackedListItem>
- <SpaceTierIcon tier={space.tier} />
- <div className="flex-1">
- <div className="font-semibold text-sm">
- <SpaceTierLabel tier={space.tier} />
- </div>
- {subscription ? (
- <ul className="flex items-center gap-0.5 text-muted-foreground text-sm">
- <li>
- <SubscriptionStatus
- status={subscription.status}
- cancelAtPeriodEnd={subscription.cancelAtPeriodEnd}
- periodEnd={subscription.periodEnd}
- />
- </li>
- <li>
- <Icon>
- <DotIcon />
- </Icon>
- </li>
- <li>
- <Trans
- i18nKey="seatCount"
- defaults="{count, plural, {one, # seat} {other, # seats}}"
- values={{ count: subscription?.quantity }}
- />
- </li>
- </ul>
- ) : (
- <p className="text-muted-foreground text-sm">
- <Trans i18nKey="priceFree" />
- </p>
- )}
- </div>
- <div>
- {subscription ? (
- <Button asChild>
- <a href="/api/stripe/portal">
- <Trans i18nKey="manage" />
- </a>
- </Button>
- ) : (
- <PayWallDialog>
- <DialogTrigger asChild>
- <Button>
- <Trans i18nKey="upgradeToPro" />
- </Button>
- </DialogTrigger>
- </PayWallDialog>
- )}
+ <PageSectionGroup>
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="billingPlanTitle" defaults="Plan" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="billingSubscriptionDescription"
+ defaults="Manage your current subscription plan"
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <StackedList>
+ <StackedListItem>
+ <SpaceTierIcon tier={space.tier} />
+ <div className="flex-1">
+ <div className="font-semibold text-sm">
+ <SpaceTierLabel tier={space.tier} />
</div>
- </StackedListItem>
- </StackedList>
- </PageSectionContent>
- </PageSection>
- <PageSection>
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="support" defaults="Support" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="supportDescription"
- defaults="Need help with anything?"
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <Button asChild>
- <a href="mailto:[email protected]">
- <Icon>
- <SendIcon />
- </Icon>
- <Trans i18nKey="contactSupport" defaults="Contact Support" />
- </a>
- </Button>
- </PageSectionContent>
- </PageSection>
- </PageContent>
- </TabsContent>
+ {subscription ? (
+ <ul className="flex items-center gap-px text-muted-foreground text-sm">
+ <li>
+ <SubscriptionStatus
+ status={subscription.status}
+ cancelAtPeriodEnd={subscription.cancelAtPeriodEnd}
+ periodEnd={subscription.periodEnd}
+ />
+ </li>
+ <li>
+ <Icon>
+ <DotIcon />
+ </Icon>
+ </li>
+ <li>
+ <Trans
+ i18nKey="seatCount"
+ defaults="{count, plural, {one, # seat} {other, # seats}}"
+ values={{ count: subscription?.quantity }}
+ />
+ </li>
+ </ul>
+ ) : (
+ <p className="text-muted-foreground text-sm">
+ <Trans i18nKey="priceFree" />
+ </p>
+ )}
+ </div>
+ <div>
+ {subscription ? (
+ <Button asChild>
+ <a href="/api/stripe/portal">
+ <Trans i18nKey="manage" />
+ </a>
+ </Button>
+ ) : (
+ <PayWallDialog>
+ <DialogTrigger asChild>
+ <Button>
+ <Trans i18nKey="upgradeToPro" />
+ </Button>
+ </DialogTrigger>
+ </PayWallDialog>
+ )}
+ </div>
+ </StackedListItem>
+ </StackedList>
+ </PageSectionContent>
+ </PageSection>
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="support" defaults="Support" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="supportDescription"
+ defaults="Need help with anything?"
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <Button asChild>
+ <a href="mailto:[email protected]">
+ <Icon>
+ <SendIcon />
+ </Icon>
+ <Trans i18nKey="contactSupport" defaults="Contact Support" />
+ </a>
+ </Button>
+ </PageSectionContent>
+ </PageSection>
+ </PageSectionGroup>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/components/settings-tabs.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/components/settings-tabs.tsx
index 3529c7fb4..aa251f717 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/components/settings-tabs.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/components/settings-tabs.tsx
@@ -31,7 +31,9 @@ export function SettingsTabs({ children }: { children: React.ReactNode }) {
</TabsTrigger>
</IfFeatureEnabled>
</TabsList>
- <TabsContent value={activeTab}>{children}</TabsContent>
+ <TabsContent tabIndex={-1} value={activeTab}>
+ {children}
+ </TabsContent>
</Tabs>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/delete-space-button.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/delete-space-button.tsx
new file mode 100644
index 000000000..982158364
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/delete-space-button.tsx
@@ -0,0 +1,160 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import type { DialogProps } from "@rallly/ui/dialog";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@rallly/ui/dialog";
+import { Form, FormField, FormItem, FormMessage } from "@rallly/ui/form";
+import { Input } from "@rallly/ui/input";
+import { toast } from "@rallly/ui/sonner";
+import { TrashIcon } from "lucide-react";
+import { useRouter } from "next/navigation";
+import { useForm } from "react-hook-form";
+
+import { Trans } from "@/components/trans";
+import { deleteSpaceAction } from "@/features/space/actions";
+import { useTranslation } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+interface DeleteSpaceDialogProps extends DialogProps {
+ spaceName: string;
+ spaceId: string;
+}
+
+function DeleteSpaceDialog({
+ spaceName,
+ spaceId,
+ children,
+ ...rest
+}: DeleteSpaceDialogProps) {
+ const form = useForm<{ spaceName: string }>({
+ defaultValues: {
+ spaceName: "",
+ },
+ });
+
+ const deleteSpace = useSafeAction(deleteSpaceAction, {
+ onSuccess: () => {
+ toast.success(
+ t("deletedSpaceSuccess", {
+ defaultValue: "Space has been permanently deleted",
+ }),
+ );
+ router.push("/");
+ },
+ });
+
+ const router = useRouter();
+ const { t } = useTranslation();
+
+ return (
+ <Form {...form}>
+ <Dialog {...rest}>
+ {children}
+ <DialogContent>
+ <form
+ onSubmit={form.handleSubmit(() => {
+ deleteSpace.execute({ spaceId });
+ })}
+ >
+ <DialogHeader>
+ <DialogTitle>
+ <Trans
+ i18nKey="deleteSpaceDialogTitle"
+ defaults="Delete Space"
+ />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="deleteSpaceDialogDescription"
+ defaults="This will permanently delete the space. This action cannot be undone."
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <div className="space-y-4 py-4">
+ <p className="text-sm">
+ <Trans
+ i18nKey="deleteSpaceInstruction"
+ defaults="Please type the space name to confirm: {{spaceName}}"
+ values={{ spaceName }}
+ />
+ </p>
+ <FormField
+ control={form.control}
+ name="spaceName"
+ rules={{
+ validate: (value) => {
+ if (value !== spaceName) {
+ return t("spaceNameMismatch", {
+ defaultValue: "Space name does not match",
+ });
+ }
+ return true;
+ },
+ }}
+ render={({ field }) => (
+ <FormItem>
+ <Input
+ autoComplete="off"
+ data-1p-ignore
+ error={!!form.formState.errors.spaceName}
+ placeholder={spaceName}
+ {...field}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button>
+ <Trans i18nKey="cancel" defaults="Cancel" />
+ </Button>
+ </DialogClose>
+ <Button
+ type="submit"
+ loading={deleteSpace.isExecuting}
+ variant="destructive"
+ >
+ <Trans
+ i18nKey="deleteSpacePermanently"
+ defaults="Delete Space Permanently"
+ />
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ </Form>
+ );
+}
+
+interface DeleteSpaceButtonProps {
+ spaceName: string;
+ spaceId: string;
+}
+
+export function DeleteSpaceButton({
+ spaceName,
+ spaceId,
+}: DeleteSpaceButtonProps) {
+ return (
+ <DeleteSpaceDialog spaceName={spaceName} spaceId={spaceId}>
+ <DialogTrigger asChild>
+ <Button className="text-destructive">
+ <TrashIcon className="size-4" />
+ <Trans i18nKey="deleteSpace" defaults="Delete Space" />
+ </Button>
+ </DialogTrigger>
+ </DeleteSpaceDialog>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/leave-space-button.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/leave-space-button.tsx
new file mode 100644
index 000000000..8f182e124
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/leave-space-button.tsx
@@ -0,0 +1,156 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import type { DialogProps } from "@rallly/ui/dialog";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@rallly/ui/dialog";
+import { Form, FormField, FormItem, FormMessage } from "@rallly/ui/form";
+import { Icon } from "@rallly/ui/icon";
+import { Input } from "@rallly/ui/input";
+import { toast } from "@rallly/ui/sonner";
+import { LogOutIcon } from "lucide-react";
+import { useRouter } from "next/navigation";
+import { useForm } from "react-hook-form";
+import { Trans } from "@/components/trans";
+import { leaveSpaceAction } from "@/features/space/actions";
+import { useTranslation } from "@/i18n/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+
+interface LeaveSpaceDialogProps extends DialogProps {
+ spaceName: string;
+ spaceId: string;
+}
+
+function LeaveSpaceDialog({
+ spaceName,
+ spaceId,
+ children,
+ ...rest
+}: LeaveSpaceDialogProps) {
+ const form = useForm<{ spaceName: string }>({
+ defaultValues: {
+ spaceName: "",
+ },
+ });
+
+ const leaveSpace = useSafeAction(leaveSpaceAction, {
+ onSuccess: () => {
+ toast.success(
+ t("leftSpaceSuccess", {
+ defaultValue: "You have left the space",
+ }),
+ );
+ router.push("/");
+ },
+ });
+
+ const router = useRouter();
+ const { t } = useTranslation();
+
+ return (
+ <Form {...form}>
+ <Dialog {...rest}>
+ {children}
+ <DialogContent>
+ <form
+ onSubmit={form.handleSubmit(() => {
+ leaveSpace.execute();
+ })}
+ >
+ <DialogHeader>
+ <DialogTitle>
+ <Trans i18nKey="leaveSpaceDialogTitle" defaults="Leave Space" />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="leaveSpaceDialogDescription"
+ defaults="Are you sure you want to leave this space?"
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <div className="space-y-4 py-4">
+ <p className="text-sm">
+ <Trans
+ i18nKey="leaveSpaceInstruction"
+ defaults="Please type the space name to confirm: {{spaceName}}"
+ values={{ spaceName }}
+ />
+ </p>
+ <FormField
+ control={form.control}
+ name="spaceName"
+ rules={{
+ validate: (value) => {
+ if (value !== spaceName) {
+ return t("spaceNameMismatch", {
+ defaultValue: "Space name does not match",
+ });
+ }
+ return true;
+ },
+ }}
+ render={({ field }) => (
+ <FormItem>
+ <Input
+ autoComplete="off"
+ data-1p-ignore
+ error={!!form.formState.errors.spaceName}
+ placeholder={spaceName}
+ {...field}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button>
+ <Trans i18nKey="cancel" defaults="Cancel" />
+ </Button>
+ </DialogClose>
+ <Button
+ type="submit"
+ loading={leaveSpace.isExecuting}
+ variant="destructive"
+ >
+ <Trans i18nKey="leaveSpace" defaults="Leave Space" />
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ </Form>
+ );
+}
+
+interface LeaveSpaceButtonProps {
+ spaceName: string;
+ spaceId: string;
+}
+
+export function LeaveSpaceButton({
+ spaceName,
+ spaceId,
+}: LeaveSpaceButtonProps) {
+ return (
+ <LeaveSpaceDialog spaceName={spaceName} spaceId={spaceId}>
+ <DialogTrigger asChild>
+ <Button>
+ <Icon>
+ <LogOutIcon />
+ </Icon>
+ <Trans i18nKey="leaveSpace" defaults="Leave Space" />
+ </Button>
+ </DialogTrigger>
+ </LeaveSpaceDialog>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/space-settings-form.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/space-settings-form.tsx
index c6483e231..3f1b1a994 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/space-settings-form.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/components/space-settings-form.tsx
@@ -16,6 +16,7 @@ import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
import {
+ ImageUpload,
ImageUploadControl,
ImageUploadPreview,
} from "@/components/image-upload";
@@ -28,7 +29,6 @@ import {
import { SpaceIcon } from "@/features/space/components/space-icon";
import type { SpaceDTO } from "@/features/space/types";
import { useTranslation } from "@/i18n/client";
-import { useFeatureFlag } from "@/lib/feature-flags/client";
import { useSafeAction } from "@/lib/safe-action/client";
const spaceSettingsSchema = z.object({
@@ -42,12 +42,15 @@ type SpaceSettingsData = z.infer<typeof spaceSettingsSchema>;
interface SpaceSettingsFormProps {
space: SpaceDTO;
+ disabled?: boolean;
}
-export function SpaceSettingsForm({ space }: SpaceSettingsFormProps) {
+export function SpaceSettingsForm({
+ space,
+ disabled = false,
+}: SpaceSettingsFormProps) {
const { t } = useTranslation();
const router = useRouter();
- const isStorageEnabled = useFeatureFlag("storage");
const updateSpace = useSafeAction(updateSpaceAction);
const updateImage = useSafeAction(updateSpaceImageAction);
@@ -92,24 +95,22 @@ export function SpaceSettingsForm({ space }: SpaceSettingsFormProps) {
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
- {isStorageEnabled && (
- <div>
- <FormLabel>
- <Trans i18nKey="image" defaults="Image" />
- </FormLabel>
- <div className="mt-2 flex items-center gap-x-4">
- <ImageUploadPreview>
- <SpaceIcon name={space.name} src={space.image} size="xl" />
- </ImageUploadPreview>
- <ImageUploadControl
- keyPrefix="spaces"
- onUploadSuccess={handleImageUploadSuccess}
- onRemoveSuccess={handleImageRemoveSuccess}
- hasCurrentImage={!!space.image}
- />
- </div>
- </div>
- )}
+ <div>
+ <FormLabel>
+ <Trans i18nKey="image" defaults="Image" />
+ </FormLabel>
+ <ImageUpload className="mt-2">
+ <ImageUploadPreview>
+ <SpaceIcon name={space.name} src={space.image} size="xl" />
+ </ImageUploadPreview>
+ <ImageUploadControl
+ keyPrefix="spaces"
+ onUploadSuccess={handleImageUploadSuccess}
+ onRemoveSuccess={handleImageRemoveSuccess}
+ hasCurrentImage={!!space.image}
+ />
+ </ImageUpload>
+ </div>
<FormField
control={form.control}
name="name"
@@ -124,6 +125,7 @@ export function SpaceSettingsForm({ space }: SpaceSettingsFormProps) {
placeholder={t("spaceNamePlaceholder", {
defaultValue: "My Team",
})}
+ disabled={disabled}
{...field}
/>
</FormControl>
@@ -135,7 +137,9 @@ export function SpaceSettingsForm({ space }: SpaceSettingsFormProps) {
<Button
type="submit"
disabled={
- updateSpace.status === "executing" || !form.formState.isDirty
+ disabled ||
+ updateSpace.status === "executing" ||
+ !form.formState.isDirty
}
>
<Trans i18nKey="save" defaults="Save" />
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/page.tsx
index 136cf9f73..ad49204c0 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/general/page.tsx
@@ -1,42 +1,94 @@
-import { TabsContent } from "@rallly/ui/page-tabs";
+import { subject } from "@casl/ability";
+import { Alert, AlertTitle } from "@rallly/ui/alert";
+import { ShieldXIcon } from "lucide-react";
import type { Metadata } from "next";
import {
- PageContent,
PageSection,
PageSectionContent,
PageSectionDescription,
+ PageSectionGroup,
PageSectionHeader,
PageSectionTitle,
} from "@/app/components/page-layout";
-import { requireSpace } from "@/auth/data";
+import { requireSpace, requireUser } from "@/auth/data";
import { Trans } from "@/components/trans";
+import { defineAbilityForMember } from "@/features/space/member/ability";
import { getTranslation } from "@/i18n/server";
+import { DeleteSpaceButton } from "./components/delete-space-button";
+import { LeaveSpaceButton } from "./components/leave-space-button";
import { SpaceSettingsForm } from "./components/space-settings-form";
export default async function GeneralSettingsPage() {
- const space = await requireSpace();
+ const [space, user] = await Promise.all([requireSpace(), requireUser()]);
+ const ability = defineAbilityForMember({ space, user });
+ const isAdmin = space.role === "admin";
+ const canDeleteSpace = ability.can("delete", subject("Space", { ...space }));
return (
- <TabsContent value="general">
- <PageContent className="space-y-6">
- <PageSection>
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="spaceInformation" defaults="Space Information" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="spaceInformationDescription"
- defaults="Update your space name and basic settings."
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <SpaceSettingsForm space={space} />
- </PageSectionContent>
- </PageSection>
- </PageContent>
- </TabsContent>
+ <PageSectionGroup>
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="spaceInformation" defaults="Space Information" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="spaceInformationDescription"
+ defaults="Update your space name and basic settings."
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <SpaceSettingsForm space={space} disabled={!isAdmin} />
+ </PageSectionContent>
+ </PageSection>
+
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="leaveSpace" defaults="Leave Space" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="leaveSpaceDescription"
+ defaults="Remove yourself from this space. You'll lose access to all polls in this space."
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <LeaveSpaceButton spaceName={space.name} spaceId={space.id} />
+ </PageSectionContent>
+ </PageSection>
+
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="deleteSpace" defaults="Delete Space" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="deleteSpaceDescription"
+ defaults="Permanently delete this space and all its content. This action cannot be undone."
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ {!canDeleteSpace ? (
+ <Alert>
+ <ShieldXIcon />
+ <AlertTitle>
+ <Trans
+ i18nKey="deleteSpacePermission"
+ defaults="You need to be the owner to delete a space."
+ />
+ </AlertTitle>
+ </Alert>
+ ) : (
+ <DeleteSpaceButton spaceName={space.name} spaceId={space.id} />
+ )}
+ </PageSectionContent>
+ </PageSection>
+ </PageSectionGroup>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/members/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/members/page.tsx
index 62948db44..e3a50e0a6 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/settings/members/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/settings/members/page.tsx
@@ -5,6 +5,7 @@ import {
PageSection,
PageSectionContent,
PageSectionDescription,
+ PageSectionGroup,
PageSectionHeader,
PageSectionTitle,
} from "@/app/components/page-layout";
@@ -21,7 +22,7 @@ export default async function MembersSettingsPage() {
const [members, invites] = await Promise.all([loadMembers(), loadInvites()]);
return (
- <div className="space-y-8">
+ <PageSectionGroup>
<PageSection>
<PageSectionHeader>
<PageSectionTitle>
@@ -114,7 +115,7 @@ export default async function MembersSettingsPage() {
<InviteMemberButton />
</PageSectionContent>
</PageSection>
- </div>
+ </PageSectionGroup>
);
}
diff --git a/apps/web/src/app/components/page-layout.tsx b/apps/web/src/app/components/page-layout.tsx
index 5e99cf85d..1c0c93d94 100644
--- a/apps/web/src/app/components/page-layout.tsx
+++ b/apps/web/src/app/components/page-layout.tsx
@@ -117,6 +117,10 @@ export function PageSkeleton() {
);
}
+export function PageSectionGroup({ children }: { children?: React.ReactNode }) {
+ return <div className="space-y-6 lg:space-y-12">{children}</div>;
+}
+
export function PageSection({
children,
className,
@@ -126,7 +130,7 @@ export function PageSection({
}) {
return (
<section
- className={cn("grid gap-6 lg:grid-cols-[320px_1fr] lg:gap-8", className)}
+ className={cn("grid gap-4 lg:grid-cols-[320px_1fr] lg:gap-12", className)}
>
{children}
</section>
@@ -165,7 +169,12 @@ export function PageSectionDescription({
className?: string;
}) {
return (
- <p className={cn("mt-2 text-muted-foreground text-sm", className)}>
+ <p
+ className={cn(
+ "mt-2 text-muted-foreground text-sm leading-relaxed",
+ className,
+ )}
+ >
{children}
</p>
);
diff --git a/apps/web/src/components/image-upload.tsx b/apps/web/src/components/image-upload.tsx
index 36b7aaaba..3bef00945 100644
--- a/apps/web/src/components/image-upload.tsx
+++ b/apps/web/src/components/image-upload.tsx
@@ -7,6 +7,7 @@ import React from "react";
import { z } from "zod";
import { Trans } from "@/components/trans";
import { useTranslation } from "@/i18n/client";
+import { useFeatureFlag } from "@/lib/feature-flags/client";
import { useSafeAction } from "@/lib/safe-action/client";
import { getImageUploadUrlAction } from "@/lib/storage/actions";
import { uploadImage } from "@/lib/storage/image-upload";
@@ -25,8 +26,16 @@ export interface ImageUploadPreviewProps {
children?: React.ReactNode;
}
-export function ImageUpload({ children }: { children?: React.ReactNode }) {
- return <div className="flex items-center gap-x-4">{children}</div>;
+export function ImageUpload({
+ className,
+ children,
+}: {
+ className?: string;
+ children?: React.ReactNode;
+}) {
+ return (
+ <div className={cn("flex items-center gap-x-4", className)}>{children}</div>
+ );
}
export function ImageUploadControl({
@@ -35,6 +44,8 @@ export function ImageUploadControl({
onRemoveSuccess,
hasCurrentImage = false,
}: ImageUploadControlProps) {
+ const isStorageEnabled = useFeatureFlag("storage");
+
const { t } = useTranslation();
const [isRemoving, startRemoving] = React.useTransition();
const [isUploading, startUploading] = React.useTransition();
@@ -127,6 +138,7 @@ export function ImageUploadControl({
<div className="flex gap-2">
<Button
loading={isUploading}
+ disabled={!isStorageEnabled}
onClick={() => {
document.getElementById("image-upload")?.click();
}}
diff --git a/apps/web/src/features/navigation/config.tsx b/apps/web/src/features/navigation/config.tsx
index 9eaf9d5c2..2169e0092 100644
--- a/apps/web/src/features/navigation/config.tsx
+++ b/apps/web/src/features/navigation/config.tsx
@@ -1,6 +1,5 @@
"use client";
-import { subject } from "@casl/ability";
import type { LucideIcon } from "lucide-react";
import {
BarChart2Icon,
@@ -10,7 +9,6 @@ import {
} from "lucide-react";
import { usePathname } from "next/navigation";
import React from "react";
-import { useSpace } from "@/features/space/client";
import { isSpacesEnabled } from "@/features/space/constants";
import { useTranslation } from "@/i18n/client";
@@ -37,11 +35,6 @@ export interface NavigationConfig {
export const useSpaceMenu = () => {
const { t } = useTranslation();
- const space = useSpace();
-
- const canManageSpace = space
- .getMemberAbility()
- .can("update", subject("Space", space.data));
const pathname = usePathname();
const config = React.useMemo<NavigationConfig>(
@@ -79,7 +72,7 @@ export const useSpaceMenu = () => {
},
],
},
- ...(isSpacesEnabled && canManageSpace
+ ...(isSpacesEnabled
? [
{
id: "manage",
@@ -98,7 +91,7 @@ export const useSpaceMenu = () => {
: []),
],
}),
- [pathname, t, canManageSpace],
+ [pathname, t],
);
return React.useMemo(
diff --git a/apps/web/src/features/space/actions.ts b/apps/web/src/features/space/actions.ts
index c521e1a79..8ecb628c6 100644
--- a/apps/web/src/features/space/actions.ts
+++ b/apps/web/src/features/space/actions.ts
@@ -5,6 +5,7 @@ import { accessibleBy } from "@casl/prisma";
import { prisma } from "@rallly/database";
import { absoluteUrl } from "@rallly/utils/absolute-url";
import { waitUntil } from "@vercel/functions";
+import { revalidatePath } from "next/cache";
import { z } from "zod";
import { updateSeatCount } from "@/features/billing/mutations";
import { getMember } from "@/features/space/data";
@@ -88,7 +89,7 @@ export const createSpaceAction = authActionClient
});
});
-export const deleteSpaceAction = authActionClient
+export const deleteSpaceAction = spaceActionClient
.metadata({
actionName: "space_delete",
})
@@ -100,7 +101,7 @@ export const deleteSpaceAction = authActionClient
.action(async ({ ctx, parsedInput }) => {
const space = await prisma.space.findFirst({
where: {
- AND: [accessibleBy(ctx.ability).Space, { id: parsedInput.spaceId }],
+ id: parsedInput.spaceId,
},
include: {
subscription: true,
@@ -114,18 +115,29 @@ export const deleteSpaceAction = authActionClient
});
}
- if (ctx.ability.cannot("delete", subject("Space", space))) {
+ if (ctx.getMemberAbility().cannot("delete", subject("Space", space))) {
throw new AppError({
code: "FORBIDDEN",
message: "You do not have access to this space",
});
}
+ // Check if space has an active subscription
+ if (space.subscription?.active) {
+ throw new AppError({
+ code: "FORBIDDEN",
+ message:
+ "Cannot delete space with an active subscription. Please cancel the subscription first.",
+ });
+ }
+
await prisma.space.delete({
where: {
id: parsedInput.spaceId,
},
});
+
+ revalidatePath("/", "layout");
});
export const inviteMemberAction = spaceActionClient
@@ -563,3 +575,78 @@ export const removeSpaceImageAction = spaceActionClient
await deleteImageFromS3(oldImageKey);
}
});
+
+export const leaveSpaceAction = spaceActionClient
+ .metadata({
+ actionName: "space_leave",
+ })
+ .action(async ({ ctx }) => {
+ // Check if user is the space owner
+ if (ctx.space.ownerId === ctx.user.id) {
+ throw new AppError({
+ code: "FORBIDDEN",
+ message:
+ "Space owners cannot leave their space. Transfer ownership first.",
+ });
+ }
+
+ // Get the user's member record
+ const member = await prisma.spaceMember.findFirst({
+ where: {
+ spaceId: ctx.space.id,
+ userId: ctx.user.id,
+ },
+ });
+
+ if (!member) {
+ throw new AppError({
+ code: "NOT_FOUND",
+ message: "You are not a member of this space",
+ });
+ }
+
+ // Check if user has other spaces
+ const userSpaces = await prisma.spaceMember.findMany({
+ where: {
+ userId: ctx.user.id,
+ NOT: {
+ spaceId: ctx.space.id,
+ },
+ },
+ orderBy: {
+ lastSelectedAt: "desc",
+ },
+ });
+
+ if (userSpaces.length === 0) {
+ throw new AppError({
+ code: "FORBIDDEN",
+ message: "Cannot leave your last remaining space",
+ });
+ }
+
+ await prisma.$transaction(async (tx) => {
+ // Remove the user from the space
+ await tx.spaceMember.delete({
+ where: {
+ id: member.id,
+ },
+ });
+
+ // Update the most recent remaining space to be current
+ // (this handles the case where they're leaving their active space)
+ await tx.spaceMember.update({
+ where: {
+ id: userSpaces[0].id,
+ },
+ data: {
+ lastSelectedAt: new Date(),
+ },
+ });
+
+ // Update seat count if billing is enabled
+ if (isFeatureEnabled("billing")) {
+ await updateSeatCount(ctx.space.id, -1);
+ }
+ });
+ });
diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsx
index 29e84730c..5c088b63e 100644
--- a/apps/web/src/features/space/client.tsx
+++ b/apps/web/src/features/space/client.tsx
@@ -47,6 +47,7 @@ export const SpaceProvider = ({
},
space: {
id: data.id,
+ ownerId: data.ownerId,
role: data.role,
},
}),
diff --git a/apps/web/src/features/space/components/space-dropdown.tsx b/apps/web/src/features/space/components/space-dropdown.tsx
index 692b6494b..01ccd9cc3 100644
--- a/apps/web/src/features/space/components/space-dropdown.tsx
+++ b/apps/web/src/features/space/components/space-dropdown.tsx
@@ -5,13 +5,14 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@rallly/ui/dropdown-menu";
import { Icon } from "@rallly/ui/icon";
-import { CirclePlusIcon, SettingsIcon } from "lucide-react";
+import { CirclePlusIcon, SettingsIcon, UserPlusIcon } from "lucide-react";
import Link from "next/link";
import { RouterLoadingIndicator } from "@/components/router-loading-indicator";
import { Trans } from "@/components/trans";
@@ -51,6 +52,9 @@ export function SpaceDropdown({
className="min-w-[var(--radix-dropdown-menu-trigger-width)]"
align="start"
>
+ <DropdownMenuLabel>
+ <Trans i18nKey="spaces" defaults="Spaces" />
+ </DropdownMenuLabel>
<DropdownMenuRadioGroup
value={activeSpaceId}
onValueChange={(value) => {
@@ -70,20 +74,29 @@ export function SpaceDropdown({
))}
</DropdownMenuRadioGroup>
<DropdownMenuSeparator />
- <DropdownMenuItem onClick={newSpaceDialog.trigger}>
- <Icon>
- <CirclePlusIcon />
- </Icon>
- <Trans i18nKey="createSpace" defaults="Create Space" />
- </DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href="/settings/general">
<Icon>
<SettingsIcon />
</Icon>
- <Trans i18nKey="settings" defaults="Settings" />
+ <Trans i18nKey="spaceSettings" defaults="Space Settings" />
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <Link href="/settings/members">
+ <Icon>
+ <UserPlusIcon />
+ </Icon>
+ <Trans i18nKey="inviteMembers" defaults="Invite Members" />
</Link>
</DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onClick={newSpaceDialog.trigger}>
+ <Icon>
+ <CirclePlusIcon />
+ </Icon>
+ <Trans i18nKey="createSpace" defaults="Create Space" />
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
{setActiveSpace.isExecuting ? <RouterLoadingIndicator /> : null}
diff --git a/apps/web/src/features/space/member/ability.ts b/apps/web/src/features/space/member/ability.ts
index e3f988cc7..5bcf1b057 100644
--- a/apps/web/src/features/space/member/ability.ts
+++ b/apps/web/src/features/space/member/ability.ts
@@ -7,7 +7,7 @@ import type { MemberRole } from "@/features/space/schema";
export type MemberAbilityContext = {
user: { id: string };
- space: { id: string; role: MemberRole };
+ space: { id: string; ownerId: string; role: MemberRole };
};
type Action = "cancel" | "create" | "read" | "update" | "delete";
@@ -47,6 +47,14 @@ export function defineAbilityForMember(ctx?: MemberAbilityContext) {
break;
}
+ const isOwner = ctx.space.ownerId === ctx.user.id;
+
+ if (isOwner) {
+ builder.can("delete", "Space", {
+ ownerId: ctx.user.id,
+ });
+ }
+
return builder.build();
}