Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15062 Rev 16794
Línea 1... Línea -...
1
/* eslint-disable no-mixed-spaces-and-tabs */
-
 
2
import React, { useState } from 'react'
1
import React, { useState } from 'react'
3
import LocationModal from './LocationModal'
2
import LocationModal from './LocationModal'
4
import DeleteModal from '../../../shared/DeleteModal'
3
import DeleteModal from '../../../shared/DeleteModal'
Línea 5... Línea 4...
5
 
4
 
6
const Location = ({ locations = [], googleApiKey, locationsAddUrl, title }) => {
-
 
7
 
5
const Location = ({ locations = [], googleApiKey, locationsAddUrl, title }) => {
8
	const [actionUrl, setActionUrl] = useState(locationsAddUrl)
6
  const [actionUrl, setActionUrl] = useState(locationsAddUrl)
9
	const [defaultData, setDefaultData] = useState('')
7
  const [defaultData, setDefaultData] = useState('')
10
	const [showModal, setShowModal] = useState(false)
8
  const [showModal, setShowModal] = useState(false)
11
	const [showDeleteModal, setShowDeleteModal] = useState(false)
9
  const [showDeleteModal, setShowDeleteModal] = useState(false)
12
	const [deleteLink, setDeleteLink] = useState('')
10
  const [deleteLink, setDeleteLink] = useState('')
13
	const [removeElement, setRemoveElement] = useState('')
11
  const [removeElement, setRemoveElement] = useState('')
14
	const [locationState, setLocationState] = useState(locations)
12
  const [locationState, setLocationState] = useState(locations)
15
 
13
 
16
	const addLocation = (url) => {
14
  const closeModal = () => {
-
 
15
    setShowModal(false)
-
 
16
  }
-
 
17
 
17
		setShowModal(true)
18
  const closeDeleteModal = () => {
18
		setActionUrl(url)
19
    setShowDeleteModal(false)
19
	}
20
  }
20
 
21
 
21
	const editLocation = (url, item) => {
22
  const addLocation = (url) => {
22
		setShowModal(true)
23
    setShowModal(true)
23
		setActionUrl(url)
-
 
24
		setDefaultData(item)
24
    setActionUrl(url)
25
	}
25
  }
26
 
26
 
27
	const closeModal = () => setShowModal(false)
27
  const editLocation = (url, item) => {
-
 
28
    setShowModal(true)
-
 
29
    setActionUrl(url)
-
 
30
    setDefaultData(item)
28
	const closeDeleteModal = () => setShowDeleteModal(false)
31
  }
29
 
32
 
30
	const deleteLocation = ({ url, address }) => {
33
  const deleteLocation = ({ url, address }) => {
31
		setShowDeleteModal(true)
34
    setShowDeleteModal(true)
32
		setDeleteLink(url)
35
    setDeleteLink(url)
33
		setRemoveElement(address)
36
    setRemoveElement(address)
34
	}
37
  }
35
 
38
 
36
	return (
39
  return (
37
		<>
40
    <>
38
			<div className="user-profile-extended-ov st2">
41
      <div className="user-profile-extended-ov st2">
39
				<h3>
42
        <h3>
40
					{title}
43
          {title}
41
					<button
44
          <button
42
						className="btn btn-location-add"
45
            className="btn btn-location-add"
43
						onClick={() => addLocation(locationsAddUrl)}
46
            onClick={() => addLocation(locationsAddUrl)}
44
					>
47
          >
45
						<i className="fa fa-plus-square" />
48
            <i className="fa fa-plus-square" />
46
					</button>
49
          </button>
47
				</h3>
50
        </h3>
48
				<span id="locations-records">
-
 
49
					{
51
        <span id="locations-records">
50
						locationState.map((location, index) => (
52
          {locationState.map((location, index) => (
51
							<>
53
            <>
52
								<p key={index}>
54
              <p key={index}>
53
									{location.formatted_address}
55
                {location.formatted_address}
54
									{location.is_main === 'y' ? ' (Principal)' : ''}
56
                {location.is_main === 'y' ? ' (Principal)' : '(Secundaria)'}
55
									<button
57
                <button
56
										onClick={() => editLocation(location.link_edit, location)}
58
                  onClick={() => editLocation(location.link_edit, location)}
57
										className="btn btn-location-edit"
59
                  className="btn btn-location-edit"
58
										style={{ padding: '.3rem' }}
60
                  style={{ padding: '.3rem' }}
59
									>
61
                >
60
										<i className="fa fa-pencil" />
62
                  <i className="fa fa-pencil" />
61
									</button>
63
                </button>
-
 
64
                <button
-
 
65
                  onClick={() =>
-
 
66
                    deleteLocation({
62
									<button
67
                      url: location.link_delete,
-
 
68
                      address: location.formatted_address
-
 
69
                    })
63
										onClick={() => deleteLocation({ url: location.link_delete, address: location.formatted_address })}
70
                  }
64
										className="btn btn-location-delete"
71
                  className="btn btn-location-delete"
65
										style={{ padding: '.3rem' }}
72
                  style={{ padding: '.3rem' }}
66
									>
73
                >
67
										<i className="fa fa-trash" />
74
                  <i className="fa fa-trash" />
68
									</button>
75
                </button>
69
								</p>
-
 
70
								{
76
              </p>
71
									locations[index + 1] && <hr />
-
 
72
								}
77
              {locations[index + 1] && <hr />}
73
							</>
78
            </>
74
						))
-
 
75
					}
79
          ))}
76
				</span>
80
        </span>
77
			</div >
-
 
78
			{
-
 
79
				showModal
81
      </div>
80
                &&
82
      {showModal && (
81
                <LocationModal
83
        <LocationModal
82
                	closeModal={closeModal}
84
          closeModal={closeModal}
83
                	onComplete={setLocationState}
85
          onComplete={setLocationState}
84
                	dataLink={actionUrl}
86
          dataLink={actionUrl}
85
                	googleApiKey={googleApiKey}
87
          googleApiKey={googleApiKey}
86
                	defaultData={defaultData}
88
          defaultData={defaultData}
87
                />
89
        />
88
			}
-
 
89
			{
90
      )}
90
				showDeleteModal
-
 
91
                &&
91
      {showDeleteModal && (
92
                <DeleteModal
92
        <DeleteModal
93
                	url={deleteLink}
93
          url={deleteLink}
94
                	isOpen={showDeleteModal}
94
          isOpen={showDeleteModal}
95
                	closeModal={closeDeleteModal}
95
          closeModal={closeDeleteModal}
-
 
96
          title={'Esta seguro de eliminar esta ubicación?'}
-
 
97
          onComplete={() =>
-
 
98
            setLocationState(
96
                	title={'Esta seguro de eliminar esta ubicación?'}
99
              locationState.filter(
-
 
100
                (val) => val.formatted_address !== removeElement
-
 
101
              )
-
 
102
            )
97
                	onComplete={() => setLocationState(locationState.filter(val => val.formatted_address !== removeElement))}
103
          }
98
                	message={'Ubicación eliminada'}
104
          message={'Ubicación eliminada'}
99
                />
105
        />
100
			}
106
      )}
101
		</>
107
    </>
102
	)
108
  )
Línea 103... Línea -...
103
}
-
 
104
 
109
}
-
 
110