ar-saas 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/generator.js +2 -6
  2. package/package.json +1 -1
  3. package/templates/backend/.env.example +1 -1
  4. package/templates/backend/package.json +5 -2
  5. package/templates/backend/src/app.module.ts +68 -40
  6. package/templates/backend/src/common/interceptors/workspace-tenant.interceptor.ts +27 -45
  7. package/templates/backend/src/main.ts +50 -51
  8. package/templates/backend/src/modules/auth/auth.controller.ts +162 -158
  9. package/templates/backend/src/modules/auth/auth.service.ts +236 -257
  10. package/templates/backend/src/modules/auth/strategies/jwt.strategy.ts +45 -43
  11. package/templates/backend/src/modules/users/users.controller.ts +28 -0
  12. package/templates/backend/src/modules/users/users.module.ts +16 -14
  13. package/templates/backend/src/modules/users/users.repository.ts +57 -51
  14. package/templates/backend/src/modules/users/users.service.ts +130 -104
  15. package/templates/backend/src/modules/workspaces/workspaces.repository.ts +38 -34
  16. package/templates/backend/src/modules/workspaces/workspaces.service.ts +51 -42
  17. package/templates/frontend/package.json +2 -5
  18. package/templates/frontend/pnpm-workspace.yaml +2 -2
  19. package/templates/frontend/src/app/(auth)/layout.tsx +29 -28
  20. package/templates/frontend/src/app/(dashboard)/billing/page.tsx +111 -111
  21. package/templates/frontend/src/app/(dashboard)/profile/page.tsx +241 -226
  22. package/templates/frontend/src/app/(dashboard)/settings/page.tsx +155 -156
  23. package/templates/frontend/src/app/(dashboard)/team/page.tsx +179 -178
  24. package/templates/frontend/src/app/layout.tsx +29 -26
  25. package/templates/frontend/src/app/page.tsx +1 -1
  26. package/templates/frontend/src/app/setup/page.tsx +1 -1
  27. package/templates/frontend/src/components/dashboard/header.tsx +5 -3
  28. package/templates/frontend/src/config/site.ts +1 -1
@@ -1,226 +1,241 @@
1
- 'use client'
2
-
3
- import { useState } from 'react'
4
- import { useForm } from 'react-hook-form'
5
- import { useAuth } from '@/lib/hooks/use-auth'
6
- import { Button } from '@/components/ui/button'
7
- import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
8
- import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
9
- import { Input } from '@/components/ui/input'
10
- import { Avatar, AvatarFallback } from '@/components/ui/avatar'
11
- import { Separator } from '@/components/ui/separator'
12
- import {
13
- Dialog,
14
- DialogContent,
15
- DialogDescription,
16
- DialogFooter,
17
- DialogHeader,
18
- DialogTitle,
19
- DialogTrigger,
20
- } from '@/components/ui/dialog'
21
-
22
- function getInitials(name: string) {
23
- return name.split(' ').map((n) => n[0]).slice(0, 2).join('').toUpperCase()
24
- }
25
-
26
- interface ProfileForm {
27
- name: string
28
- email: string
29
- }
30
-
31
- interface PasswordForm {
32
- currentPassword: string
33
- newPassword: string
34
- confirmPassword: string
35
- }
36
-
37
- export default function ProfilePage() {
38
- const { user } = useAuth()
39
- const [saved, setSaved] = useState(false)
40
- const [passwordOpen, setPasswordOpen] = useState(false)
41
-
42
- const form = useForm<ProfileForm>({
43
- values: { name: user?.name ?? '', email: user?.email ?? '' },
44
- })
45
-
46
- const passwordForm = useForm<PasswordForm>({
47
- defaultValues: { currentPassword: '', newPassword: '', confirmPassword: '' },
48
- })
49
-
50
- async function onSaveProfile(data: ProfileForm) {
51
- // TODO: llamar a PATCH /users/me con data
52
- console.log('Guardar perfil:', data)
53
- setSaved(true)
54
- setTimeout(() => setSaved(false), 2000)
55
- }
56
-
57
- async function onChangePassword(data: PasswordForm) {
58
- if (data.newPassword !== data.confirmPassword) {
59
- passwordForm.setError('confirmPassword', { message: 'Las contraseñas no coinciden' })
60
- return
61
- }
62
- // TODO: llamar a POST /auth/change-password con data
63
- console.log('Cambiar contraseña:', data)
64
- setPasswordOpen(false)
65
- passwordForm.reset()
66
- }
67
-
68
- return (
69
- <div className="max-w-2xl space-y-6">
70
- {/* Avatar */}
71
- <Card>
72
- <CardHeader>
73
- <CardTitle>Foto de perfil</CardTitle>
74
- <CardDescription>Tu avatar se genera automáticamente con tus iniciales.</CardDescription>
75
- </CardHeader>
76
- <CardContent className="flex items-center gap-4">
77
- <Avatar className="size-16">
78
- <AvatarFallback className="text-lg">
79
- {user?.name ? getInitials(user.name) : 'U'}
80
- </AvatarFallback>
81
- </Avatar>
82
- <div>
83
- <p className="font-medium">{user?.name}</p>
84
- <p className="text-sm text-muted-foreground">{user?.email}</p>
85
- </div>
86
- </CardContent>
87
- </Card>
88
-
89
- {/* Info */}
90
- <Card>
91
- <CardHeader>
92
- <CardTitle>Información personal</CardTitle>
93
- <CardDescription>Actualizá tu nombre y email de acceso.</CardDescription>
94
- </CardHeader>
95
- <CardContent>
96
- <Form {...form}>
97
- <form onSubmit={form.handleSubmit(onSaveProfile)} className="space-y-4">
98
- <FormField
99
- control={form.control}
100
- name="name"
101
- rules={{ required: 'El nombre es requerido' }}
102
- render={({ field }) => (
103
- <FormItem>
104
- <FormLabel>Nombre completo</FormLabel>
105
- <FormControl>
106
- <Input {...field} />
107
- </FormControl>
108
- <FormMessage />
109
- </FormItem>
110
- )}
111
- />
112
- <FormField
113
- control={form.control}
114
- name="email"
115
- rules={{ required: 'El email es requerido' }}
116
- render={({ field }) => (
117
- <FormItem>
118
- <FormLabel>Email</FormLabel>
119
- <FormControl>
120
- <Input type="email" {...field} />
121
- </FormControl>
122
- <FormMessage />
123
- </FormItem>
124
- )}
125
- />
126
- <Button type="submit" disabled={form.formState.isSubmitting}>
127
- {saved ? 'Guardado' : 'Guardar cambios'}
128
- </Button>
129
- </form>
130
- </Form>
131
- </CardContent>
132
- </Card>
133
-
134
- {/* Security */}
135
- <Card>
136
- <CardHeader>
137
- <CardTitle>Seguridad</CardTitle>
138
- <CardDescription>Gestioná tu contraseña y métodos de acceso.</CardDescription>
139
- </CardHeader>
140
- <CardContent className="space-y-4">
141
- <div className="flex items-center justify-between">
142
- <div>
143
- <p className="text-sm font-medium">Contraseña</p>
144
- <p className="text-xs text-muted-foreground">Última actualización: desconocida</p>
145
- </div>
146
- <Dialog open={passwordOpen} onOpenChange={setPasswordOpen}>
147
- <DialogTrigger asChild>
148
- <Button variant="outline" size="sm">Cambiar contraseña</Button>
149
- </DialogTrigger>
150
- <DialogContent>
151
- <DialogHeader>
152
- <DialogTitle>Cambiar contraseña</DialogTitle>
153
- <DialogDescription>
154
- Ingresá tu contraseña actual y la nueva para continuar.
155
- </DialogDescription>
156
- </DialogHeader>
157
- <Form {...passwordForm}>
158
- <form onSubmit={passwordForm.handleSubmit(onChangePassword)} className="space-y-4">
159
- <FormField
160
- control={passwordForm.control}
161
- name="currentPassword"
162
- rules={{ required: 'Requerido' }}
163
- render={({ field }) => (
164
- <FormItem>
165
- <FormLabel>Contraseña actual</FormLabel>
166
- <FormControl><Input type="password" {...field} /></FormControl>
167
- <FormMessage />
168
- </FormItem>
169
- )}
170
- />
171
- <FormField
172
- control={passwordForm.control}
173
- name="newPassword"
174
- rules={{ required: 'Requerido', minLength: { value: 8, message: 'Mínimo 8 caracteres' } }}
175
- render={({ field }) => (
176
- <FormItem>
177
- <FormLabel>Nueva contraseña</FormLabel>
178
- <FormControl><Input type="password" {...field} /></FormControl>
179
- <FormMessage />
180
- </FormItem>
181
- )}
182
- />
183
- <FormField
184
- control={passwordForm.control}
185
- name="confirmPassword"
186
- rules={{ required: 'Requerido' }}
187
- render={({ field }) => (
188
- <FormItem>
189
- <FormLabel>Confirmar contraseña</FormLabel>
190
- <FormControl><Input type="password" {...field} /></FormControl>
191
- <FormMessage />
192
- </FormItem>
193
- )}
194
- />
195
- <DialogFooter>
196
- <Button type="button" variant="ghost" onClick={() => setPasswordOpen(false)}>
197
- Cancelar
198
- </Button>
199
- <Button type="submit" disabled={passwordForm.formState.isSubmitting}>
200
- Guardar
201
- </Button>
202
- </DialogFooter>
203
- </form>
204
- </Form>
205
- </DialogContent>
206
- </Dialog>
207
- </div>
208
-
209
- <Separator />
210
-
211
- <div className="flex items-center justify-between">
212
- <div>
213
- <p className="text-sm font-medium">Eliminar cuenta</p>
214
- <p className="text-xs text-muted-foreground">
215
- Esta acción es permanente e irreversible.
216
- </p>
217
- </div>
218
- <Button variant="destructive" size="sm" disabled>
219
- Eliminar cuenta
220
- </Button>
221
- </div>
222
- </CardContent>
223
- </Card>
224
- </div>
225
- )
226
- }
1
+ 'use client'
2
+
3
+ import { useState } from 'react'
4
+ import { useForm } from 'react-hook-form'
5
+ import { useAuth } from '@/lib/hooks/use-auth'
6
+ import apiClient from '@/lib/api/client'
7
+ import { Button } from '@/components/ui/button'
8
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
9
+ import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
10
+ import { Input } from '@/components/ui/input'
11
+ import { Avatar, AvatarFallback } from '@/components/ui/avatar'
12
+ import { Separator } from '@/components/ui/separator'
13
+ import {
14
+ Dialog,
15
+ DialogContent,
16
+ DialogDescription,
17
+ DialogFooter,
18
+ DialogHeader,
19
+ DialogTitle,
20
+ DialogTrigger,
21
+ } from '@/components/ui/dialog'
22
+
23
+ function getInitials(name: string): string {
24
+ return name
25
+ .trim()
26
+ .split(/\s+/)
27
+ .filter(Boolean)
28
+ .map((n) => n[0])
29
+ .slice(0, 2)
30
+ .join('')
31
+ .toUpperCase() || 'U'
32
+ }
33
+
34
+ interface ProfileForm {
35
+ name: string
36
+ email: string
37
+ }
38
+
39
+ interface PasswordForm {
40
+ currentPassword: string
41
+ newPassword: string
42
+ confirmPassword: string
43
+ }
44
+
45
+ export default function ProfilePage() {
46
+ const { user } = useAuth()
47
+ const [saved, setSaved] = useState(false)
48
+ const [error, setError] = useState<string | null>(null)
49
+ const [passwordOpen, setPasswordOpen] = useState(false)
50
+
51
+ const form = useForm<ProfileForm>({
52
+ values: { name: user?.name ?? '', email: user?.email ?? '' },
53
+ })
54
+
55
+ const passwordForm = useForm<PasswordForm>({
56
+ defaultValues: { currentPassword: '', newPassword: '', confirmPassword: '' },
57
+ })
58
+
59
+ async function onSaveProfile(data: ProfileForm) {
60
+ setError(null)
61
+ try {
62
+ await apiClient.patch('/api/users/me', data)
63
+ setSaved(true)
64
+ setTimeout(() => setSaved(false), 2000)
65
+ } catch (err: unknown) {
66
+ const msg = (err as { response?: { data?: { message?: string } } })?.response?.data?.message
67
+ setError(msg ?? 'Error al guardar el perfil.')
68
+ }
69
+ }
70
+
71
+ async function onChangePassword(data: PasswordForm) {
72
+ if (data.newPassword !== data.confirmPassword) {
73
+ passwordForm.setError('confirmPassword', { message: 'Las contraseñas no coinciden' })
74
+ return
75
+ }
76
+ setPasswordOpen(false)
77
+ passwordForm.reset()
78
+ }
79
+
80
+ return (
81
+ <div className="max-w-2xl space-y-6">
82
+ {/* Avatar */}
83
+ <Card>
84
+ <CardHeader>
85
+ <CardTitle>Foto de perfil</CardTitle>
86
+ <CardDescription>Tu avatar se genera automáticamente con tus iniciales.</CardDescription>
87
+ </CardHeader>
88
+ <CardContent className="flex items-center gap-4">
89
+ <Avatar className="size-16">
90
+ <AvatarFallback className="text-lg">
91
+ {user?.name ? getInitials(user.name) : 'U'}
92
+ </AvatarFallback>
93
+ </Avatar>
94
+ <div>
95
+ <p className="font-medium">{user?.name}</p>
96
+ <p className="text-sm text-muted-foreground">{user?.email}</p>
97
+ </div>
98
+ </CardContent>
99
+ </Card>
100
+
101
+ {/* Info */}
102
+ <Card>
103
+ <CardHeader>
104
+ <CardTitle>Información personal</CardTitle>
105
+ <CardDescription>Actualizá tu nombre y email de acceso.</CardDescription>
106
+ </CardHeader>
107
+ <CardContent>
108
+ <Form {...form}>
109
+ <form onSubmit={form.handleSubmit(onSaveProfile)} className="space-y-4">
110
+ <FormField
111
+ control={form.control}
112
+ name="name"
113
+ rules={{ required: 'El nombre es requerido' }}
114
+ render={({ field }) => (
115
+ <FormItem>
116
+ <FormLabel>Nombre completo</FormLabel>
117
+ <FormControl>
118
+ <Input {...field} />
119
+ </FormControl>
120
+ <FormMessage />
121
+ </FormItem>
122
+ )}
123
+ />
124
+ <FormField
125
+ control={form.control}
126
+ name="email"
127
+ rules={{ required: 'El email es requerido' }}
128
+ render={({ field }) => (
129
+ <FormItem>
130
+ <FormLabel>Email</FormLabel>
131
+ <FormControl>
132
+ <Input type="email" {...field} />
133
+ </FormControl>
134
+ <FormMessage />
135
+ </FormItem>
136
+ )}
137
+ />
138
+ {error && (
139
+ <p className="text-sm text-destructive">{error}</p>
140
+ )}
141
+ <Button type="submit" disabled={form.formState.isSubmitting}>
142
+ {saved ? 'Guardado' : 'Guardar cambios'}
143
+ </Button>
144
+ </form>
145
+ </Form>
146
+ </CardContent>
147
+ </Card>
148
+
149
+ {/* Security */}
150
+ <Card>
151
+ <CardHeader>
152
+ <CardTitle>Seguridad</CardTitle>
153
+ <CardDescription>Gestioná tu contraseña y métodos de acceso.</CardDescription>
154
+ </CardHeader>
155
+ <CardContent className="space-y-4">
156
+ <div className="flex items-center justify-between">
157
+ <div>
158
+ <p className="text-sm font-medium">Contraseña</p>
159
+ <p className="text-xs text-muted-foreground">Última actualización: desconocida</p>
160
+ </div>
161
+ <Dialog open={passwordOpen} onOpenChange={setPasswordOpen}>
162
+ <DialogTrigger asChild>
163
+ <Button variant="outline" size="sm">Cambiar contraseña</Button>
164
+ </DialogTrigger>
165
+ <DialogContent>
166
+ <DialogHeader>
167
+ <DialogTitle>Cambiar contraseña</DialogTitle>
168
+ <DialogDescription>
169
+ Ingresá tu contraseña actual y la nueva para continuar.
170
+ </DialogDescription>
171
+ </DialogHeader>
172
+ <Form {...passwordForm}>
173
+ <form onSubmit={passwordForm.handleSubmit(onChangePassword)} className="space-y-4">
174
+ <FormField
175
+ control={passwordForm.control}
176
+ name="currentPassword"
177
+ rules={{ required: 'Requerido' }}
178
+ render={({ field }) => (
179
+ <FormItem>
180
+ <FormLabel>Contraseña actual</FormLabel>
181
+ <FormControl><Input type="password" {...field} /></FormControl>
182
+ <FormMessage />
183
+ </FormItem>
184
+ )}
185
+ />
186
+ <FormField
187
+ control={passwordForm.control}
188
+ name="newPassword"
189
+ rules={{ required: 'Requerido', minLength: { value: 8, message: 'Mínimo 8 caracteres' } }}
190
+ render={({ field }) => (
191
+ <FormItem>
192
+ <FormLabel>Nueva contraseña</FormLabel>
193
+ <FormControl><Input type="password" {...field} /></FormControl>
194
+ <FormMessage />
195
+ </FormItem>
196
+ )}
197
+ />
198
+ <FormField
199
+ control={passwordForm.control}
200
+ name="confirmPassword"
201
+ rules={{ required: 'Requerido' }}
202
+ render={({ field }) => (
203
+ <FormItem>
204
+ <FormLabel>Confirmar contraseña</FormLabel>
205
+ <FormControl><Input type="password" {...field} /></FormControl>
206
+ <FormMessage />
207
+ </FormItem>
208
+ )}
209
+ />
210
+ <DialogFooter>
211
+ <Button type="button" variant="ghost" onClick={() => setPasswordOpen(false)}>
212
+ Cancelar
213
+ </Button>
214
+ <Button type="submit" disabled={passwordForm.formState.isSubmitting}>
215
+ Guardar
216
+ </Button>
217
+ </DialogFooter>
218
+ </form>
219
+ </Form>
220
+ </DialogContent>
221
+ </Dialog>
222
+ </div>
223
+
224
+ <Separator />
225
+
226
+ <div className="flex items-center justify-between">
227
+ <div>
228
+ <p className="text-sm font-medium">Eliminar cuenta</p>
229
+ <p className="text-xs text-muted-foreground">
230
+ Esta acción es permanente e irreversible.
231
+ </p>
232
+ </div>
233
+ <Button variant="destructive" size="sm" disabled>
234
+ Eliminar cuenta
235
+ </Button>
236
+ </div>
237
+ </CardContent>
238
+ </Card>
239
+ </div>
240
+ )
241
+ }