Proyectos de Subversion LeadersLinked - SPA

Rev

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

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