datos de visita agregada
This commit is contained in:
@@ -45,7 +45,19 @@ const PRODUCTIVE_ACTIVITIES = [
|
||||
'Unidad de suministro',
|
||||
];
|
||||
|
||||
const OSP_TYPES = ['COOPERATIVA', 'EPSIC', 'EPSDC', 'UPF', 'OTROS'];
|
||||
const ECO_SECTORS = ['Primario', 'Secundario', 'Terciario'];
|
||||
|
||||
// const ECO_SECTORS_PRIMARIO = ['Agropecuario', 'Pesca', 'Minería', 'Forestal'];
|
||||
// const ECO_SECTORS_SECUNDARIO = ['Manufactura', 'Construcción', 'Energía'];
|
||||
const ECO_SECTORS_PRIMARIO = ['Agricola'];
|
||||
const ECO_SECTORS_SECUNDARIO = ['Manufactura'];
|
||||
const ECO_SECTORS_TERCIARIO = ['Servicios', 'Comercio', 'Turismo'];
|
||||
|
||||
const CENTRAL_PRODUCTIVE_ACTIVITY = ['Produción Vegetal', 'Produción Animal', 'Produción Animal y Vegetal'];
|
||||
const MAIN_PRODUCTIVE_ACTIVITY = ['Agricultura', ''];
|
||||
|
||||
|
||||
const OSP_TYPES = ['EPSIC', 'EPSDC', 'UPF', 'OTROS', 'COOPERATIVA'];
|
||||
const STATUS_OPTIONS = ['ACTIVA', 'INACTIVA'];
|
||||
const CIVIL_STATE_OPTIONS = ['Soltero', 'Casado'];
|
||||
|
||||
@@ -69,19 +81,43 @@ export function CreateTrainingForm({
|
||||
const [municipality, setMunicipality] = React.useState(0);
|
||||
const [disabledMunicipality, setDisabledMunicipality] = React.useState(true);
|
||||
const [disabledParish, setDisabledParish] = React.useState(true);
|
||||
|
||||
const [coor_state, setCoor_state] = React.useState(0);
|
||||
const [coor_municipality, setCoor_municipality] = React.useState(0);
|
||||
const [disabledCoorMunicipality, setDisabledCoorMunicipality] = React.useState(true);
|
||||
const [disabledCoorParish, setDisabledCoorParish] = React.useState(true);
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = React.useState<File[]>([]);
|
||||
|
||||
const { data: dataState } = useStateQuery();
|
||||
const { data: dataMunicipality } = useMunicipalityQuery(state);
|
||||
const { data: dataParish } = useParishQuery(municipality);
|
||||
|
||||
const { data: dataCoorState } = useStateQuery();
|
||||
const { data: dataCoorMunicipality } = useMunicipalityQuery(coor_state);
|
||||
const { data: dataCoorParish } = useParishQuery(coor_municipality);
|
||||
|
||||
|
||||
const coor_stateOptions = dataCoorState?.data || [{ id: 0, name: 'Sin estados' }];
|
||||
|
||||
const coor_municipalityOptions =
|
||||
Array.isArray(dataCoorMunicipality?.data) && dataCoorMunicipality.data.length > 0
|
||||
? dataCoorMunicipality.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Municipios' }];
|
||||
|
||||
const coor_parishOptions =
|
||||
Array.isArray(dataCoorParish?.data) && dataCoorParish.data.length > 0
|
||||
? dataCoorParish.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Parroquias' }];
|
||||
|
||||
|
||||
const stateOptions = dataState?.data || [{ id: 0, name: 'Sin estados' }];
|
||||
|
||||
const municipalityOptions =
|
||||
Array.isArray(dataMunicipality?.data) && dataMunicipality.data.length > 0
|
||||
? dataMunicipality.data
|
||||
: [{ id: 0, stateId: 0, name: 'Sin Municipios' }];
|
||||
// const parishOptions = dataParish?.data || [{id:0,municipalityId:0,name:'Sin Parroquias'}]
|
||||
|
||||
const parishOptions =
|
||||
Array.isArray(dataParish?.data) && dataParish.data.length > 0
|
||||
? dataParish.data
|
||||
@@ -99,6 +135,14 @@ export function CreateTrainingForm({
|
||||
setMunicipality(Number(defaultValues.municipality));
|
||||
setDisabledParish(false);
|
||||
}
|
||||
if (defaultValues.coor_state) {
|
||||
setCoor_state(Number(defaultValues.coor_state));
|
||||
setDisabledCoorMunicipality(false);
|
||||
}
|
||||
if (defaultValues.coor_municipality) {
|
||||
setCoor_municipality(Number(defaultValues.coor_municipality));
|
||||
setDisabledParish(false);
|
||||
}
|
||||
}
|
||||
}, [defaultValues]);
|
||||
|
||||
@@ -117,8 +161,13 @@ export function CreateTrainingForm({
|
||||
defaultValues: {
|
||||
firstname: defaultValues?.firstname || '',
|
||||
lastname: defaultValues?.lastname || '',
|
||||
coor_state: defaultValues?.coor_state || undefined,
|
||||
coor_municipality: defaultValues?.coor_municipality || undefined,
|
||||
coor_parish: defaultValues?.coor_parish || undefined,
|
||||
coor_phone: defaultValues?.coor_phone || '',
|
||||
visitDate: formatToLocalISO(defaultValues?.visitDate),
|
||||
productiveActivity: defaultValues?.productiveActivity || '',
|
||||
ecoSector: defaultValues?.ecoSector || '',
|
||||
financialRequirementDescription:
|
||||
defaultValues?.financialRequirementDescription || '',
|
||||
siturCodeCommune: defaultValues?.siturCodeCommune || '',
|
||||
@@ -245,6 +294,91 @@ export function CreateTrainingForm({
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="coor_phone"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Telefono del coordinador Estadal</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} placeholder="Ej. 04121234567" value={field.value ?? ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="coor_state"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Estado</FormLabel>
|
||||
<SelectSearchable
|
||||
options={stateOptions.map((item) => ({
|
||||
value: item.id.toString(),
|
||||
label: item.name,
|
||||
}))}
|
||||
onValueChange={(value) => {
|
||||
field.onChange(Number(value));
|
||||
setCoor_state(Number(value));
|
||||
setDisabledCoorMunicipality(false);
|
||||
setDisabledCoorParish(true);
|
||||
}}
|
||||
placeholder="Selecciona un estado"
|
||||
defaultValue={field.value?.toString()}
|
||||
/>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="coor_municipality"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Municipio</FormLabel>
|
||||
<SelectSearchable
|
||||
options={municipalityOptions.map((item) => ({
|
||||
value: item.id.toString(),
|
||||
label: item.name,
|
||||
}))}
|
||||
onValueChange={(value) => {
|
||||
field.onChange(Number(value));
|
||||
setCoor_municipality(Number(value));
|
||||
setDisabledCoorParish(false);
|
||||
}}
|
||||
placeholder="Selecciona un municipio"
|
||||
disabled={disabledCoorMunicipality}
|
||||
defaultValue={field.value?.toString()}
|
||||
/>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="coor_parish"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Parroquia</FormLabel>
|
||||
<SelectSearchable
|
||||
options={parishOptions.map((item) => ({
|
||||
value: item.id.toString(),
|
||||
label: item.name,
|
||||
}))}
|
||||
onValueChange={(value) => field.onChange(Number(value))}
|
||||
placeholder="Selecciona una parroquia"
|
||||
disabled={disabledCoorParish}
|
||||
defaultValue={field.value?.toString()}
|
||||
/>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="visitDate"
|
||||
@@ -301,6 +435,34 @@ export function CreateTrainingForm({
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="ecoSector"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Sector Económico</FormLabel>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Seleccione tipo" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{ECO_SECTORS.map((type) => (
|
||||
<SelectItem key={type} value={type}>
|
||||
{type}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="ospRif"
|
||||
|
||||
@@ -82,6 +82,12 @@ export const trainingSchema = z.object({
|
||||
state: z.number().optional().nullable(),
|
||||
municipality: z.number().optional().nullable(),
|
||||
parish: z.number().optional().nullable(),
|
||||
coor_state: z.number().optional().nullable(),
|
||||
coor_municipality: z.number().optional().nullable(),
|
||||
coor_parish: z.number().optional().nullable(),
|
||||
coor_phone: z.string().optional().nullable(),
|
||||
ecoSector: z.string().min(1, { message: 'Sector económico es requerido' })
|
||||
// mainProductiveActivity: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
export type TrainingSchema = z.infer<typeof trainingSchema>;
|
||||
|
||||
Reference in New Issue
Block a user