Skip to content

Commit

Permalink
fix(web): readonly name and slug fields in workspace settings
Browse files Browse the repository at this point in the history
  • Loading branch information
IKatsuba committed May 6, 2024
1 parent 209e9dc commit 9485869
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Switch } from '@saasfy/ui/switch';
import { toast } from '@saasfy/ui/use-toast';

const FormSchema = z.object({
marketing_emails: z.boolean().default(false).optional(),
security_emails: z.boolean(),
});

Expand All @@ -30,14 +29,7 @@ export default function Notifications() {
});

function onSubmit(data: z.infer<typeof FormSchema>) {
toast({
title: 'You submitted the following values:',
description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
</pre>
),
});
console.log(data);
}

return (
Expand All @@ -46,23 +38,6 @@ export default function Notifications() {
<div>
<h3 className="mb-4 text-lg font-medium">Email Notifications</h3>
<div className="space-y-4">
<FormField
control={form.control}
name="marketing_emails"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">Marketing emails</FormLabel>
<FormDescription>
Receive emails about new products, features, and more.
</FormDescription>
</div>
<FormControl>
<Switch checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
</FormItem>
)}
/>
<FormField
control={form.control}
name="security_emails"
Expand Down
40 changes: 38 additions & 2 deletions apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { redirect } from 'next/navigation';

import { createAdminClient, getUser } from '@saasfy/supabase/server';
import { Button } from '@saasfy/ui/button';
import {
Card,
Expand All @@ -9,7 +12,26 @@ import {
} from '@saasfy/ui/card';
import { Input } from '@saasfy/ui/input';

export default function Settings() {
export default async function Settings({ params }: { params: { workspaceSlug: string } }) {
const user = await getUser();

if (!user) {
return redirect('/login');
}

const supabase = createAdminClient();

const { data: workspace } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();

if (!workspace) {
return redirect('/not-found');
}

return (
<>
<Card>
Expand All @@ -19,7 +41,21 @@ export default function Settings() {
</CardHeader>
<CardContent>
<form>
<Input />
<Input defaultValue={workspace.name} readOnly />
</form>
</CardContent>
<CardFooter className="border-t px-6 py-4">
<Button>Save</Button>
</CardFooter>
</Card>
<Card>
<CardHeader>
<CardTitle>Workspace Slug</CardTitle>
<CardDescription>The slug of your workspace</CardDescription>
</CardHeader>
<CardContent>
<form>
<Input defaultValue={workspace.slug} readOnly />
</form>
</CardContent>
<CardFooter className="border-t px-6 py-4">
Expand Down

0 comments on commit 9485869

Please sign in to comment.