Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2858 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2858 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";
4
 
4
 
5
import { axios } from '@app/utils'
5
import { axios } from "@app/utils";
6
import { useFetchHelper } from '@hooks'
6
import { useFetchHelper } from "@hooks";
7
import { addNotification } from '@app/redux/notification/notification.actions'
7
import { addNotification } from "@app/redux/notification/notification.actions";
8
 
8
 
9
import Modal from '@components/UI/modal/Modal'
9
import Modal from "@components/UI/modal/Modal";
10
import Input from '@components/UI/inputs/Input'
10
import Input from "@components/UI/inputs/Input";
11
import Select from '@components/UI/inputs/Select'
11
import Select from "@components/UI/inputs/Select";
Línea 12... Línea 12...
12
 
12
 
13
const AddGroupModal = ({ show, onHide, fetchGroups }) => {
13
const AddGroupModal = ({ show, onHide, fetchGroups }) => {
14
  const { data: groupTypes } = useFetchHelper('group-types')
14
  const { data: groupTypes } = useFetchHelper("group-types");
15
  const { data: industries } = useFetchHelper('industries')
15
  const { data: industries } = useFetchHelper("industries");
Línea 16... Línea 16...
16
  const dispatch = useDispatch()
16
  const dispatch = useDispatch();
17
 
17
 
18
  const {
18
  const {
19
    control,
19
    control,
20
    handleSubmit,
20
    handleSubmit,
Línea 21... Línea 21...
21
    formState: { errors }
21
    formState: { errors },
22
  } = useForm()
22
  } = useForm();
23
 
23
 
Línea 24... Línea 24...
24
  const onSubmit = handleSubmit((data) => {
24
  const onSubmit = handleSubmit((data) => {
25
    const formData = new FormData()
25
    const formData = new FormData();
26
    Object.entries(data).forEach(([key, value]) => formData.append(key, value))
26
    Object.entries(data).forEach(([key, value]) => formData.append(key, value));
27
 
27
 
-
 
28
    axios
28
    axios
29
      .post(`/group/my-groups/add`, formData)
29
      .post(`/group/my-groups/add`, formData)
30
      .then((response) => {
30
      .then(({ data: responseData }) => {
31
        const { success } = response.data;
31
        const { success } = responseData
32
 
32
        if (!success) throw new Error('Error al crear el grupo')
33
        if (!success) throw new Error("Error al crear el grupo");
33
        fetchGroups()
34
        fetchGroups();
34
        onHide()
35
        onHide();
35
      })
36
      })
Línea 36... Línea 37...
36
      .catch((err) => {
37
      .catch((err) => {
37
        dispatch(addNotification({ style: 'danger', msg: err.message }))
38
        dispatch(addNotification({ style: "danger", msg: err.message }));
38
      })
39
      });
39
  })
40
  });
40
 
41
 
41
  return (
42
  return (
42
    <Modal title='Nuevo Grupo' show={show} onClose={onHide} onAccept={onSubmit}>
43
    <Modal title="Nuevo Grupo" show={show} onClose={onHide} onAccept={onSubmit}>
43
      <Input
44
      <Input
44
        label='Nombre'
45
        label="Nombre"
45
        name='name'
46
        name="name"
Línea 46... Línea 47...
46
        placeholder='Nombre del grupo'
47
        placeholder="Nombre del grupo"
47
        control={control}
48
        control={control}
48
        rules={{ required: 'Este campo es requerido' }}
49
        rules={{ required: "Este campo es requerido" }}
49
        error={errors.name?.message}
50
        error={errors.name?.message}
50
      />
51
      />
51
 
52
 
52
      <Select
53
      <Select
53
        label='Industria'
54
        label="Industria"
Línea 54... Línea 55...
54
        name='type_id'
55
        name="type_id"
55
        control={control}
56
        control={control}
56
        rules={{ required: 'Por favor eliga un tipo' }}
57
        rules={{ required: "Por favor eliga un tipo" }}
57
        error={errors.type_id?.message}
58
        error={errors.type_id?.message}
58
        options={groupTypes}
59
        options={groupTypes}
59
      />
60
      />
60
 
61
 
61
      <Select
62
      <Select
62
        label='Tipo'
63
        label="Tipo"
63
        name='industry_id'
64
        name="industry_id"
64
        control={control}
65
        control={control}
Línea 65... Línea 66...
65
        rules={{ required: 'Por favor eliga un tipo' }}
66
        rules={{ required: "Por favor eliga un tipo" }}