Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1639 | Ir a la última revisión | | Ultima modificación | Ver Log |

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