agregado los campos de distribucion (interna y externa)

This commit is contained in:
2026-01-28 15:54:26 -04:00
parent 69843e9e68
commit d2908f1e4c
8 changed files with 2770 additions and 112 deletions

View File

@@ -37,6 +37,8 @@ import {
import { SelectSearchable } from '@repo/shadcn/select-searchable';
import React from 'react';
import { COUNTRY_OPTIONS } from '@/constants/countries';
// const PRODUCTIVE_ACTIVITIES = [
// 'Agricola',
// 'Textil',
@@ -47,9 +49,6 @@ import React from 'react';
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 PRODUCTIVE_SECTORS = ['Agricola', 'Manufactura', 'Servicios', 'Comercio', 'Turismo'];
const CENTRAL_PRODUCTIVE_ACTIVITY = [
@@ -62,11 +61,6 @@ const CENTRAL_PRODUCTIVE_ACTIVITY = [
'COMERCIO'
];
// const PRODUCTIVE_SECTORS_PRIMARIO = ['Agricola'];
// const PRODUCTIVE_SECTORS_SECUNDARIO = ['Manufactura'];
// const PRODUCTIVE_SECTORS_TERCIARIO = ['Servicios', 'Comercio', 'Turismo'];
const MAIN_PRODUCTIVE_ACTIVITY = [
'AGRICULTURA ',
'CRIA ',
@@ -168,10 +162,10 @@ export function CreateTrainingForm({
const isSaving = isCreating || isUpdating;
// const [state, setState] = React.useState(0);
// const [municipality, setMunicipality] = React.useState(0);
// const [disabledMunicipality, setDisabledMunicipality] = React.useState(true);
// const [disabledParish, setDisabledParish] = React.useState(true);
const [state, setState] = React.useState(0);
const [municipality, setMunicipality] = React.useState(0);
const [disabledMunicipality, setDisabledMunicipality] = React.useState(true);
const [disabledParish, setDisabledParish] = React.useState(true);
const [coorState, setcoorState] = React.useState(0);
const [coorMunicipality, setcoorMunicipality] = React.useState(0);
@@ -180,9 +174,9 @@ export function CreateTrainingForm({
const [selectedFiles, setSelectedFiles] = React.useState<File[]>([]);
// const { data: dataState } = useStateQuery();
// const { data: dataMunicipality } = useMunicipalityQuery(state);
// const { data: dataParish } = useParishQuery(municipality);
const { data: dataState } = useStateQuery();
const { data: dataMunicipality } = useMunicipalityQuery(state);
const { data: dataParish } = useParishQuery(municipality);
const { data: dataCoorState } = useStateQuery();
const { data: dataCoorMunicipality } = useMunicipalityQuery(coorState);
@@ -202,30 +196,30 @@ export function CreateTrainingForm({
: [{ id: 0, stateId: 0, name: 'Sin Parroquias' }];
// const stateOptions = dataState?.data || [{ id: 0, name: 'Sin estados' }];
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 municipalityOptions =
Array.isArray(dataMunicipality?.data) && dataMunicipality.data.length > 0
? dataMunicipality.data
: [{ id: 0, stateId: 0, name: 'Sin Municipios' }];
// const parishOptions =
// Array.isArray(dataParish?.data) && dataParish.data.length > 0
// ? dataParish.data
// : [{ id: 0, stateId: 0, name: 'Sin Parroquias' }];
const parishOptions =
Array.isArray(dataParish?.data) && dataParish.data.length > 0
? dataParish.data
: [{ id: 0, stateId: 0, name: 'Sin Parroquias' }];
// No local state needed for existing photos, we use form values
React.useEffect(() => {
if (defaultValues) {
// if (defaultValues.state) {
// setState(Number(defaultValues.state));
// setDisabledMunicipality(false);
// }
// if (defaultValues.municipality) {
// setMunicipality(Number(defaultValues.municipality));
// setDisabledParish(false);
// }
if (defaultValues.state) {
setState(Number(defaultValues.state));
setDisabledMunicipality(false);
}
if (defaultValues.municipality) {
setMunicipality(Number(defaultValues.municipality));
setDisabledParish(false);
}
if (defaultValues.coorState) {
setcoorState(Number(defaultValues.coorState));
@@ -272,8 +266,8 @@ export function CreateTrainingForm({
productCountDaily: defaultValues?.productCountDaily || 0,
productCountWeekly: defaultValues?.productCountWeekly || 0,
productCountMonthly: defaultValues?.productCountMonthly || 0,
financialRequirementDescription:
defaultValues?.financialRequirementDescription || '',
// financialRequirementDescription:
// defaultValues?.financialRequirementDescription || '',
siturCodeCommune: defaultValues?.siturCodeCommune || '',
communeName: defaultValues?.communeName || '',
communeRif: defaultValues?.communeRif || '',
@@ -299,8 +293,9 @@ export function CreateTrainingForm({
companyConstitutionYear:
defaultValues?.companyConstitutionYear || new Date().getFullYear(),
producerCount: defaultValues?.producerCount || 0,
productCount: defaultValues?.productCount || 0,
// productCount: defaultValues?.productCount || 0,
productDescription: defaultValues?.productDescription || '',
prodDescriptionInternal: defaultValues?.prodDescriptionInternal || '',
installedCapacity: defaultValues?.installedCapacity || '',
operationalCapacity: defaultValues?.operationalCapacity || '',
ospResponsibleFullname: defaultValues?.ospResponsibleFullname || '',
@@ -316,9 +311,16 @@ export function CreateTrainingForm({
photo2: defaultValues?.photo2 || '',
photo3: defaultValues?.photo3 || '',
paralysisReason: defaultValues?.paralysisReason || '',
// state: defaultValues?.state || undefined,
// municipality: defaultValues?.municipality || undefined,
// parish: defaultValues?.parish || undefined
state: defaultValues?.state || undefined,
municipality: defaultValues?.municipality || undefined,
parish: defaultValues?.parish || undefined,
internalCount: defaultValues?.internalCount || 0,
externalCount: defaultValues?.externalCount || 0,
prodDescriptionExternal: defaultValues?.prodDescriptionExternal || '',
country: defaultValues?.country || undefined,
city: defaultValues?.city || undefined,
menCount: defaultValues?.menCount || 0,
womenCount: defaultValues?.womenCount || 0,
},
mode: 'onChange',
});
@@ -565,7 +567,7 @@ export function CreateTrainingForm({
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione tipo" />
<SelectValue placeholder="Seleccione sector económico" />
</SelectTrigger>
</FormControl>
<SelectContent>
@@ -593,7 +595,7 @@ export function CreateTrainingForm({
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione tipo" />
<SelectValue placeholder="Seleccione sector productivo" />
</SelectTrigger>
</FormControl>
<SelectContent>
@@ -621,7 +623,7 @@ export function CreateTrainingForm({
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione tipo" />
<SelectValue placeholder="Seleccione actividad central productiva" />
</SelectTrigger>
</FormControl>
<SelectContent>
@@ -640,6 +642,34 @@ export function CreateTrainingForm({
<FormField
control={form.control}
name="mainProductiveActivity"
render={({ field }) => (
<FormItem>
<FormLabel>Actividad Productiva Principal</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione actividad productiva principal" />
</SelectTrigger>
</FormControl>
<SelectContent>
{MAIN_PRODUCTIVE_ACTIVITY.map((type) => (
<SelectItem key={type} value={type}>
{type}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="productiveActivity"
render={({ field }) => (
<FormItem>
<FormLabel>Actividad Productiva</FormLabel>
@@ -649,7 +679,7 @@ export function CreateTrainingForm({
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione tipo" />
<SelectValue placeholder="Seleccione actividad productiva" />
</SelectTrigger>
</FormControl>
<SelectContent>
@@ -721,8 +751,64 @@ export function CreateTrainingForm({
)}
/> */}
{/* Tipo de equipamiento */}
<FormField
control={form.control}
name="companyConstitutionYear"
render={({ field }) => (
<FormItem>
<FormLabel>Año de constitución</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="currentStatus"
render={({ field }) => (
<FormItem>
<FormLabel>Estatus</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Seleccione estatus" />
</SelectTrigger>
</FormControl>
<SelectContent>
{STATUS_OPTIONS.map((status) => (
<SelectItem key={status} value={status}>
{status}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="paralysisReason"
render={({ field }) => (
<FormItem className="col-span-2">
<FormLabel>Razones de paralización (si aplica)</FormLabel>
<FormControl>
<Textarea {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<hr className="col-span-2" />
{/* Tipo de equipamiento */}
<h3 className="text-lg font-semibold col-span-2">Tipo de equipamiento:</h3>
<FormField
control={form.control}
@@ -767,7 +853,7 @@ export function CreateTrainingForm({
/>
<hr className="col-span-2" />
{/* Productos Terminados */}
{/* Datos de Producción de la Organización Socio Productivo */}
<h3 className="text-lg font-semibold col-span-2">Datos de Producción de la Organización Socio Productivo:</h3>
<FormField
@@ -871,16 +957,88 @@ export function CreateTrainingForm({
</FormItem>
)}
/>
<hr className="col-span-2" />
{/* Distribución Interna */}
<h3 className="text-lg font-semibold col-span-2">Distribución Interna</h3>
<FormField
control={form.control}
name="companyConstitutionYear"
name="state"
render={({ field }) => (
<FormItem>
<FormLabel>Año de constitución</FormLabel>
<FormLabel>Estado</FormLabel>
<SelectSearchable
options={stateOptions.map((item) => ({
value: item.id.toString(),
label: item.name,
}))}
onValueChange={(value) => {
field.onChange(Number(value));
setState(Number(value));
setDisabledMunicipality(false);
setDisabledParish(true);
}}
placeholder="Selecciona un estado"
defaultValue={field.value?.toString()}
/>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="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));
setMunicipality(Number(value));
setDisabledParish(false);
}}
placeholder="Selecciona un municipio"
disabled={disabledMunicipality}
defaultValue={field.value?.toString()}
/>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="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={disabledParish}
defaultValue={field.value?.toString()}
/>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="internalCount"
render={({ field }) => (
<FormItem>
<FormLabel>Cantidad</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
@@ -890,6 +1048,125 @@ export function CreateTrainingForm({
/>
<FormField
control={form.control}
name="prodDescriptionInternal"
render={({ field }) => (
<FormItem className="col-span-2">
<FormLabel>Breve descripción</FormLabel>
<FormControl>
<Textarea {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<hr className='col-span-2' />
{/* Distribución Externa */}
<h3 className="text-lg font-semibold col-span-2">Distribución Externa (Exportación)</h3>
<FormField
control={form.control}
name="country"
render={({ field }) => (
<FormItem>
<FormLabel>País</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger className="w-full">
<SelectValue placeholder="Seleccione tipo" />
</SelectTrigger>
</FormControl>
<SelectContent>
{COUNTRY_OPTIONS.map((type) => (
<SelectItem key={type} value={type}>
{type}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="city"
render={({ field }) => (
<FormItem>
<FormLabel>Ciudad</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="externalCount"
render={({ field }) => (
<FormItem>
<FormLabel>Cantidad (Kg, TON, UNID. LT)</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="prodDescriptionExternal"
render={({ field }) => (
<FormItem>
<FormLabel>Breve descripción</FormLabel>
<FormControl>
<Textarea {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<hr className='col-span-2' />
<h3 className="text-lg font-semibold col-span-2">Cantidad Mano de Obra</h3>
<FormField
control={form.control}
name="menCount"
render={({ field }) => (
<FormItem>
<FormLabel>Hombres</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="womenCount"
render={({ field }) => (
<FormItem>
<FormLabel>Mujeres</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* <FormField
control={form.control}
name="productCount"
render={({ field }) => (
@@ -901,37 +1178,9 @@ export function CreateTrainingForm({
<FormMessage />
</FormItem>
)}
/>
/> */}
<FormField
control={form.control}
name="currentStatus"
render={({ field }) => (
<FormItem>
<FormLabel>Estatus</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Seleccione estatus" />
</SelectTrigger>
</FormControl>
<SelectContent>
{STATUS_OPTIONS.map((status) => (
<SelectItem key={status} value={status}>
{status}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
{/* <FormField
control={form.control}
name="productDescription"
render={({ field }) => (
@@ -945,9 +1194,9 @@ export function CreateTrainingForm({
<FormMessage />
</FormItem>
)}
/>
/> */}
<FormField
{/* <FormField
control={form.control}
name="installedCapacity"
render={({ field }) => (
@@ -959,9 +1208,9 @@ export function CreateTrainingForm({
<FormMessage />
</FormItem>
)}
/>
/> */}
<FormField
{/* <FormField
control={form.control}
name="operationalCapacity"
render={({ field }) => (
@@ -973,9 +1222,9 @@ export function CreateTrainingForm({
<FormMessage />
</FormItem>
)}
/>
/> */}
<FormField
{/* <FormField
control={form.control}
name="financialRequirementDescription"
render={({ field }) => (
@@ -989,21 +1238,7 @@ export function CreateTrainingForm({
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="paralysisReason"
render={({ field }) => (
<FormItem className="col-span-2">
<FormLabel>Razones de paralización (si aplica)</FormLabel>
<FormControl>
<Textarea {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
/> */}
</CardContent>
</Card>