Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15214 Rev 15215
Línea 58... Línea 58...
58
 
58
 
Línea 59... Línea 59...
59
	const closeModal = () => dispatch(closeShareModal())
59
	const closeModal = () => dispatch(closeShareModal())
Línea 60... Línea 60...
60
 
60
 
61
	useEffect(() => clearErrors(), [isOpen])
61
	useEffect(() => clearErrors(), [isOpen])
62
 
62
 
-
 
63
	const onSubmit = (data) => {
63
	const onSubmit = (data, e) => {
64
		setLoading(true)
64
		setLoading(true)
65
		const currentFormData = new FormData()
65
		const currentFormData = new FormData()
-
 
Línea 66... Línea 66...
66
		for (let input in data) {
66
 
67
			currentFormData.append(input, data[input])
67
		Object.entries(data)
68
		}
68
			.map(([entry, value]) => currentFormData.append(entry, value))
69
 
69
 
-
 
70
		axios.post(postUrl, currentFormData)
-
 
71
			.then(({ data }) => {
-
 
72
				const newFeed = data.data
-
 
73
				if (!data.success) {
-
 
74
					typeof data.data === 'string'
-
 
75
						? dispatch(addNotification({
-
 
76
							style: 'danger',
-
 
77
							msg: data.data
-
 
78
						}))
-
 
79
						: Object.entries(data.data).map(([key, value]) =>
-
 
80
							value.map(err =>
-
 
81
								dispatch(addNotification({
70
		axios.post(postUrl, currentFormData)
82
									style: 'danger',
71
			.then(({ data }) => {
-
 
72
				const newFeed = data.data
-
 
73
				if (data.success) {
-
 
74
					setLoading(false)
-
 
75
					e.target.reset()
83
									msg: `${key}: ${err}`
76
					setValue('description', '')
-
 
77
					setValue('file', '')
-
 
78
					clearErrors()
-
 
79
					closeModal()
-
 
80
					dispatch(addNotification({
-
 
81
						style: 'success',
-
 
82
						msg: 'La publicación ha sido compartida',
-
 
83
					}))
-
 
84
 
-
 
85
					if (currentPage && timelineUrl) {
-
 
86
						dispatch(fetchFeeds(timelineUrl, currentPage))
-
 
87
					}
-
 
88
 
-
 
89
					if (feedSharedId) {
-
 
90
						return dispatch(addFeed(newFeed, feedSharedId))
84
								}))
91
					}
-
 
92
 
-
 
93
					return dispatch(addFeed(newFeed))
-
 
94
				}
-
 
95
				typeof data.data === 'string'
-
 
96
					?
-
 
97
					dispatch(addNotification({
-
 
98
						style: 'danger',
-
 
99
						msg: data.data
-
 
100
					}))
-
 
101
					: Object.entries(data.data).map(([key, value]) =>
-
 
102
						value.map(err =>
-
 
103
							dispatch(addNotification({
-
 
104
								style: 'danger',
-
 
105
								msg: `${key}: ${err}`
85
							))
-
 
86
					setLoading(false)
-
 
87
					closeModal()
-
 
88
				}
106
							}))
89
				setLoading(false)
-
 
90
				setValue('description', '')
-
 
91
				setValue('file', '')
-
 
92
				clearErrors()
-
 
93
				closeModal()
-
 
94
				dispatch(addNotification({
-
 
95
					style: 'success',
-
 
96
					msg: 'La publicación ha sido compartida',
-
 
97
				}))
-
 
98
 
-
 
99
				if (currentPage && timelineUrl) {
-
 
100
					dispatch(fetchFeeds(timelineUrl, currentPage))
-
 
101
				}
-
 
102
 
-
 
103
				if (feedSharedId) {
-
 
104
					return dispatch(addFeed(newFeed, feedSharedId))
107
						)
105
				}
108
					)
106
 
Línea 109... Línea 107...
109
				setLoading(false)
107
				return dispatch(addFeed(newFeed))
110
				closeModal()
108
 
Línea 118... Línea 116...
118
 
116
 
119
	return (
117
	return (
120
		<Modal
118
		<Modal
121
			show={isOpen}
119
			show={isOpen}
122
			onHide={closeModal}
120
			onHide={closeModal}
123
			autoFocus={false}
-
 
124
		>
121
			autoFocus={false}>
125
			<form encType="multipart/form-data" onSubmit={handleSubmit(onSubmit)}>
122
			<form onSubmit={handleSubmit(onSubmit)}>
126
				<Modal.Header closeButton>
123
				<Modal.Header closeButton>
127
					<Modal.Title>Compartir una publicación</Modal.Title>
124
					<Modal.Title>Compartir una publicación</Modal.Title>
128
				</Modal.Header>
125
				</Modal.Header>
129
				<Modal.Body>
126
				<Modal.Body>
Línea 148... Línea 145...
148
							{errors.file && <p>{errors.file.message}</p>}
145
							{errors.file && <p>{errors.file.message}</p>}
149
						</>
146
						</>
150
					}
147
					}
151
				</Modal.Body>
148
				</Modal.Body>
152
				<Modal.Footer>
149
				<Modal.Footer>
-
 
150
					<button
153
					<button className='btn btn-sm btn-primary' disabled={loading}>
151
						className='btn btn-sm btn-primary'
-
 
152
						disabled={loading}
-
 
153
						type='submit'>
154
						Enviar
154
						Enviar
155
					</button>
155
					</button>
-
 
156
					<button
156
					<button className='btn btn-sm btn-tertiary' onClick={closeModal} disabled={loading} >
157
						className='btn btn-sm btn-tertiary'
-
 
158
						disabled={loading}
-
 
159
						onClick={closeModal}>
157
						Cancelar
160
						Cancelar
158
					</button>
161
					</button>
159
				</Modal.Footer>
162
				</Modal.Footer>
160
			</form>
163
			</form>
161
		</Modal>
164
		</Modal>