42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { Link, useNavigate } from '@tanstack/react-router'
|
|
import type { CreateFirstGroup } from '@gruperly/shared'
|
|
import { ChevronLeft } from 'lucide-react'
|
|
import { createGroup } from '../../lib/api'
|
|
import { GroupForm } from './GroupForm'
|
|
|
|
export function CreateGroupView() {
|
|
const navigate = useNavigate()
|
|
const queryClient = useQueryClient()
|
|
|
|
const create = useMutation({
|
|
mutationFn: (values: CreateFirstGroup) => createGroup(values),
|
|
onSuccess: (result) => {
|
|
void queryClient.invalidateQueries({ queryKey: ['groups'] })
|
|
void navigate({ to: '/groups/$groupId', params: { groupId: result.group.id } })
|
|
},
|
|
})
|
|
|
|
return (
|
|
<section className="mx-auto w-full max-w-md">
|
|
<Link
|
|
to="/groups"
|
|
className="mb-6 hidden items-center gap-1 text-sm font-medium text-foreground/70 transition-colors hover:text-primary lg:inline-flex"
|
|
>
|
|
<ChevronLeft className="size-4" />
|
|
Grupos
|
|
</Link>
|
|
|
|
<GroupForm
|
|
heading="Nuevo grupo"
|
|
description="Definí los datos de la clase que vas a cobrar. Después siempre podés editarlos."
|
|
submitLabel="Crear grupo"
|
|
isSubmitting={create.isPending}
|
|
errorMessage={
|
|
create.isError ? 'No pudimos crear el grupo. Revisá los datos e intentá de nuevo.' : null
|
|
}
|
|
onSubmit={(values) => create.mutate(values)}
|
|
/>
|
|
</section>
|
|
)
|
|
} |