anexado guardar en minio y cambios generales en la interfaz de osp
This commit is contained in:
@@ -162,14 +162,16 @@ export function CreateTrainingForm({
|
||||
});
|
||||
|
||||
// 1. Extrae errors de formState
|
||||
const { formState: { errors } } = form;
|
||||
const {
|
||||
formState: { errors },
|
||||
} = form;
|
||||
|
||||
// 2. Crea un efecto para monitorearlos
|
||||
useEffect(() => {
|
||||
if (Object.keys(errors).length > 0) {
|
||||
console.log("Campos con errores:", errors);
|
||||
}
|
||||
}, [errors]);
|
||||
// 2. Crea un efecto para monitorearlos
|
||||
useEffect(() => {
|
||||
if (Object.keys(errors).length > 0) {
|
||||
console.log('Campos con errores:', errors);
|
||||
}
|
||||
}, [errors]);
|
||||
|
||||
// Cascading Select Logic
|
||||
const ecoSector = useWatch({ control: form.control, name: 'ecoSector' });
|
||||
@@ -219,13 +221,12 @@ useEffect(() => {
|
||||
{ id: 0, name: 'Sin estados' },
|
||||
];
|
||||
|
||||
const coorMunicipalityOptions =
|
||||
dataCoorMunicipality?.data?.length
|
||||
? dataCoorMunicipality.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Municipios' }];
|
||||
const coorMunicipalityOptions = dataCoorMunicipality?.data?.length
|
||||
? dataCoorMunicipality.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Municipios' }];
|
||||
|
||||
const coorParishOptions =
|
||||
Array.isArray(dataCoorParish?.data) && dataCoorParish?.data?.length
|
||||
Array.isArray(dataCoorParish?.data) && dataCoorParish?.data?.length
|
||||
? dataCoorParish.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Parroquias' }];
|
||||
|
||||
@@ -264,8 +265,6 @@ useEffect(() => {
|
||||
}, [defaultValues]);
|
||||
|
||||
const onSubmit = async (formData: TrainingSchema) => {
|
||||
|
||||
|
||||
const data = new FormData();
|
||||
|
||||
// 1. Definimos las claves que NO queremos enviar en el bucle general
|
||||
@@ -279,12 +278,13 @@ useEffect(() => {
|
||||
];
|
||||
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
// 2. Condición actualizada: Si la key está en la lista de excluidos, la saltamos
|
||||
// 2. Condición actualizada: Si la key está en la lista de excluidos, o es un valor vacío (null/undefined), lo saltamos.
|
||||
// Permitimos cadenas vacías ('') para indicar al backend que se debe limpiar el campo (ej: borrar foto).
|
||||
if (excludedKeys.includes(key) || value === undefined || value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Lógica de conversión (Igual que tenías)
|
||||
// 3. Lógica de conversión
|
||||
if (
|
||||
Array.isArray(value) ||
|
||||
(typeof value === 'object' && !(value instanceof Date))
|
||||
@@ -393,10 +393,13 @@ useEffect(() => {
|
||||
<FormLabel>Teléfono</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
{...field}
|
||||
placeholder="Ej. 04121234567"
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '');
|
||||
field.onChange(val.slice(0, 11));
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
@@ -514,7 +517,7 @@ useEffect(() => {
|
||||
</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
@@ -550,7 +553,7 @@ useEffect(() => {
|
||||
form.setValue('mainProductiveActivity', '');
|
||||
form.setValue('productiveActivity', '');
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
@@ -585,7 +588,7 @@ useEffect(() => {
|
||||
form.setValue('mainProductiveActivity', '');
|
||||
form.setValue('productiveActivity', '');
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
disabled={!ecoSector}
|
||||
>
|
||||
<FormControl>
|
||||
@@ -620,7 +623,7 @@ useEffect(() => {
|
||||
form.setValue('mainProductiveActivity', '');
|
||||
form.setValue('productiveActivity', '');
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
disabled={!productiveSector}
|
||||
>
|
||||
<FormControl>
|
||||
@@ -654,7 +657,7 @@ useEffect(() => {
|
||||
field.onChange(val);
|
||||
form.setValue('productiveActivity', '');
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
disabled={!centralProductiveActivity}
|
||||
>
|
||||
<FormControl>
|
||||
@@ -685,7 +688,7 @@ useEffect(() => {
|
||||
</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
disabled={!mainProductiveActivity}
|
||||
>
|
||||
<FormControl>
|
||||
@@ -715,7 +718,11 @@ useEffect(() => {
|
||||
RIF de la organización (opcional)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="J-12345678-9" />
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="J-12345678-9"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -731,7 +738,7 @@ useEffect(() => {
|
||||
Nombre de la organización (opcional)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -747,7 +754,11 @@ useEffect(() => {
|
||||
Año de constitución
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -764,7 +775,7 @@ useEffect(() => {
|
||||
</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
@@ -793,7 +804,11 @@ useEffect(() => {
|
||||
infraestrutura (MT2)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="e.g. 500" />
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="e.g. 500"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -837,7 +852,7 @@ useEffect(() => {
|
||||
</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
@@ -846,9 +861,9 @@ useEffect(() => {
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="CASA">CASA</SelectItem>
|
||||
<SelectItem value="GALPON">GALPON</SelectItem>
|
||||
<SelectItem value="GALPÓN">GALPÓN</SelectItem>
|
||||
<SelectItem value="LOCAL">LOCAL</SelectItem>
|
||||
<SelectItem value="ALMACEN">ALMACEN</SelectItem>
|
||||
<SelectItem value="ALMACÉN">ALMACÉN</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
@@ -893,7 +908,7 @@ useEffect(() => {
|
||||
Razones de paralización (opcional)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea {...field} />
|
||||
<Textarea {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -952,6 +967,7 @@ useEffect(() => {
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="https://maps.google.com/..."
|
||||
/>
|
||||
</FormControl>
|
||||
@@ -973,7 +989,7 @@ useEffect(() => {
|
||||
Nombre de la Comuna
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -989,7 +1005,7 @@ useEffect(() => {
|
||||
Código SITUR de la Comuna
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1005,7 +1021,7 @@ useEffect(() => {
|
||||
Rif de la Comuna
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1021,14 +1037,13 @@ useEffect(() => {
|
||||
Nombre del Vocero o Vocera
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="communeSpokespersonPhone"
|
||||
@@ -1038,7 +1053,15 @@ useEffect(() => {
|
||||
Número de Teléfono del Vocero
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="Ej. 04121234567"
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '');
|
||||
field.onChange(val.slice(0, 11));
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1054,7 +1077,11 @@ useEffect(() => {
|
||||
Correo Electrónico de la Comuna (Opcional)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="email" {...field} />
|
||||
<Input
|
||||
type="email"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1092,7 +1119,7 @@ useEffect(() => {
|
||||
Código SITUR del Consejo Comunal
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1108,7 +1135,7 @@ useEffect(() => {
|
||||
Rif del Consejo Comunal
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1124,13 +1151,13 @@ useEffect(() => {
|
||||
Nombre del Vocero o Vocera
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="communalCouncilSpokespersonPhone"
|
||||
@@ -1140,7 +1167,15 @@ useEffect(() => {
|
||||
Número de Teléfono del Vocero
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="Ej. 04121234567"
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '');
|
||||
field.onChange(val.slice(0, 11));
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1156,7 +1191,11 @@ useEffect(() => {
|
||||
Correo Electrónico del Consejo Comunal (Opcional)
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="email" {...field} />
|
||||
<Input
|
||||
type="email"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1204,9 +1243,9 @@ useEffect(() => {
|
||||
name="ospResponsibleRif"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>RIF</FormLabel>
|
||||
<FormLabel>RIF (Opcional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1218,10 +1257,10 @@ useEffect(() => {
|
||||
name="civilState"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Estado Civil</FormLabel>
|
||||
<FormLabel>Estado Civil (Opcional)</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
defaultValue={field.value ?? undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
@@ -1248,7 +1287,15 @@ useEffect(() => {
|
||||
<FormItem>
|
||||
<FormLabel>Teléfono</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
placeholder="Ej. 04121234567"
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '');
|
||||
field.onChange(val.slice(0, 11));
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1260,9 +1307,13 @@ useEffect(() => {
|
||||
name="ospResponsibleEmail"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Correo Electrónico</FormLabel>
|
||||
<FormLabel>Correo Electrónico (Opcional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="email" {...field} />
|
||||
<Input
|
||||
type="email"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1274,9 +1325,13 @@ useEffect(() => {
|
||||
name="familyBurden"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Carga Familiar</FormLabel>
|
||||
<FormLabel>Carga Familiar (Opcional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1288,9 +1343,13 @@ useEffect(() => {
|
||||
name="numberOfChildren"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Número de Hijos</FormLabel>
|
||||
<FormLabel>Número de Hijos (Opcional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1312,7 +1371,7 @@ useEffect(() => {
|
||||
<FormItem>
|
||||
<FormLabel>Observaciones Generales (Opcional)</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea {...field} />
|
||||
<Textarea {...field} value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -1344,7 +1403,7 @@ useEffect(() => {
|
||||
className="relative aspect-square rounded-md overflow-hidden bg-muted group"
|
||||
>
|
||||
<img
|
||||
src={`${process.env.NEXT_PUBLIC_API_URL}${photoUrl}`}
|
||||
src={`${photoUrl}`}
|
||||
alt={`Existing ${idx + 1}`}
|
||||
className="object-cover w-full h-full"
|
||||
/>
|
||||
@@ -1397,7 +1456,9 @@ useEffect(() => {
|
||||
newFiles.length + selectedFiles.length + existingCount >
|
||||
3
|
||||
) {
|
||||
toast.error(`Máximo 3 imágenes en total. Ya tienes ${existingCount} subidas y ${selectedFiles.length} seleccionadas para subir.`)
|
||||
toast.error(
|
||||
`Máximo 3 imágenes en total. Ya tienes ${existingCount} subidas y ${selectedFiles.length} seleccionadas para subir.`,
|
||||
);
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user