"use client"; import { createCourse } from "@/app/(protected)/teacher/actions"; // Server Action import { useRouter } from "next/navigation"; import { useState, FormEvent } from "react"; import Link from "next/link"; export default function TeacherNewCourseForm() { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); async function handleSubmit(event: FormEvent) { event.preventDefault(); setIsLoading(true); setError(null); const formData = new FormData(event.currentTarget); try { // 1. Call the Server Action const result = await createCourse(formData); if (result.success && result.data) { // 2. Redirect to the Course Editor // We will build the [slug]/edit page next router.push(`/teacher/courses/${result.data.slug}/edit`); } else { setError(result.error || "Algo salió mal al crear el curso."); setIsLoading(false); } } catch { setError("Error de conexión. Inténtalo de nuevo."); setIsLoading(false); } } return (
{/* Breadcrumb / Back Link */}
← Volver al Panel

Crear Nuevo Curso

Empieza con un título. Podrás agregar lecciones, cuestionarios y más detalles en la siguiente pantalla.

Esto generará la URL pública de tu curso.

{error && (
{error}
)}
Cancelar
); }