Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3432 Rev 3692
Línea 1... Línea 1...
1
import React from "react";
1
import React from 'react';
2
import { useDispatch, useSelector } from "react-redux";
2
import { useDispatch, useSelector } 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';
12
 
12
 
13
const AddCompanyModal = ({
-
 
14
  show = false,
-
 
15
  onHide = () => null,
-
 
16
  fetchCompanies = () => [],
13
const AddCompanyModal = ({ show = false, onHide = () => null, fetchCompanies = () => [] }) => {
17
}) => {
-
 
18
  const { data: companySizes } = useFetchHelper("company-sizes");
14
  const { data: companySizes } = useFetchHelper('company-sizes');
19
  const { data: industries } = useFetchHelper("industries");
15
  const { data: industries } = useFetchHelper('industries');
20
  const labels = useSelector(({ intl }) => intl.labels);
16
  const labels = useSelector(({ intl }) => intl.labels);
21
  const dispatch = useDispatch();
17
  const dispatch = useDispatch();
Línea 22... Línea 18...
22
 
18
 
23
  const {
19
  const {
24
    control,
20
    control,
25
    handleSubmit,
21
    handleSubmit,
26
    formState: { errors },
22
    formState: { errors }
Línea 27... Línea 23...
27
  } = useForm();
23
  } = useForm();
28
 
24
 
29
  const onSubmit = handleSubmit((data) => {
25
  const onSubmit = handleSubmit((data) => {
Línea 30... Línea 26...
30
    const formData = new FormData();
26
    const formData = new FormData();
31
    Object.entries(data).map(([key, value]) => formData.append(key, value));
27
    Object.entries(data).map(([key, value]) => formData.append(key, value));
32
 
28
 
33
    axios
29
    axios
34
      .post("/company/my-companies/add", formData)
30
      .post('/company/my-companies/add', formData)
35
      .then((response) => {
31
      .then((response) => {
36
        const { success, data } = response.data;
32
        const { success, data } = response.data;
37
        if (!success) {
33
        if (!success) {
38
          const errorMessage =
-
 
39
            typeof data === "string"
34
          const errorMessage =
40
              ? data
-
 
Línea 41... Línea 35...
41
              : Object.entries(data).map(
35
            typeof data === 'string'
42
                  ([key, value]) => `${key}: ${value[0]}`
36
              ? data
43
                );
37
              : Object.entries(data).map(([key, value]) => `${key}: ${value[0]}`);
Línea 44... Línea 38...
44
 
38
 
45
          dispatch(addNotification({ style: "danger", msg: errorMessage }));
39
          dispatch(addNotification({ style: 'danger', msg: errorMessage }));
46
          return;
40
          return;
47
        }
41
        }
48
 
42
 
49
        fetchCompanies();
43
        fetchCompanies();
50
        onHide();
44
        onHide();
Línea 51... Línea 45...
51
      })
45
      })
52
      .catch((err) => {
-
 
53
        dispatch(addNotification({ style: "danger", msg: err.message }));
46
      .catch((err) => {
54
      });
-
 
55
  });
-
 
56
 
-
 
57
  return (
-
 
58
    <Modal
47
        dispatch(addNotification({ style: 'danger', msg: err.message }));
59
      title={labels.new_company}
48
      });
60
      show={show}
49
  });
61
      onClose={onHide}
50
 
62
      onAccept={onSubmit}
51
  return (
63
    >
52
    <Modal title={labels.new_company} show={show} onClose={onHide} onAccept={onSubmit}>
64
      <Input
53
      <Input
Línea 65... Línea 54...
65
        name="name"
54
        name='name'
66
        placeholder={labels.name_of_company}
55
        placeholder={labels.name_of_company}
67
        error={errors.name?.message}
56
        error={errors.name?.message}
68
        control={control}
57
        control={control}
69
        rules={{ required: "Por favor ingrese el nombre de la Empresa" }}
58
        rules={{ required: 'Por favor ingrese el nombre de la Empresa' }}
70
      />
59
      />
71
 
60
 
Línea 72... Línea 61...
72
      <Select
61
      <Select
73
        name="industry_id"
62
        name='industry_id'
74
        options={industries}
63
        options={industries}
75
        control={control}
64
        control={control}
76
        rules={{ required: labels.select_industry }}
65
        rules={{ required: labels.select_industry }}
77
        error={errors.industry_id?.message}
66
        error={errors.industry_id?.message}
78
      />
67
      />