ar-saas 0.3.3 → 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.
- package/dist/generator.js +2 -6
- package/package.json +1 -1
- package/templates/backend/.env.example +1 -1
- package/templates/backend/package.json +5 -2
- package/templates/backend/src/app.module.ts +68 -40
- package/templates/backend/src/common/interceptors/workspace-tenant.interceptor.ts +27 -45
- package/templates/backend/src/main.ts +50 -51
- package/templates/backend/src/modules/auth/auth.controller.ts +162 -158
- package/templates/backend/src/modules/auth/auth.service.ts +236 -257
- package/templates/backend/src/modules/auth/strategies/jwt.strategy.ts +45 -43
- package/templates/backend/src/modules/users/users.controller.ts +28 -0
- package/templates/backend/src/modules/users/users.module.ts +16 -14
- package/templates/backend/src/modules/users/users.repository.ts +57 -51
- package/templates/backend/src/modules/users/users.service.ts +130 -104
- package/templates/backend/src/modules/workspaces/workspaces.repository.ts +38 -34
- package/templates/backend/src/modules/workspaces/workspaces.service.ts +51 -42
- package/templates/frontend/package.json +2 -5
- package/templates/frontend/pnpm-workspace.yaml +2 -2
- package/templates/frontend/src/app/(auth)/layout.tsx +29 -28
- package/templates/frontend/src/app/(dashboard)/billing/page.tsx +111 -111
- package/templates/frontend/src/app/(dashboard)/profile/page.tsx +241 -226
- package/templates/frontend/src/app/(dashboard)/settings/page.tsx +155 -156
- package/templates/frontend/src/app/(dashboard)/team/page.tsx +179 -178
- package/templates/frontend/src/app/layout.tsx +29 -26
- package/templates/frontend/src/app/page.tsx +1 -1
- package/templates/frontend/src/app/setup/page.tsx +1 -1
- package/templates/frontend/src/components/dashboard/header.tsx +5 -3
- 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
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
}
|