Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 11152 Rev 14738
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
2
import { useState } from 'react'
2
import { useState } from 'react'
3
import SearchLocationInput from '../../../shared/SearchLocationInput'
3
import SearchLocationInput from '../../../shared/SearchLocationInput'
4
import SubmitModal from '../../../jobs/components/Modals/SubmitModal'
4
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
5
import axios from 'axios'
-
 
6
import { useDispatch } from 'react-redux'
5
import { useForm } from 'react-hook-form'
7
import { Button, Modal } from 'react-bootstrap'
Línea 6... Línea 8...
6
 
8
 
7
const LocationModal = ({
9
const LocationModal = ({
8
	closeModal,
10
	closeModal,
9
	dataLink,
11
	dataLink,
10
	googleApiKey,
12
	googleApiKey,
-
 
13
	defaultData = '',
11
	defaultData = ''
14
	onComplete = function () { }
Línea 12... Línea 15...
12
}) => {
15
}) => {
13
 
16
 
14
	const [isActive, setIsActive] = useState((defaultData.is_main === 'y') ? true : false)
17
	const [isActive, setIsActive] = useState((defaultData.is_main === 'y') ? true : false)
-
 
18
	const [value, setValue] = useState(defaultData.formatted_address)
-
 
19
	const [data, setData] = useState({})
-
 
20
	const dispatch = useDispatch()
-
 
21
 
-
 
22
	const onSubmit = () => {
-
 
23
 
-
 
24
		const values = Object.values(data)
-
 
25
 
-
 
26
		if (!values.length) {
-
 
27
			return dispatch(addNotification({
-
 
28
				style: 'danger',
-
 
29
				msg: 'El campo no puede estar vacio.'
-
 
30
			}))
-
 
31
		}
-
 
32
 
-
 
33
		const formData = new FormData()
-
 
34
		Object.entries({ ...data, is_main: isActive ? 'y' : 'n' }).forEach((entries) => {
-
 
35
			formData.append(entries[0], entries[1])
-
 
36
		})
-
 
37
 
-
 
38
		axios.post(dataLink, formData)
-
 
39
			.then(({ data }) => {
-
 
40
				if (!data.success) {
-
 
41
					return dispatch(addNotification({
-
 
42
						style: 'danger',
-
 
43
						msg: typeof data.data === 'string'
-
 
44
							? data.data
-
 
45
							: 'Ha ocurrido un error'
-
 
46
					}))
-
 
47
				}
-
 
48
 
-
 
49
				onComplete(data.data)
-
 
50
				dispatch(addNotification({
-
 
51
					style: 'success',
-
 
52
					msg: 'Registro actualizado'
-
 
53
				}))
-
 
54
				closeModal()
-
 
55
			})
Línea 15... Línea 56...
15
	const [value, setValue] = useState(defaultData.formatted_address)
56
			.catch((err) => console.log(err))
16
	const [data, setData] = useState({})
-
 
17
 
57
	}
18
	return (
58
 
19
		<SubmitModal
59
	return (
20
			title='Ubicación'
60
		<Modal size="lg" show onHide={closeModal}>
21
			closeModal={closeModal}
61
			<Modal.Header closeButton>
-
 
62
				<Modal.Title>Ubicación</Modal.Title>
22
			submitData={{ ...data, is_main: isActive ? 'y' : 'n' }}
63
			</Modal.Header>
23
			postLink={dataLink}
64
			<Modal.Body>
24
		>
65
				<div className='form-group'>
25
			<SearchLocationInput
66
					<SearchLocationInput
26
				value={value}
67
						value={value}
27
				setValue={setValue}
68
						setValue={setValue}
28
				googleApiKey={googleApiKey}
69
						googleApiKey={googleApiKey}
29
				updateData={setData}
70
						updateData={setData}
30
			/>
71
					/>
31
			<div
72
					<div
32
				className={`toggle btn btn-primary ${!isActive && 'off'}`}
73
						className={`toggle btn btn-primary ${!isActive && 'off'}`}
33
				data-toggle="toggle"
74
						data-toggle="toggle"
34
				role="button"
75
						role="button"
35
				style={{ width: '130px' }}
76
						style={{ width: '130px' }}
36
				onClick={() => setIsActive(!isActive)}
77
						onClick={() => setIsActive(!isActive)}
37
			>
78
					>
38
				<input
79
						<input
39
					type="checkbox"
80
							type="checkbox"
40
					checked={isActive}
81
							checked={isActive}
41
				/>
82
						/>
42
				<div className="toggle-group">
83
						<div className="toggle-group">
-
 
84
							<label htmlFor="status" className="btn btn-primary toggle-on">Principal</label>
-
 
85
							<label htmlFor="status" className="btn btn-light toggle-off">Secundaria</label>
43
					<label htmlFor="status" className="btn btn-primary toggle-on">Principal</label>
86
							<span className="toggle-handle btn btn-light"></span>
-
 
87
						</div>
-
 
88
					</div>
-
 
89
				</div>
-
 
90
			</Modal.Body>
-
 
91
			<Modal.Footer>
-
 
92
				<Button
-
 
93
					variant="primary"
44
					<label htmlFor="status" className="btn btn-light toggle-off">Secundaria</label>
94
					onClick={onSubmit}
-
 
95
				>
-
 
96
					Enviar
-
 
97
				</Button>
-
 
98
				<Button variant="danger" onClick={closeModal}>
45
					<span className="toggle-handle btn btn-light"></span>
99
					Cancelar
46
				</div>
100
				</Button>
47
			</div>
101
			</Modal.Footer>
48
		</SubmitModal>
102
		</Modal >
49
	)
103
	)