Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1645 Rev 1646
Línea 3... Línea 3...
3
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
Línea 4... Línea 4...
4
 
4
 
5
import { sendReport } from '@app/services/reports'
5
import { sendReport } from '@app/services/reports'
6
import { addNotification } from '@app/redux/notification/notification.actions'
6
import { addNotification } from '@app/redux/notification/notification.actions'
-
 
7
import { closeReportModal } from '@app/redux/report/report.actions'
Línea 7... Línea -...
7
import { closeReportModal } from '@app/redux/report/report.actions'
-
 
8
 
-
 
9
import Form from '../UI/form/Form'
-
 
10
import FormInputText from '../UI/form/FormInputText'
8
import { block_options, reasons } from '@app/constants/report'
11
import SelectInput from '../UI/form/SelectField'
-
 
12
import Modal from '../UI/modal/Modal'
-
 
13
 
-
 
14
const reasons = [
9
 
15
  {
-
 
16
    name: 'Contenido sexual',
-
 
17
    value: 's'
-
 
18
  },
10
import Modal from '../UI/modal/Modal'
19
  {
-
 
20
    name: 'Contenido ofensivo',
-
 
21
    value: 'o'
-
 
22
  },
-
 
23
  {
-
 
24
    name: 'Discriminación',
-
 
25
    value: 'd'
-
 
26
  },
-
 
27
  {
-
 
28
    name: 'Adicciones',
-
 
29
    value: 'a'
-
 
30
  },
-
 
31
  {
-
 
32
    name: 'Terrorismo',
-
 
33
    value: 't'
-
 
34
  },
-
 
35
  {
-
 
36
    name: 'Otro',
-
 
37
    value: 'ot'
-
 
38
  }
-
 
39
]
-
 
40
 
-
 
41
const block_options = [
-
 
42
  {
-
 
43
    name: 'Sí',
-
 
44
    value: 'y'
-
 
45
  },
-
 
46
  {
-
 
47
    name: 'No',
-
 
48
    value: 'n'
-
 
Línea 49... Línea 11...
49
  }
11
import SelectInput from '../UI/form/SelectField'
50
]
12
import FormInputText from '../UI/form/FormInputText'
51
 
13
 
52
export default function ReportModal() {
14
export default function ReportModal() {
53
  const { showModal, type, reportUrl, onComplete } = useSelector(
15
  const { showModal, type, reportUrl, onComplete } = useSelector(
Línea 54... Línea 16...
54
    (state) => state.report
16
    (state) => state.report
Línea 55... Línea 17...
55
  )
17
  )
56
  const dispatch = useDispatch()
18
  const dispatch = useDispatch()
-
 
19
 
57
 
20
  const { control, errors, getValues } = useForm()
Línea 58... Línea 21...
58
  const { control, errors, handleSubmit } = useForm()
21
 
59
 
22
  const onSubmit = async () => {
60
  const onSubmit = handleSubmit(async (formData) => {
23
    try {
Línea 69... Línea 32...
69
      dispatch(addNotification({ style: 'success', msg: data }))
32
      dispatch(addNotification({ style: 'success', msg: data }))
70
      dispatch(closeReportModal())
33
      dispatch(closeReportModal())
71
    } catch (error) {
34
    } catch (error) {
72
      dispatch(addNotification({ style: 'danger', msg: error.message }))
35
      dispatch(addNotification({ style: 'danger', msg: error.message }))
73
    }
36
    }
74
  })
37
  }
Línea 75... Línea 38...
75
 
38
 
Línea 76... Línea 39...
76
  const closeModal = () => dispatch(closeReportModal())
39
  const closeModal = () => dispatch(closeReportModal())
77
 
40
 
78
  return (
41
  return (
79
    <Modal
42
    <Modal
80
      show={showModal}
43
      show={showModal}
-
 
44
      onClose={closeModal}
81
      onClose={closeModal}
45
      title={`Reportar ${type.toLowerCase()}`}
82
      title={`Reportar ${type.toLowerCase()}`}
-
 
83
    >
46
      onAccept={onSubmit}
84
      <Form onSubmit={onSubmit} autoComplete='off'>
47
    >
85
        <SelectInput
48
      <SelectInput
86
          id='reason'
49
        id='reason'
87
          name='reason'
50
        name='reason'
88
          label='Motivo'
51
        label='Motivo'
89
          options={reasons}
52
        options={reasons}
90
          control={control}
53
        control={control}
91
          error={errors.reason?.message}
54
        error={errors.reason?.message}
92
          rules={{ required: true }}
55
        rules={{ required: true }}
93
        />
56
      />
94
 
57
 
95
        <SelectInput
58
      <SelectInput
96
          id='block_user'
59
        id='block_user'
97
          name='block_user'
60
        name='block_user'
98
          label='Bloquear a este usuario'
61
        label='Bloquear a este usuario'
99
          options={block_options}
62
        options={block_options}
100
          control={control}
63
        control={control}
101
          error={errors.block_user?.message}
64
        error={errors.block_user?.message}
102
          rules={{ required: true }}
65
        rules={{ required: true }}
103
        />
66
      />
104
 
67
 
105
        <FormInputText
68
      <FormInputText
106
          name='comment'
69
        name='comment'
107
          control={control}
70
        control={control}
-
 
71
        rules={{ required: false }}
108
          rules={{ required: false }}
72
        label='Comentario'
109
        />
73
        placeholder='(Opcional)'
110
      </Form>
74
      />
111
    </Modal>
75
    </Modal>