first commit

This commit is contained in:
gestions-UO
2026-05-11 20:50:44 +02:00
parent f7ba09d405
commit 838bec205e
36 changed files with 2514 additions and 99 deletions

30
hooks/useForm.ts Normal file
View File

@@ -0,0 +1,30 @@
"use client";
import { useState } from 'react';
import { supabase } from '@/lib/supabase/client';
export const useFormSubmit = (tableName: string) => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState<string | null>(null);
const submit = async (data: any) => {
setIsSubmitting(true);
setError(null);
try {
const { error: sbError } = await supabase
.from(tableName)
.insert([data]);
if (sbError) throw sbError;
setSuccess(true);
} catch (err: any) {
setError(err.message || 'Error al enviar los datos');
} finally {
setIsSubmitting(false);
}
};
return { submit, isSubmitting, success, error };
};