161 lines
4.6 KiB
TypeScript
161 lines
4.6 KiB
TypeScript
import type { Route } from './+types'
|
|
|
|
import { useForm } from 'react-hook-form'
|
|
import { Link } from 'react-router'
|
|
|
|
import { Container } from '@/components/container'
|
|
|
|
import type { User } from '@repo/auth/auth'
|
|
import { userContext } from '@repo/auth/context'
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbLink,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
BreadcrumbSeparator
|
|
} from '@repo/ui/components/ui/breadcrumb'
|
|
import { Button } from '@repo/ui/components/ui/button'
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle
|
|
} from '@repo/ui/components/ui/card'
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage
|
|
} from '@repo/ui/components/ui/form'
|
|
import { Input } from '@repo/ui/components/ui/input'
|
|
import { Spinner } from '@repo/ui/components/ui/spinner'
|
|
import { request as req } from '@repo/util/request'
|
|
|
|
export function meta({}: Route.MetaArgs) {
|
|
return [{ title: 'Minha conta' }]
|
|
}
|
|
|
|
export async function loader({ context, request }: Route.ActionArgs) {
|
|
const user = context.get(userContext) as User
|
|
const r = await req({
|
|
url: `/users/${user.sub}`,
|
|
request,
|
|
context
|
|
})
|
|
return { user: await r.json() }
|
|
}
|
|
|
|
export default function Route({ loaderData: { user } }) {
|
|
const form = useForm({ defaultValues: user })
|
|
const { handleSubmit, control, formState } = form
|
|
|
|
const onSubmit = async (data) => {
|
|
console.log(data)
|
|
}
|
|
|
|
return (
|
|
<Container className="space-y-2.5">
|
|
<Breadcrumb>
|
|
<BreadcrumbList>
|
|
<BreadcrumbItem>
|
|
<BreadcrumbLink asChild>
|
|
<Link to="..">Meus cursos</Link>
|
|
</BreadcrumbLink>
|
|
</BreadcrumbItem>
|
|
<BreadcrumbSeparator />
|
|
<BreadcrumbItem>
|
|
<BreadcrumbPage>Minha conta</BreadcrumbPage>
|
|
</BreadcrumbItem>
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
|
|
<div className="lg:max-w-2xl mx-auto space-y-2.5">
|
|
<Form {...form}>
|
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-2xl">Minha conta</CardTitle>
|
|
<CardDescription>
|
|
Gerenciar as configurações da sua conta.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
|
|
<CardContent className="space-y-4">
|
|
<FormField
|
|
control={control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Nome</FormLabel>
|
|
<FormControl>
|
|
<Input {...field} />
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={control}
|
|
name="email"
|
|
disabled={true}
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Email</FormLabel>
|
|
<FormControl>
|
|
<Input {...field} />
|
|
</FormControl>
|
|
<FormLabel className="text-sm font-normal text-muted-foreground">
|
|
<span>
|
|
Para gerenciar os emails ou trocar o email principal,
|
|
use as{' '}
|
|
<Link
|
|
to="emails"
|
|
className="text-blue-400 underline hover:no-underline"
|
|
>
|
|
configurações de emails
|
|
</Link>
|
|
</span>
|
|
</FormLabel>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={control}
|
|
name="cpf"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>CPF</FormLabel>
|
|
<FormControl>
|
|
<Input {...field} />
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<div className="flex justify-end">
|
|
<Button
|
|
type="submit"
|
|
className="cursor-pointer"
|
|
disabled={formState.isSubmitting}
|
|
>
|
|
{formState.isSubmitting && <Spinner />}
|
|
Editar
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Form>
|
|
</div>
|
|
</Container>
|
|
)
|
|
}
|