| 1 | 'use client' |
| 2 | |
| 3 | import { zodResolver } from '@hookform/resolvers/zod' |
| 4 | import { useRouter } |
| 5 | import { useState } |
| 6 | import { Controller, useForm |
| 7 | import { toast } |
| 8 | import type { z |
| 9 | import { Button } |
| 10 | import { |
| 11 | Card, |
| 12 | CardContent, |
| 13 | CardDescription, |
| 14 | CardHeader, |
| 15 | CardTitle, |
| 16 | } from '@/components/ui/card' |
| 17 | import { |
| 18 | Field, |
| 19 | FieldDescription, |
| 20 | FieldError, |
| 21 | FieldGroup, |
| 22 | FieldLabel, |
| 23 | } from '@/components/ui/field' |
| 24 | import { Input } |
| 25 | import { authClient } |
| 26 | import { titleToSlug } |
| 27 | import { analyticsService } |
| 28 | import { createNewOrganizationSchema } |
| 29 | |
| 30 | export default function OnboardingPageClient |
| 31 | const form = |
| 32 | resolver: zodResolver(createNewOrganizationSchema |
| 33 | defaultValues: {}, |
| 34 | }) |
| 35 | const [isLoading, |
| 36 | const router = |
| 37 | |
| 38 | const nameValue = |
| 39 | const slugPreview = |
| 40 | |
| 41 | async function handleSubmit |
| 42 | data: z |
| 43 | ) { |
| 44 | setIsLoading(true) |
| 45 | try { |
| 46 | const { slugified, |
| 47 | const slugVerify = |
| 48 | slug: slugified, |
| 49 | }) |
| 50 | |
| 51 | const organization = |
| 52 | name: data.name |
| 53 | slug: slugVerify.data |
| 54 | }) |
| 55 | if (organization.error |
| 56 | toast.error(organization |
| 57 | return |
| 58 | } |
| 59 | toast.success('Workspace created successfully |
| 60 | analyticsService.track('workspace_created |
| 61 | router.replace(`/ |
| 62 | } catch (error) |
| 63 | console.error(error |
| 64 | } finally { |
| 65 | setIsLoading(false) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return ( |
| 70 | <div className='relative w-full max-w-md |
| 71 | <div |
| 72 | aria-hidden |
| 73 | className='pointer-events-none absolute top-0 left-1/2 h-64 w-64 -translate-x-1/2 rounded-full bg-primary/10 blur-3xl' |
| 74 | /> |
| 75 | <div className='relative flex flex-col items-center gap-6 |
| 76 | <div className='flex flex-col items-center gap-3 text-center |
| 77 | <div className='flex flex-col gap-1 |
| 78 | <h1 className='font-semibold text-2xl tracking-tight |
| 79 | Welcome to Saturn |
| 80 | </h1> |
| 81 | <p className='text-muted-foreground text-sm |
| 82 | Let's set up your first workspace to get started. |
| 83 | </p> |
| 84 | </div> |
| 85 | </div> |
| 86 | |
| 87 | <Card className=' |
| 88 | <CardHeader> |
| 89 | <CardTitle>Create a workspace</CardTitle |
| 90 | <CardDescription> |
| 91 | A workspace is where you'll manage clients, projects, and |
| 92 | invoices. |
| 93 | </CardDescription> |
| 94 | </CardHeader> |
| 95 | <CardContent> |
| 96 | <form |
| 97 | className='space-y-6' |
| 98 | onSubmit={form.handleSubmit |
| 99 | > |
| 100 | <FieldGroup> |
| 101 | <Controller |
| 102 | control={form.control |
| 103 | name='name' |
| 104 | render={({ field |
| 105 | <Field |
| 106 | className='col-span-full gap-1' |
| 107 | data-invalid={fieldState.invalid |
| 108 | > |
| 109 | <FieldLabel>Workspace name</FieldLabel |
| 110 | <Input |
| 111 | {...field} |
| 112 | aria-invalid={fieldState.invalid |
| 113 | autoFocus |
| 114 | onChange={(e) |
| 115 | placeholder='Acme Inc.' |
| 116 | type='text' |
| 117 | /> |
| 118 | <FieldDescription> |
| 119 | {slugPreview ? ( |
| 120 | <span className='flex flex-wrap items-center gap-1 |
| 121 | Your workspace URL will be |
| 122 | <code className='rounded bg-muted px-1.5 py-0.5 font-mono text-foreground text-xs |
| 123 | {typeof window === |
| 124 | ? '' |
| 125 | : window.location. |
| 126 | /{slugPreview} |
| 127 | </code> |
| 128 | </span> |
| 129 | ) : ( |
| 130 | "Don't worry, you can change it later." |
| 131 | )} |
| 132 | </FieldDescription> |
| 133 | {fieldState.invalid && |
| 134 | <FieldError errors={ |
| 135 | )} |
| 136 | </Field> |
| 137 | )} |
| 138 | /> |
| 139 | </FieldGroup> |
| 140 | <Button className=' |
| 141 | Create workspace |
| 142 | </Button> |
| 143 | </form> |
| 144 | </CardContent> |
| 145 | </Card> |
| 146 | |
| 147 | <p className='text-muted-foreground text-xs |
| 148 | You can create more workspaces anytime from your account. |
| 149 | </p> |
| 150 | </div> |
| 151 | </div> |
| 152 | ) |
| 153 | } |