Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3269 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3269 Rev 3697
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect } from 'react';
2
import { useSelector } from 'react-redux'
2
import { useSelector } from 'react-redux';
3
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form';
4
import { Box } from '@mui/material'
4
import { Box } from '@mui/material';
5
 
5
 
6
import { getYears } from 'utils/dates'
6
import { getYears } from 'utils/dates';
7
import { useFetchHelper } from '@hooks'
7
import { useFetchHelper } from '@hooks';
8
 
8
 
9
import CKEditor from '@components/common/ckeditor/Ckeditor'
9
import CKEditor from '@components/common/ckeditor/Ckeditor';
10
import Modal from '@app/components/UI/modal/Modal'
10
import Modal from '@app/components/UI/modal/Modal';
11
import Select from '@app/components/UI/inputs/Select'
11
import Select from '@app/components/UI/inputs/Select';
12
import FormErrorFeedback from '@app/components/UI/form/FormErrorFeedback'
12
import FormErrorFeedback from '@app/components/UI/form/FormErrorFeedback';
13
import Input from '@app/components/UI/inputs/Input'
13
import Input from '@app/components/UI/inputs/Input';
14
import SwitchInput from '@app/components/UI/SwitchInput'
14
import SwitchInput from '@app/components/UI/SwitchInput';
15
import UbicationInput from '@app/components/UI/inputs/UbicationInput'
15
import UbicationInput from '@app/components/UI/inputs/UbicationInput';
Línea 16... Línea 16...
16
 
16
 
17
const EducationModal = ({
17
const EducationModal = ({
18
  show = false,
18
  show = false,
19
  currentEducation = null,
19
  currentEducation = null,
20
  onClose = () => {},
20
  onClose = () => {},
21
  onConfirm = () => {}
21
  onConfirm = () => {}
22
}) => {
22
}) => {
23
  const { data: degrees } = useFetchHelper('degrees')
23
  const { data: degrees } = useFetchHelper('degrees');
Línea 24... Línea 24...
24
  const labels = useSelector(({ intl }) => intl.labels)
24
  const labels = useSelector(({ intl }) => intl.labels);
25
 
25
 
26
  const {
26
  const {
27
    control,
27
    control,
Línea 42... Línea 42...
42
      from_year: '',
42
      from_year: '',
43
      to_year: '',
43
      to_year: '',
44
      description: ''
44
      description: ''
45
    },
45
    },
46
    values: currentEducation
46
    values: currentEducation
47
  })
47
  });
48
  const isCurrent = watch('is_current', 'n') === 'y'
48
  const isCurrent = watch('is_current', 'n') === 'y';
Línea 49... Línea 49...
49
 
49
 
50
  const handleAddress = (address) => {
50
  const handleAddress = (address) => {
51
    Object.entries(address).forEach(([key, value]) => {
51
    Object.entries(address).forEach(([key, value]) => {
52
      if (value) {
52
      if (value) {
53
        register(key)
53
        register(key);
54
        setValue(key, value)
54
        setValue(key, value);
55
      }
55
      }
56
    })
56
    });
Línea 57... Línea 57...
57
  }
57
  };
58
 
58
 
59
  const handleCloseModal = () => {
59
  const handleCloseModal = () => {
60
    reset()
60
    reset();
Línea 61... Línea 61...
61
    onClose()
61
    onClose();
Línea 62... Línea 62...
62
  }
62
  };
63
 
63
 
64
  const onSubmitHandler = handleSubmit((data) => onConfirm(data))
64
  const onSubmitHandler = handleSubmit((data) => onConfirm(data));
65
 
65
 
66
  useEffect(() => {
66
  useEffect(() => {
Línea 67... Línea 67...
67
    register('formatted_address', { required: 'Este campo es requerido' })
67
    register('formatted_address', { required: 'Este campo es requerido' });
68
    register('description', { required: 'Este campo es requerido' })
68
    register('description', { required: 'Este campo es requerido' });
69
    register('is_current')
-
 
70
  }, [])
69
    register('is_current');
71
 
-
 
72
  useEffect(() => {
70
  }, []);
73
    if (!currentEducation) return
71
 
Línea 74... Línea 72...
74
    const currentDegree = degrees.find(
72
  useEffect(() => {
75
      ({ name }) => name === currentEducation.degree
73
    if (!currentEducation) return;
76
    )
74
    const currentDegree = degrees.find(({ name }) => name === currentEducation.degree);
77
    if (currentDegree) setValue('degree_id', currentDegree.value)
75
    if (currentDegree) setValue('degree_id', currentDegree.value);
Línea 115... Línea 113...
115
        onGetAddress={handleAddress}
113
        onGetAddress={handleAddress}
116
        error={errors.formatted_address?.message}
114
        error={errors.formatted_address?.message}
117
        placeholder='Ubicación'
115
        placeholder='Ubicación'
118
      />
116
      />
119
      {errors.formatted_address && (
117
      {errors.formatted_address && (
120
        <FormErrorFeedback>
-
 
121
          {errors.formatted_address.message}
118
        <FormErrorFeedback>{errors.formatted_address.message}</FormErrorFeedback>
122
        </FormErrorFeedback>
-
 
123
      )}
119
      )}
Línea 124... Línea 120...
124
 
120
 
125
      <Input
121
      <Input
126
        name='grade_or_percentage'
122
        name='grade_or_percentage'
Línea 136... Línea 132...
136
        control={control}
132
        control={control}
137
        label='Desde'
133
        label='Desde'
138
        placeholder={labels.from_year}
134
        placeholder={labels.from_year}
139
        rules={{ required: 'Este campo es requerido' }}
135
        rules={{ required: 'Este campo es requerido' }}
140
        error={errors.from_year?.message}
136
        error={errors.from_year?.message}
141
        options={getYears().map((year) => ({ name: year, value: year }))}
137
        options={getYears().map((year) => ({ label: year, value: year }))}
142
      />
138
      />
Línea 143... Línea 139...
143
 
139
 
144
      {!isCurrent && (
140
      {!isCurrent && (
145
        <Select
141
        <Select
146
          name='to_year'
142
          name='to_year'
147
          control={control}
143
          control={control}
148
          label='Hasta'
144
          label='Hasta'
149
          placeholder='Año hasta'
145
          placeholder='Año hasta'
150
          rules={{ required: 'Este campo es requerido' }}
146
          rules={{ required: 'Este campo es requerido' }}
151
          error={errors.to_year?.message}
147
          error={errors.to_year?.message}
152
          options={getYears().map((year) => ({ name: year, value: year }))}
148
          options={getYears().map((year) => ({ label: year, value: year }))}
153
        />
149
        />
Línea 154... Línea 150...
154
      )}
150
      )}
155
 
151
 
Línea 166... Línea 162...
166
        name='description'
162
        name='description'
167
        rules={{ required: 'Este campo es requerido' }}
163
        rules={{ required: 'Este campo es requerido' }}
168
        error={errors.description?.message}
164
        error={errors.description?.message}
169
      />
165
      />
170
    </Modal>
166
    </Modal>
171
  )
167
  );
172
}
168
};
Línea 173... Línea 169...
173
 
169