Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3577 stevensc 1
import React, { useEffect } from 'react'
2
import { useForm } from 'react-hook-form'
3
import { useDispatch } from 'react-redux'
4
 
5
import { useInmail } from '@hooks'
6
import { replyInmail } from '@app/services/inmail'
7
import { addNotification } from '@app/redux/notification/notification.actions'
8
 
9
import Modal from '@components/UI/modal/Modal'
10
import Input from '@components/UI/inputs/Input'
11
import Ckeditor from '@components/common/ckeditor/Ckeditor'
12
 
13
export default function ReplyModal() {
14
  const { replyModalShow, closeReply, selectedMessage } = useInmail()
15
  const dispatch = useDispatch()
16
 
17
  const {
18
    setValue,
19
    handleSubmit,
20
    register,
21
    reset,
22
    formState: { isSubmitting, errors }
23
  } = useForm({
24
    defaultValues: {
25
      body: '',
26
      subject: '',
27
      filename: ''
28
    }
29
  })
30
 
31
  const onSend = handleSubmit(async (message) => {
32
    try {
33
      const result = await replyInmail(selectedMessage?.send_link, message)
34
      dispatch(addNotification({ style: 'success', msg: result }))
35
      closeReply()
36
      reset()
37
    } catch (error) {
38
      dispatch(addNotification({ style: 'danger', msg: error.message }))
39
    }
40
  })
41
 
42
  useEffect(() => {
43
    const requiredErrorMsg = 'Este campo es requerido'
44
    register('body', { required: requiredErrorMsg })
45
    register('subject', { required: requiredErrorMsg })
46
    register('filename')
47
  }, [replyModalShow])
48
 
49
  return (
50
    <Modal
51
      show={replyModalShow}
52
      title={`Respuesta a ${selectedMessage?.name}`}
53
      onAccept={onSend}
54
      loading={isSubmitting}
55
      onClose={closeReply}
56
    >
57
      <Input label='Para' value={selectedMessage?.name} disabled />
58
 
59
      <Input
60
        label='Asunto'
61
        onChange={(e) => setValue('subject', e.target.value)}
62
      />
63
 
64
      <Ckeditor onChange={(value) => setValue('body', value)} />
65
 
66
      <Input
67
        type='file'
68
        label='Adjunto'
69
        accept='image/*'
70
        onChange={(e) => setValue('filename', e.target.files[0])}
71
        error={errors.filename?.message}
72
      />
73
    </Modal>
74
  )
75
}