Cambios en el formulario: nuevos inputs, esquemas actualizados, correciones para el modo telefono, eliminada redundancia de condicionales en los defaulvalus y values de los inputs

This commit is contained in:
2026-04-08 20:11:22 -04:00
parent 7f5a895c12
commit 2da200a491
4 changed files with 166 additions and 219 deletions

View File

@@ -158,6 +158,7 @@ export const trainingSurveys = t.pgTable(
updatedBy: t updatedBy: t
.integer('updated_by') .integer('updated_by')
.references(() => users.id, { onDelete: 'cascade' }), .references(() => users.id, { onDelete: 'cascade' }),
surveyStatus: t.text('survey_status').notNull().default('PUBLICADO'),
...timestamps, ...timestamps,
}, },
(trainingSurveys) => ({ (trainingSurveys) => ({

View File

@@ -7,6 +7,7 @@ import {
IsEmail, IsEmail,
IsInt, IsInt,
IsOptional, IsOptional,
isString,
IsString, IsString,
ValidateIf, ValidateIf,
} from 'class-validator'; } from 'class-validator';
@@ -332,4 +333,8 @@ export class CreateTrainingDto {
@IsString() @IsString()
@IsOptional() @IsOptional()
photo3?: string; photo3?: string;
@ApiProperty()
@IsString()
surveyStatus: string
} }

View File

@@ -151,7 +151,7 @@ export function CreateTrainingForm({
generalObservations: defaultValues?.generalObservations || '', generalObservations: defaultValues?.generalObservations || '',
ospResponsibleEmail: defaultValues?.ospResponsibleEmail || '', ospResponsibleEmail: defaultValues?.ospResponsibleEmail || '',
paralysisReason: defaultValues?.paralysisReason || '', paralysisReason: defaultValues?.paralysisReason || '',
infrastructureMt2: defaultValues?.infrastructureMt2 || undefined, infrastructureMt2: defaultValues?.infrastructureMt2 || '',
hasTransport: defaultValues?.hasTransport || false, hasTransport: defaultValues?.hasTransport || false,
structureType: defaultValues?.structureType || undefined, structureType: defaultValues?.structureType || undefined,
isOpenSpace: defaultValues?.isOpenSpace || false, isOpenSpace: defaultValues?.isOpenSpace || false,
@@ -172,6 +172,7 @@ export function CreateTrainingForm({
womenCount: defaultValues?.womenCount || 0, womenCount: defaultValues?.womenCount || 0,
menCount: defaultValues?.menCount || 0, menCount: defaultValues?.menCount || 0,
surveyStatus: defaultValues?.surveyStatus || 'BORRADOR'
}, },
mode: 'onChange', mode: 'onChange',
}); });
@@ -208,6 +209,11 @@ export function CreateTrainingForm({
name: 'productiveActivity', name: 'productiveActivity',
}); });
const structureType = useWatch({
control: form.control,
name: 'structureType',
});
const productiveSectorOptions = ecoSector const productiveSectorOptions = ecoSector
? SECTOR_PRODUCTIVO_MAP[ecoSector] || [] ? SECTOR_PRODUCTIVO_MAP[ecoSector] || []
: []; : [];
@@ -222,6 +228,7 @@ export function CreateTrainingForm({
: []; : [];
const other = productiveActivity == 'OTRO' ? true : false; const other = productiveActivity == 'OTRO' ? true : false;
const showInfrastructure = structureType && structureType !== 'NINGUNA';
// Reset dependent fields when parent changes // Reset dependent fields when parent changes
React.useEffect(() => { React.useEffect(() => {
@@ -371,7 +378,7 @@ export function CreateTrainingForm({
<Input <Input
{...field} {...field}
placeholder="Ej. 04121234567" placeholder="Ej. 04121234567"
value={field.value ?? ''} value={field.value}
onChange={(e) => { onChange={(e) => {
const val = e.target.value.replace(/\D/g, ''); const val = e.target.value.replace(/\D/g, '');
field.onChange(val.slice(0, 11)); field.onChange(val.slice(0, 11));
@@ -393,7 +400,7 @@ export function CreateTrainingForm({
<Input <Input
type="datetime-local" type="datetime-local"
{...field} {...field}
value={field.value || ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -491,7 +498,7 @@ export function CreateTrainingForm({
</FormLabel> </FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value ?? undefined} defaultValue={field.value}
> >
<FormControl> <FormControl>
<SelectTrigger className="w-full"> <SelectTrigger className="w-full">
@@ -527,7 +534,7 @@ export function CreateTrainingForm({
form.setValue('mainProductiveActivity', ''); form.setValue('mainProductiveActivity', '');
form.setValue('productiveActivity', ''); form.setValue('productiveActivity', '');
}} }}
defaultValue={field.value ?? undefined} defaultValue={field.value}
> >
<FormControl> <FormControl>
<SelectTrigger className="w-full"> <SelectTrigger className="w-full">
@@ -562,7 +569,7 @@ export function CreateTrainingForm({
form.setValue('mainProductiveActivity', ''); form.setValue('mainProductiveActivity', '');
form.setValue('productiveActivity', ''); form.setValue('productiveActivity', '');
}} }}
defaultValue={field.value ?? undefined} defaultValue={field.value}
disabled={!ecoSector} disabled={!ecoSector}
> >
<FormControl> <FormControl>
@@ -597,7 +604,7 @@ export function CreateTrainingForm({
form.setValue('mainProductiveActivity', ''); form.setValue('mainProductiveActivity', '');
form.setValue('productiveActivity', ''); form.setValue('productiveActivity', '');
}} }}
defaultValue={field.value ?? undefined} defaultValue={field.value}
disabled={!productiveSector} disabled={!productiveSector}
> >
<FormControl> <FormControl>
@@ -631,7 +638,7 @@ export function CreateTrainingForm({
field.onChange(val); field.onChange(val);
form.setValue('productiveActivity', ''); form.setValue('productiveActivity', '');
}} }}
defaultValue={field.value ?? undefined} defaultValue={field.value}
disabled={!centralProductiveActivity} disabled={!centralProductiveActivity}
> >
<FormControl> <FormControl>
@@ -662,7 +669,7 @@ export function CreateTrainingForm({
</FormLabel> </FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value ?? undefined} defaultValue={field.value}
disabled={!mainProductiveActivity} disabled={!mainProductiveActivity}
> >
<FormControl> <FormControl>
@@ -695,7 +702,7 @@ export function CreateTrainingForm({
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -715,7 +722,7 @@ export function CreateTrainingForm({
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
placeholder="J-12345678-9" placeholder="J-12345678-9"
/> />
</FormControl> </FormControl>
@@ -733,7 +740,7 @@ export function CreateTrainingForm({
Nombre de la organización (opcional) Nombre de la organización (opcional)
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -752,7 +759,7 @@ export function CreateTrainingForm({
<Input <Input
type="number" type="number"
{...field} {...field}
value={field.value ?? ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -770,7 +777,7 @@ export function CreateTrainingForm({
</FormLabel> </FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value ?? undefined} defaultValue={field.value}
> >
<FormControl> <FormControl>
<SelectTrigger> <SelectTrigger>
@@ -792,24 +799,56 @@ export function CreateTrainingForm({
<FormField <FormField
control={form.control} control={form.control}
name="infrastructureMt2" name="structureType"
render={({ field }) => ( render={({ field }) => (
<FormItem className="w-full flex flex-col space-y-3"> <FormItem className="w-full flex flex-col space-y-3">
<FormLabel className="whitespace-normal leading-tight font-semibold"> <FormLabel className="whitespace-normal leading-tight font-semibold">
infraestrutura (MT2) Tipo Estructura
</FormLabel> </FormLabel>
<FormControl> <Select
<Input onValueChange={field.onChange}
{...field} defaultValue={field.value}
value={field.value ?? ''} >
placeholder="e.g. 500" <FormControl>
/> <SelectTrigger>
</FormControl> <SelectValue placeholder="Seleccione tipo" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="CASA">CASA</SelectItem>
<SelectItem value="GALPÓN">GALPÓN</SelectItem>
<SelectItem value="LOCAL">LOCAL</SelectItem>
<SelectItem value="ALMACÉN">ALMACÉN</SelectItem>
<SelectItem value="NINGUNA">NINGUNA</SelectItem>
</SelectContent>
</Select>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
{showInfrastructure && (
<FormField
control={form.control}
name="infrastructureMt2"
render={({ field }) => (
<FormItem className="w-full flex flex-col space-y-3">
<FormLabel className="whitespace-normal leading-tight font-semibold">
infraestrutura (MT2)
</FormLabel>
<FormControl>
<Input
{...field}
value={field.value}
placeholder="e.g. 500"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}
<FormField <FormField
control={form.control} control={form.control}
name="hasTransport" name="hasTransport"
@@ -837,35 +876,6 @@ export function CreateTrainingForm({
)} )}
/> />
<FormField
control={form.control}
name="structureType"
render={({ field }) => (
<FormItem className="w-full flex flex-col space-y-3">
<FormLabel className="whitespace-normal leading-tight font-semibold">
Tipo Estructura
</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value ?? undefined}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Seleccione tipo" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="CASA">CASA</SelectItem>
<SelectItem value="GALPÓN">GALPÓN</SelectItem>
<SelectItem value="LOCAL">LOCAL</SelectItem>
<SelectItem value="ALMACÉN">ALMACÉN</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField <FormField
control={form.control} control={form.control}
name="isOpenSpace" name="isOpenSpace"
@@ -903,7 +913,7 @@ export function CreateTrainingForm({
Razones de paralización (opcional) Razones de paralización (opcional)
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Textarea {...field} value={field.value ?? ''} /> <Textarea {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -943,7 +953,7 @@ export function CreateTrainingForm({
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel> <FormLabel>
Breve Descripción de la Zona de Distribución Breve Descripción de la Zona de Distribución (Opcional)
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input <Input
@@ -992,7 +1002,7 @@ export function CreateTrainingForm({
<FormLabel>País</FormLabel> <FormLabel>País</FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value ?? undefined} defaultValue={field.value}
> >
<FormControl> <FormControl>
<SelectTrigger className="w-full"> <SelectTrigger className="w-full">
@@ -1019,7 +1029,7 @@ export function CreateTrainingForm({
<FormItem> <FormItem>
<FormLabel>Ciudad</FormLabel> <FormLabel>Ciudad</FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1035,12 +1045,13 @@ export function CreateTrainingForm({
<FormItem> <FormItem>
<FormLabel>Breve Descripción</FormLabel> <FormLabel>Breve Descripción</FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
<div className="grid grid-cols-2 gap-2"> <div className="grid grid-cols-2 gap-2">
<FormField <FormField
control={form.control} control={form.control}
@@ -1052,7 +1063,7 @@ export function CreateTrainingForm({
<Input <Input
type="number" type="number"
{...field} {...field}
value={field.value ?? ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -1067,7 +1078,7 @@ export function CreateTrainingForm({
<FormLabel>Unidad</FormLabel> <FormLabel>Unidad</FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value ?? undefined} defaultValue={field.value}
> >
<FormControl> <FormControl>
<SelectTrigger className="w-full"> <SelectTrigger className="w-full">
@@ -1142,12 +1153,12 @@ export function CreateTrainingForm({
<CardHeader> <CardHeader>
<CardTitle>3. Detalles de la ubicación</CardTitle> <CardTitle>3. Detalles de la ubicación</CardTitle>
</CardHeader> </CardHeader>
<CardContent className="grid grid-cols-1 lg:grid-cols-2 gap-6 items-start"> <CardContent className="grid grid-cols-1 md:grid-cols-2 gap-6 items-start">
<FormField <FormField
control={form.control} control={form.control}
name="ospAddress" name="ospAddress"
render={({ field }) => ( render={({ field }) => (
<FormItem className="col-span-1 lg:col-span-2 flex flex-col space-y-2"> <FormItem className="md:col-span-2 flex flex-col space-y-2">
<FormLabel> <FormLabel>
Dirección de la Organización Socio Productivo Dirección de la Organización Socio Productivo
</FormLabel> </FormLabel>
@@ -1163,14 +1174,14 @@ export function CreateTrainingForm({
control={form.control} control={form.control}
name="ospGoogleMapsLink" name="ospGoogleMapsLink"
render={({ field }) => ( render={({ field }) => (
<FormItem className="col-span-1 lg:col-span-2 flex flex-col space-y-2"> <FormItem className="md:col-span-2 flex flex-col space-y-2">
<FormLabel> <FormLabel>
Coordenadas de la Ubicación (Google Maps. Opcional) Coordenadas de la Ubicación (Google Maps. Opcional)
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
placeholder="10.123456, -66.123456" placeholder="10.123456, -66.123456"
/> />
</FormControl> </FormControl>
@@ -1179,7 +1190,7 @@ export function CreateTrainingForm({
)} )}
/> />
<div className="col-span-1 lg:col-span-2 border-b pb-2 mt-4 hidden md:inline"> <div className="col-span-2 border-b pb-2 mt-4 hidden md:inline">
<h4 className="font-semibold mb-2">Datos de la Comuna</h4> <h4 className="font-semibold mb-2">Datos de la Comuna</h4>
</div> </div>
@@ -1192,7 +1203,7 @@ export function CreateTrainingForm({
Nombre de la Comuna Nombre de la Comuna
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1208,7 +1219,7 @@ export function CreateTrainingForm({
Código SITUR de la Comuna Código SITUR de la Comuna
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1224,7 +1235,7 @@ export function CreateTrainingForm({
Rif de la Comuna Rif de la Comuna
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1240,7 +1251,7 @@ export function CreateTrainingForm({
Nombre del Vocero o Vocera Nombre del Vocero o Vocera
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1258,7 +1269,7 @@ export function CreateTrainingForm({
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
placeholder="Ej. 04121234567" placeholder="Ej. 04121234567"
onChange={(e) => { onChange={(e) => {
const val = e.target.value.replace(/\D/g, ''); const val = e.target.value.replace(/\D/g, '');
@@ -1283,7 +1294,7 @@ export function CreateTrainingForm({
<Input <Input
type="email" type="email"
{...field} {...field}
value={field.value ?? ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -1322,7 +1333,7 @@ export function CreateTrainingForm({
Código SITUR del Consejo Comunal Código SITUR del Consejo Comunal
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1338,7 +1349,7 @@ export function CreateTrainingForm({
Rif del Consejo Comunal Rif del Consejo Comunal
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1354,7 +1365,7 @@ export function CreateTrainingForm({
Nombre del Vocero o Vocera Nombre del Vocero o Vocera
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input {...field} value={field.value ?? ''} /> <Input {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1372,7 +1383,7 @@ export function CreateTrainingForm({
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
placeholder="Ej. 04121234567" placeholder="Ej. 04121234567"
onChange={(e) => { onChange={(e) => {
const val = e.target.value.replace(/\D/g, ''); const val = e.target.value.replace(/\D/g, '');
@@ -1397,7 +1408,7 @@ export function CreateTrainingForm({
<Input <Input
type="email" type="email"
{...field} {...field}
value={field.value ?? ''} value={field.value}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
@@ -1436,7 +1447,7 @@ export function CreateTrainingForm({
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
value={field.value ?? ''} value={field.value}
placeholder="Ej. 04121234567" placeholder="Ej. 04121234567"
onChange={(e) => { onChange={(e) => {
const val = e.target.value.replace(/\D/g, ''); const val = e.target.value.replace(/\D/g, '');
@@ -1453,7 +1464,7 @@ export function CreateTrainingForm({
control={form.control} control={form.control}
name="ospResponsibleFullname" name="ospResponsibleFullname"
render={({ field }) => ( render={({ field }) => (
<FormItem className="col-span-2"> <FormItem className="md:col-span-2">
<FormLabel>Nombre y apellido</FormLabel> <FormLabel>Nombre y apellido</FormLabel>
<FormControl> <FormControl>
<Input {...field} /> <Input {...field} />
@@ -1462,102 +1473,6 @@ export function CreateTrainingForm({
</FormItem> </FormItem>
)} )}
/> />
{/* <FormField
control={form.control}
name="ospResponsibleRif"
render={({ field }) => (
<FormItem>
<FormLabel>RIF (Opcional)</FormLabel>
<FormControl>
<Input {...field} value={field.value ?? ''} />
</FormControl>
<FormMessage />
</FormItem>
)}
/> */}
{/* <FormField
control={form.control}
name="civilState"
render={({ field }) => (
<FormItem>
<FormLabel>Estado Civil (Opcional)</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value ?? undefined}
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione estado civil" />
</SelectTrigger>
</FormControl>
<SelectContent>
{CIVIL_STATE_OPTIONS.map((state) => (
<SelectItem key={state} value={state}>
{state}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/> */}
{/* <FormField
control={form.control}
name="ospResponsibleEmail"
render={({ field }) => (
<FormItem>
<FormLabel>Correo Electrónico (Opcional)</FormLabel>
<FormControl>
<Input
type="email"
{...field}
value={field.value ?? ''}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/> */}
{/* <FormField
control={form.control}
name="familyBurden"
render={({ field }) => (
<FormItem>
<FormLabel>Carga Familiar (Opcional)</FormLabel>
<FormControl>
<Input
type="number"
{...field}
value={field.value ?? ''}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/> */}
{/* <FormField
control={form.control}
name="numberOfChildren"
render={({ field }) => (
<FormItem>
<FormLabel>Número de Hijos (Opcional)</FormLabel>
<FormControl>
<Input
type="number"
{...field}
value={field.value ?? ''}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/> */}
</CardContent> </CardContent>
</Card> </Card>
@@ -1574,7 +1489,7 @@ export function CreateTrainingForm({
<FormItem> <FormItem>
<FormLabel>Observaciones Generales (Opcional)</FormLabel> <FormLabel>Observaciones Generales (Opcional)</FormLabel>
<FormControl> <FormControl>
<Textarea {...field} value={field.value ?? ''} /> <Textarea {...field} value={field.value} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
@@ -1641,7 +1556,7 @@ export function CreateTrainingForm({
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<FormLabel> <FormLabel>
Subir nuevas imágenes (máximo 3 en total) Subir imágenes (Máximo 3 y opcional)
</FormLabel> </FormLabel>
<Input <Input
type="file" type="file"
@@ -1728,23 +1643,49 @@ export function CreateTrainingForm({
</CardContent> </CardContent>
</Card> </Card>
<div className="flex justify-end gap-4 mt-8"> <div className="grid grid-cols-2 md:grid-cols-3 justify-items-end gap-3 mt-8">
<Button <Button
variant="outline" variant="outline"
type="button" type="button"
onClick={onCancel} onClick={onCancel}
className="w-32" className="w-32 col-span-2 md:col-span-1"
> >
Cancelar Cancelar
</Button> </Button>
<FormField
control={form.control}
name="surveyStatus"
render={({ field }) => (
<FormItem>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Seleccione tipo" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem defaultChecked value="BORRADOR">BORRADOR</SelectItem>
<SelectItem value="PUBLICADO">PUBLICADO</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<Button <Button
type="submit" type="submit"
disabled={ disabled={
isSaving || isSaving
(selectedFiles.length === 0 && // ||
!['photo1', 'photo2', 'photo3'].some((f) => // (selectedFiles.length === 0 &&
form.watch(f as any), // !['photo1', 'photo2', 'photo3'].some((f) =>
)) // form.watch(f as any),
// ))
} }
className="w-32" className="w-32"
> >

View File

@@ -46,18 +46,17 @@ export const trainingSchema = z.object({
productiveActivity: z.string({ productiveActivity: z.string({
message: 'Actividad Productiva es requerida', message: 'Actividad Productiva es requerida',
}), }),
productiveActivityOther: z.string().min(1, { message: 'Este campo es requerido' }).optional(), productiveActivityOther: z.string().min(1, { message: 'Otra actividad productiva es requerida' }).optional(),
ospRif: z.string().optional().or(z.literal('')).nullable(), ospRif: z.string().optional(),
ospName: z.string().optional().or(z.literal('')).nullable(), ospName: z.string().optional(),
companyConstitutionYear: z.coerce companyConstitutionYear: z.coerce
.number() .number()
.min(1900, { message: 'Año inválido' }) .min(1900, { message: 'Año inválido' }),
.nullable(),
currentStatus: z currentStatus: z
.string() .string()
.min(1, { message: 'Estatus actual es requerido' }) .min(1, { message: 'Estatus actual es requerido' })
.default('ACTIVA'), .default('ACTIVA'),
infrastructureMt2: z.string({ message: 'Infraestructura es requerida' }), infrastructureMt2: z.string({ message: 'Infraestructura es requerida' }).optional(),
hasTransport: z hasTransport: z
.preprocess( .preprocess(
(val) => val === 'true' || val === true || val === 1 || val === '1', (val) => val === 'true' || val === true || val === 1 || val === '1',
@@ -75,7 +74,7 @@ export const trainingSchema = z.object({
.optional() .optional()
.nullable() .nullable()
.default(false), .default(false),
paralysisReason: z.string().optional().nullable(), paralysisReason: z.string().optional(),
//Datos del Equipamiento //Datos del Equipamiento
equipmentList: z.array(equipmentItemSchema).optional().default([]), equipmentList: z.array(equipmentItemSchema).optional().default([]),
@@ -88,8 +87,7 @@ export const trainingSchema = z.object({
// Distribución y Exportación // Distribución y Exportación
internalDistributionZone: z internalDistributionZone: z
.string() .string(),
.min(1, { message: 'Zona de distribución es requerida' }),
isExporting: z isExporting: z
.preprocess( .preprocess(
(val) => val === 'true' || val === true || val === 1 || val === '1', (val) => val === 'true' || val === true || val === 1 || val === '1',
@@ -97,11 +95,11 @@ export const trainingSchema = z.object({
) )
.optional() .optional()
.default(false), .default(false),
externalCountry: z.string().optional().nullable(), externalCountry: z.string().optional(),
externalCity: z.string().optional().nullable(), externalCity: z.string().optional(),
externalDescription: z.string().optional().nullable(), externalDescription: z.string().optional(),
externalQuantity: z.coerce.string().or(z.number()).optional().nullable(), externalQuantity: z.coerce.string().or(z.number()).optional(),
externalUnit: z.string().optional().nullable(), externalUnit: z.string().optional(),
// Mano de obra // Mano de obra
womenCount: z.coerce womenCount: z.coerce
@@ -115,7 +113,7 @@ export const trainingSchema = z.object({
ospAddress: z ospAddress: z
.string() .string()
.min(1, { message: 'Dirección de la OSP es requerida' }), .min(1, { message: 'Dirección de la OSP es requerida' }),
ospGoogleMapsLink: z.string().optional().or(z.literal('')).nullable(), ospGoogleMapsLink: z.string().optional().or(z.literal('')),
communeName: z communeName: z
.string() .string()
.min(1, { message: 'Nombre de la comuna es requerida' }), .min(1, { message: 'Nombre de la comuna es requerida' }),
@@ -137,8 +135,7 @@ export const trainingSchema = z.object({
.string() .string()
.email({ message: 'Correo electrónico de la Comuna inválido' }) .email({ message: 'Correo electrónico de la Comuna inválido' })
.optional() .optional()
.or(z.literal('')) .or(z.literal('')),
.nullable(),
communalCouncil: z communalCouncil: z
.string() .string()
.min(1, { message: 'Consejo Comunal es requerido' }), .min(1, { message: 'Consejo Comunal es requerido' }),
@@ -162,8 +159,7 @@ export const trainingSchema = z.object({
.string() .string()
.email({ message: 'Correo electrónico del Consejo Comunal inválido' }) .email({ message: 'Correo electrónico del Consejo Comunal inválido' })
.optional() .optional()
.or(z.literal('')) .or(z.literal('')),
.nullable(),
//Datos del Responsable OSP //Datos del Responsable OSP
ospResponsibleCedula: z ospResponsibleCedula: z
@@ -191,7 +187,7 @@ export const trainingSchema = z.object({
numberOfChildren: z.coerce.number().optional(), numberOfChildren: z.coerce.number().optional(),
//Datos adicionales //Datos adicionales
generalObservations: z.string().optional().nullable(), generalObservations: z.string().optional(),
//IMAGENES //IMAGENES
files: z.any().optional(), files: z.any().optional(),
@@ -210,6 +206,7 @@ export const trainingSchema = z.object({
updatedBy: z.number().optional().nullable(), updatedBy: z.number().optional().nullable(),
created_at: z.string().optional().nullable(), created_at: z.string().optional().nullable(),
updated_at: z.string().optional().nullable(), updated_at: z.string().optional().nullable(),
surveyStatus: z.string()
}); });
export type TrainingSchema = z.infer<typeof trainingSchema>; export type TrainingSchema = z.infer<typeof trainingSchema>;
@@ -228,11 +225,11 @@ export const getTrainingSchema = z.object({
mainProductiveActivity: z.string(), mainProductiveActivity: z.string(),
productiveActivity: z.string(), productiveActivity: z.string(),
productiveActivityOther: z.string(), productiveActivityOther: z.string(),
ospRif: z.string().optional().or(z.literal('')).nullable(), ospRif: z.string().optional().or(z.literal('')),
ospName: z.string().optional().or(z.literal('')).nullable(), ospName: z.string().optional().or(z.literal('')),
companyConstitutionYear: z.coerce.number(), companyConstitutionYear: z.coerce.number(),
currentStatus: z.string(), currentStatus: z.string(),
infrastructureMt2: z.string(), infrastructureMt2: z.string().optional(),
hasTransport: z hasTransport: z
.preprocess( .preprocess(
(val) => val === 'true' || val === true || val === 1 || val === '1', (val) => val === 'true' || val === true || val === 1 || val === '1',
@@ -250,7 +247,7 @@ export const getTrainingSchema = z.object({
.optional() .optional()
.nullable() .nullable()
.default(false), .default(false),
paralysisReason: z.string().optional().nullable(), paralysisReason: z.string().optional(),
//Datos del Equipamiento //Datos del Equipamiento
equipmentList: z.array(equipmentItemSchema).optional().default([]), equipmentList: z.array(equipmentItemSchema).optional().default([]),
//Datos de Producción //Datos de Producción
@@ -266,23 +263,23 @@ export const getTrainingSchema = z.object({
) )
.optional() .optional()
.default(false), .default(false),
externalCountry: z.string().optional().nullable(), externalCountry: z.string().optional(),
externalCity: z.string().optional().nullable(), externalCity: z.string().optional(),
externalDescription: z.string().optional().nullable(), externalDescription: z.string().optional(),
externalQuantity: z.coerce.string().or(z.number()).optional().nullable(), externalQuantity: z.coerce.string().or(z.number()).optional(),
externalUnit: z.string().optional().nullable(), externalUnit: z.string().optional(),
// Mano de obra // Mano de obra
womenCount: z.coerce.number(), womenCount: z.coerce.number(),
menCount: z.coerce.number(), menCount: z.coerce.number(),
//Detalles de la ubicación //Detalles de la ubicación
ospAddress: z.string(), ospAddress: z.string(),
ospGoogleMapsLink: z.string().optional().or(z.literal('')).nullable(), ospGoogleMapsLink: z.string().optional().or(z.literal('')),
communeName: z.string(), communeName: z.string(),
siturCodeCommune: z.string(), siturCodeCommune: z.string(),
communeRif: z.string().or(z.literal('')).nullable(), communeRif: z.string().or(z.literal('')),
communeSpokespersonName: z.string().or(z.literal('')).nullable(), communeSpokespersonName: z.string().or(z.literal('')),
communeSpokespersonPhone: z.string(), communeSpokespersonPhone: z.string(),
communeEmail: z.string().optional().or(z.literal('')).nullable(), communeEmail: z.string().optional().or(z.literal('')),
communalCouncil: z.string(), communalCouncil: z.string(),
siturCodeCommunalCouncil: z.string(), siturCodeCommunalCouncil: z.string(),
communalCouncilRif: z.string().optional(), communalCouncilRif: z.string().optional(),
@@ -292,14 +289,14 @@ export const getTrainingSchema = z.object({
//Datos del Responsable OSP //Datos del Responsable OSP
ospResponsibleCedula: z.string(), ospResponsibleCedula: z.string(),
ospResponsibleFullname: z.string(), ospResponsibleFullname: z.string(),
ospResponsibleRif: z.string().optional().nullable(), ospResponsibleRif: z.string().optional(),
civilState: z.string().optional().nullable(), civilState: z.string().optional(),
ospResponsiblePhone: z.string(), ospResponsiblePhone: z.string(),
ospResponsibleEmail: z.string(), ospResponsibleEmail: z.string(),
familyBurden: z.coerce.number().optional(), familyBurden: z.coerce.number().optional(),
numberOfChildren: z.coerce.number().optional(), numberOfChildren: z.coerce.number().optional(),
//Datos adicionales //Datos adicionales
generalObservations: z.string().optional().nullable(), generalObservations: z.string().optional(),
//no se envia la backend al crear ni editar el formulario //no se envia la backend al crear ni editar el formulario
state: z.number().nullable(), state: z.number().nullable(),
municipality: z.number().nullable(), municipality: z.number().nullable(),
@@ -314,8 +311,10 @@ export const getTrainingSchema = z.object({
updatedBy: z.number().optional().nullable(), updatedBy: z.number().optional().nullable(),
created_at: z.string().optional().nullable(), created_at: z.string().optional().nullable(),
updated_at: z.string().optional().nullable(), updated_at: z.string().optional().nullable(),
surveyStatus: z.string()
}); });
// Para mostrar datos
export const trainingApiResponseSchema = z.object({ export const trainingApiResponseSchema = z.object({
message: z.string(), message: z.string(),
data: z.array(getTrainingSchema), data: z.array(getTrainingSchema),
@@ -331,7 +330,8 @@ export const trainingApiResponseSchema = z.object({
}), }),
}); });
//
export const TrainingMutate = z.object({ export const TrainingMutate = z.object({
message: z.string(), message: z.string(),
data: trainingSchema, data: getTrainingSchema,
}); });