Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/semana/admin/palestra/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import PalestrasForms from '@/components/palestras/palestras_forms'

export default function PalestraPage() {
return <></>
return <PalestrasForms></PalestrasForms>
}
137 changes: 137 additions & 0 deletions src/components/palestras/palestras_forms.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'use client'

import React from 'react'
import { useState, MouseEventHandler } from 'react'
import PalestrasLabel from './palestras_label'

export default function PalestrasForms() {
const [numPalestrantes, setNumPalestrantes] = useState(1) // Por Default

/*
const [erroPalestrantes, setErroPalestrantes] = useState('')
async function cadastrar_palestra(formData: FormData) {
//const formData = new FormData(event.currentTarget)
const title = formData.get('title')
const day = formData.get('data')

const name: string[] = []
for (let i = 0; i < numPalestrantes; i++) {
const nome = formData.get(`name-${i}`)
if (nome) {
name.push(nome.toString())
}
}

const response = await fetch('/api/atividade/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: title,
name: name,
day: day,
}),
})

const res = await response.json()
}
*/

function handleNumPalestrantes() {
setNumPalestrantes(numPalestrantes + 1);
}

function removePalestrantes() {
setNumPalestrantes(numPalestrantes - 1);
}

return (
<>
<div className=" max-w-5xl mx-auto p-6 flex items-center justify-center min-h-screen py-10 overflow-y-auto bg-gray-100">
<form
className="border rounded-2xl shadow-sm bg-white p-10 w-full m-10"
//action={cadastrar_palestra}
>
<h2 className="text-xl font-semibold">Adicionar Palestra</h2>
<PalestrasLabel
value="title"
label="Título da Palestra"
type="name">
</PalestrasLabel>

{[...Array(numPalestrantes)].map((_, index) => (
<PalestrasLabel
value={`name-${index + 1}`}
label={`Nome do Palestrante ${index + 1}`}
type="name">
</PalestrasLabel>
))}

{numPalestrantes < 20 && (
<div className='flex items-center justify-center'>
<button
type="submit"
className="bg-rose-600
text-white
px-4
py-2
rounded
hover:bg-rose-700
transition
p-2
mt-1
w-full"
onClick={handleNumPalestrantes}
>Adicionar Mais um Palestrante</button>
</div>)}

{numPalestrantes > 1 && (
<div className='flex items-center justify-center'>
<button
type="submit"
className="bg-rose-600
text-white
px-4
py-2
rounded
hover:bg-rose-700
transition
p-2
mt-1
w-full"
onClick={removePalestrantes}
>
Remover Palestrante
</button>
</div>
)}

<div className="mb-5 w-full">
<label
htmlFor='data'
className="block grid p-2 mt-1 w-full">
Data e Horário da Palestra
</label>
<input
id="data"
name="data"
type="datetime-local"
className="border rounded p-2 mt-1 w-full"
required
min="2025-10-20T12:00"
max="2025-10-24T18:00"
>
</input>
</div>

<div className='flex items-center justify-center'>
<button
type="submit"
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition w-full">
Cadastrar Palestra
</button>
</div>
</form>
</div>
</>
)
}
24 changes: 24 additions & 0 deletions src/components/palestras/palestras_label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
interface PalestrasLabelProps {
value : string;
label : string;
type : string;
}

export default function PalestrasLabel({ value, label, type} : PalestrasLabelProps) {
return (
<div className="mb-5 w-full">
<label
htmlFor={value}
className="block grid p-2 mt-1 w-full">
{label}
</label>
<input
id={value}
name={value}
type={type}
className="border rounded p-2 mt-1 w-full"
required>
</input>
</div>
);
}
7 changes: 7 additions & 0 deletions src/lib/submit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const data = req.body
const id = await createItem(data)
res.status(200).json({ id })
}