From cea63229765fec2d9184184392bb83e021218035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Rafael=20Siqueira?= Date: Tue, 9 Dec 2025 17:19:17 -0300 Subject: [PATCH] update calebndar --- .../routes/_.$orgid.enrollments.add/route.tsx | 327 ++++++++++-------- 1 file changed, 187 insertions(+), 140 deletions(-) diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx index f34175d..3157767 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/route.tsx @@ -1,6 +1,6 @@ import type { Route } from './+types/route' -import { ptBR } from 'react-day-picker/locale' +import { useToggle } from 'ahooks' import { CalendarIcon, SearchIcon, @@ -10,7 +10,10 @@ import { PlusIcon } from 'lucide-react' import { Link } from 'react-router' -import { useFieldArray, useForm } from 'react-hook-form' +import { Controller, useFieldArray, useForm } from 'react-hook-form' +import { Fragment, useState } from 'react' +import { format } from 'date-fns' +import { ptBR } from 'react-day-picker/locale' import { Breadcrumb, @@ -20,11 +23,6 @@ import { BreadcrumbPage, BreadcrumbSeparator } from '@repo/ui/components/ui/breadcrumb' -import { - Tooltip, - TooltipContent, - TooltipTrigger -} from '@repo/ui/components/ui/tooltip' import { InputGroup, InputGroupAddon, @@ -49,6 +47,7 @@ import { } from '@repo/ui/components/ui/popover' import { Label } from '@repo/ui/components/ui/label' import { Calendar } from '@repo/ui/components/ui/calendar' +import { data } from 'react-router' export function meta({}: Route.MetaArgs) { return [{ title: 'Adicionar matrícula' }] @@ -56,12 +55,23 @@ export function meta({}: Route.MetaArgs) { export default function Route({}: Route.ComponentProps) { const form = useForm({ defaultValues: { enrollments: [{}] } }) - const { formState, control } = form - const { fields, append, remove } = useFieldArray({ + const { formState, control, handleSubmit, getValues } = form + const { fields, insert, remove, append } = useFieldArray({ control, name: 'enrollments' }) + const onSubmit = async (data) => { + console.log(data) + } + + const duplicateRow = (index: number, times: number = 1) => { + const values = getValues(`enrollments.${index}`) + Array.from({ length: times }, (_, i) => { + insert(index + 1 + i, values) + }) + } + return (
@@ -78,7 +88,10 @@ export default function Route({}: Route.ComponentProps) { -
+
Adicionar matrícula @@ -88,137 +101,91 @@ export default function Route({}: Route.ComponentProps) { - - - - - - - - - - - {fields.map((field, index) => { - return ( - - - - - - - ) - })} - -
- Colaborador - - Curso - - Matricular em -
- - - - - - - - - - - - - - - - - - - - - -

Duplicar linha

-
-
+
+ {/* Header */} + <> +
+ Colaborador +
+
+ Curso +
+
+ Matriculado em +
+
+ - - - - - - - - -

Duplicar várias vezes

-
-
+ {/* Rows */} + <> + {fields.map((field, index) => ( + + {index >= 1 &&
} - -
-

- Duplicar várias vezes -

-

- Duplique o curso desta linha na quantidade - desejada para agilizar o preenchimento. -

+ + + + + + -
-
- - -
-
+ + + + + + -
- -
-
-
-
+ ( + + )} + /> - -
-
- + {/* Action */} +
+ + + + + +
+ + ))} +
+ + +
+
) } -function ScheduledForInput() { +function ScheduledForInput({ value, onChange }) { + const today = new Date() + const [open, { toggle, set }] = useToggle() + const [selected, setDate] = useState(value) + const displayValue = !selected + ? 'Imediatamente' + : format(selected, 'dd/MM/yyyy') + return ( - + - + @@ -250,11 +224,84 @@ function ScheduledForInput() { { + setDate(date) + onChange?.(date) + set(false) + }} + disabled={{ before: today }} + startMonth={new Date(today.getFullYear(), 0)} + endMonth={new Date(today.getFullYear() + 3, 11)} captionLayout="dropdown" - // startMonth={new Date()} locale={ptBR} /> ) } + +function DuplicateRowMultipleTimes({ + index, + duplicateRow +}: { + index: number + duplicateRow: (index: number, times: number) => void +}) { + const [open, { toggle, set }] = useToggle() + + return ( + + + + + + +
{ + e.stopPropagation() + e.preventDefault() + const formData = new FormData(e.currentTarget) + const times = parseInt(formData.get('quantity') as string) + duplicateRow(index, times) + set(false) + }} + > +
+

Duplicar várias vezes

+

+ Duplique o curso desta linha na quantidade desejada para agilizar + o preenchimento. +

+ +
+
+ + +
+
+ +
+ +
+
+
+
+
+ ) +}