Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2861 Rev 3432
Línea 1... Línea 1...
1
import React from 'react'
1
import React from "react";
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from "react-redux";
3
import { useForm } from 'react-hook-form'
3
import { useForm } from "react-hook-form";
Línea 4... Línea 4...
4
 
4
 
5
import { axios } from '@app/utils'
5
import { axios } from "@app/utils";
Línea 6... Línea 6...
6
import { addNotification } from '@app/redux/notification/notification.actions'
6
import { addNotification } from "@app/redux/notification/notification.actions";
7
 
7
 
Línea 8... Línea 8...
8
import Modal from '../UI/modal/Modal'
8
import Modal from "../UI/modal/Modal";
9
import Input from '../UI/inputs/Input'
9
import Input from "../UI/inputs/Input";
10
 
10
 
11
const CreateGroupModal = ({ isOpen, onClose }) => {
11
const CreateGroupModal = ({ isOpen, onClose }) => {
12
  const {
12
  const {
13
    control,
13
    control,
14
    handleSubmit,
14
    handleSubmit,
15
    formState: { errors }
15
    formState: { errors },
16
  } = useForm()
16
  } = useForm();
17
  const dispatch = useDispatch()
17
  const dispatch = useDispatch();
18
 
18
 
Línea 19... Línea 19...
19
  const onSubmitHandler = handleSubmit(async (data) => {
19
  const onSubmitHandler = handleSubmit(async (group) => {
20
    const formData = new FormData()
20
    const formData = new FormData();
21
    Object.entries(data).map(([key, value]) => formData.append(key, value))
21
    Object.entries(group).map(([key, value]) => formData.append(key, value));
22
 
22
 
Línea 23... Línea 23...
23
    axios
23
    axios
24
      .post('/chat/create-group', formData)
24
      .post("/chat/create-group", group)
25
      .then(({ data: response }) => {
25
      .then((response) => {
26
        const { success } = response
26
        const { success } = response.data;
27
 
27
 
28
        if (!success) {
28
        if (!success) {
29
          dispatch(
29
          dispatch(
30
            addNotification({
30
            addNotification({
31
              style: 'danger',
31
              style: "danger",
Línea 32... Línea 32...
32
              message: 'Ha ocurrido un error, por favor intente más tarde.'
32
              message: "Ha ocurrido un error, por favor intente más tarde.",
33
            })
33
            })
34
          )
34
          );
35
          return
35
          return;
36
        }
36
        }
37
 
37
 
Línea 38... Línea 38...
38
        onClose()
38
        onClose();
39
      })
39
      })
40
      .catch((err) => {
40
      .catch((err) => {
41
        dispatch(addNotification({ style: 'danger', message: err.message }))
41
        dispatch(addNotification({ style: "danger", message: err.message }));
42
      })
42
      });
43
  })
43
  });
44
 
44
 
45
  return (
45
  return (
46
    <Modal
46
    <Modal
47
      title='Crear grupo'
47
      title="Crear grupo"
48
      show={isOpen}
48
      show={isOpen}
49
      onClose={onClose}
49
      onClose={onClose}
50
      onReject={onClose}
50
      onReject={onClose}
51
      onAccept={onSubmitHandler}
51
      onAccept={onSubmitHandler}
52
    >
52
    >
53
      <Input
53
      <Input
54
        name='name'
54
        name="name"
55
        label='Nombre'
55
        label="Nombre"
56
        placeholder='Nombre del grupo'
56
        placeholder="Nombre del grupo"
Línea 57... Línea 57...
57
        control={control}
57
        control={control}