Proyectos de Subversion LeadersLinked - Backend

Rev

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

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