Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3047 Rev 3694
Línea 1... Línea 1...
1
import React, { useState, useEffect } from 'react'
1
import React, { useState, useEffect } from 'react';
2
import { useDispatch, useSelector } from 'react-redux'
2
import { useDispatch, useSelector } from 'react-redux';
3
import { IconButton, Typography } from '@mui/material'
3
import { IconButton, Typography } from '@mui/material';
4
import { Edit } from '@mui/icons-material'
4
import Edit from '@mui/icons-material/Edit';
5
 
5
 
6
import { axios } from '@utils'
6
import { axios } from '@utils';
7
import { addNotification } from '@store/notification/notification.actions'
7
import { addNotification } from '@store/notification/notification.actions';
8
 
8
 
9
import Widget from '@components/UI/Widget'
9
import Widget from '@components/UI/Widget';
10
import LocationModal from './LocationModal'
10
import LocationModal from './LocationModal';
11
 
11
 
12
const LocationCard = ({
-
 
13
  address: defaultAddress = '',
12
const LocationCard = ({ address: defaultAddress = '', uuid = '', edit = false }) => {
14
  uuid = '',
-
 
15
  edit = false
-
 
16
}) => {
-
 
17
  const [address, setAddress] = useState('')
13
  const [address, setAddress] = useState('');
18
  const [showModal, setShowModal] = useState(false)
14
  const [showModal, setShowModal] = useState(false);
19
  const labels = useSelector(({ intl }) => intl.labels)
15
  const labels = useSelector(({ intl }) => intl.labels);
20
  const dispatch = useDispatch()
16
  const dispatch = useDispatch();
Línea 21... Línea 17...
21
 
17
 
Línea 22... Línea 18...
22
  const toggleModal = () => setShowModal(!showModal)
18
  const toggleModal = () => setShowModal(!showModal);
23
 
19
 
24
  const handleEditLocation = (data) => {
20
  const handleEditLocation = (data) => {
Línea 25... Línea 21...
25
    const formData = new FormData()
21
    const formData = new FormData();
26
    Object.entries(data).map(([key, value]) => formData.append(key, value))
22
    Object.entries(data).map(([key, value]) => formData.append(key, value));
27
 
23
 
28
    axios
24
    axios
Línea 29... Línea 25...
29
      .post(`/profile/my-profiles/location/${uuid}`, formData)
25
      .post(`/profile/my-profiles/location/${uuid}`, formData)
30
      .then((response) => {
26
      .then((response) => {
31
        const { data, success } = response.data
27
        const { data, success } = response.data;
32
 
28
 
33
        if (!success) {
29
        if (!success) {
34
          const resError =
30
          const resError =
35
            typeof data === 'string'
31
            typeof data === 'string'
Línea 36... Línea 32...
36
              ? data
32
              ? data
37
              : Object.entries(data)
33
              : Object.entries(data)
Línea 38... Línea 34...
38
                  .map(([key, value]) => `${key}: ${value}`)
34
                  .map(([key, value]) => `${key}: ${value}`)
39
                  .join(', ')
35
                  .join(', ');
40
 
36
 
41
          throw new Error(resError)
37
          throw new Error(resError);
42
        }
38
        }
43
 
39
 
44
        setAddress(data.formatted_address)
40
        setAddress(data.formatted_address);
Línea 45... Línea 41...
45
        toggleModal()
41
        toggleModal();
46
      })
42
      })
47
      .catch((error) => {
43
      .catch((error) => {
Línea 48... Línea 44...
48
        dispatch(addNotification({ style: 'danger', msg: error.message }))
44
        dispatch(addNotification({ style: 'danger', msg: error.message }));
49
      })
45
      });
50
  }
46
  };
51
 
47
 
52
  useEffect(() => {
48
  useEffect(() => {
53
    setAddress(defaultAddress)
49
    setAddress(defaultAddress);
54
  }, [defaultAddress])
50
  }, [defaultAddress]);
55
 
51
 
56
  return (
52
  return (
57
    <>
53
    <>
58
      <Widget>
54
      <Widget>
59
        <Widget.Header
55
        <Widget.Header
60
          title={labels.location}
56
          title={labels.location}
61
          renderAction={() => {
57
          renderAction={() => {
Línea 62... Línea 58...
62
            if (!edit) return
58
            if (!edit) return;
63
            return (
59
            return (
64
              <IconButton onClick={toggleModal}>
60
              <IconButton onClick={toggleModal}>
65
                <Edit />
61
                <Edit />
Línea 66... Línea -...
66
              </IconButton>
-
 
67
            )
-
 
68
          }}
-
 
69
        />
62
              </IconButton>
70
 
-
 
71
        <Widget.Body>
63
            );
72
          <Typography variant='body1'>{address}</Typography>
64
          }}
73
        </Widget.Body>
65
        />
Línea 74... Línea 66...
74
      </Widget>
66