Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 685 Rev 720
Línea 1... Línea 1...
1
import React, { useRef, useState } from "react";
1
import React, { useRef, useState } from 'react'
2
import { axios } from "../../utils";
2
import { axios } from '../../utils'
3
import { Avatar } from "@mui/material";
3
import { Avatar } from '@mui/material'
4
import { Link, useHistory } from "react-router-dom";
4
import { Link, useHistory } from 'react-router-dom'
5
import { addNotification } from "store/notification/notification.actions";
5
import { addNotification } from 'store/notification/notification.actions'
6
import { useDispatch, useSelector } from "react-redux";
6
import { useDispatch, useSelector } from 'react-redux'
7
import EditIcon from '@mui/icons-material/Edit'
7
import EditIcon from '@mui/icons-material/Edit'
8
import styled from "styled-components";
8
import styled from 'styled-components'
9
import Spinner from "../UI/Spinner";
9
import Spinner from '../UI/Spinner'
10
import StyledContainer from "../widgets/WidgetLayout";
10
import StyledContainer from '../widgets/WidgetLayout'
11
import ConfirmModal from "../modals/ConfirmModal";
11
import ConfirmModal from '../modals/ConfirmModal'
-
 
12
import {
-
 
13
  AccountCircleOutlined,
-
 
14
  CancelOutlined,
-
 
15
  ChatOutlined,
-
 
16
  DeleteOutline,
-
 
17
  Done,
-
 
18
  Edit,
-
 
19
  LockOpenOutlined,
-
 
20
  LockOutlined,
-
 
21
  LogoutOutlined,
-
 
22
  OpenInNew,
-
 
23
  PersonAddOutlined,
-
 
24
  PersonRemoveOutlined,
-
 
25
  Remove,
-
 
26
  SupervisorAccountOutlined
-
 
27
} from '@mui/icons-material'
Línea 12... Línea 28...
12
 
28
 
13
const StyledSpinnerContainer = styled.div`
29
const StyledSpinnerContainer = styled.div`
14
  position: absolute;
30
  position: absolute;
15
  left: 0;
31
  left: 0;
16
  top: 0;
32
  top: 0;
17
  width: 100%;
33
  width: 100%;
18
  height: 100%;
34
  height: 100%;
19
  background: rgba(255, 255, 255, 0.4);
35
  background: rgba(255, 255, 255, 0.4);
20
  place-items: center;
36
  place-items: center;
21
  z-index: 50;
37
  z-index: 50;
Línea 22... Línea 38...
22
`;
38
`
23
 
39
 
24
const StyledItemContainer = styled(StyledContainer)`
40
const StyledItemContainer = styled(StyledContainer)`
25
  display: flex;
41
  display: flex;
26
  flex-direction: column;
42
  flex-direction: column;
27
  justify-content: center;
43
  justify-content: center;
28
  height: 100%;
44
  height: 100%;
Línea 29... Línea 45...
29
  border-radius:5px;
45
  border-radius: 5px;
30
`;
46
`
31
 
47
 
32
const StyledHeader = styled.div`
48
const StyledHeader = styled.div`
33
  align-items: center;
49
  align-items: center;
34
  display: flex;
50
  display: flex;
35
  gap: 0.5rem;
51
  gap: 0.5rem;
36
  justify-content: flex-start;
-
 
37
  position: relative;
52
  justify-content: flex-start;
Línea 38... Línea 53...
38
  padding: 15px 5px;
53
  position: relative;
39
  
54
  padding: 15px 5px;
40
`;
55
`
41
 
56
 
42
const StyledContent = styled.div`
57
const StyledContent = styled.div`
43
  display: flex;
58
  display: flex;
44
  flex-direction: column;
59
  flex-direction: column;
45
  text-align: center;
60
  text-align: center;
46
  ul {
61
  ul {
47
    align-items: center;
62
    align-items: center;
Línea 48... Línea 63...
48
    display: flex;
63
    display: flex;
49
    justify-content: center;
64
    justify-content: center;
50
  }
65
  }
51
`;
66
`
Línea 52... Línea 67...
52
 
67
 
53
const StyledAvatar = styled(Avatar)`
68
const StyledAvatar = styled(Avatar)`
54
  height: 60px !important;
69
  height: 60px !important;
55
  width: 60px !important;  
70
  width: 60px !important;
Línea 76... Línea 91...
76
  link_unfollow,
91
  link_unfollow,
77
  link_approve,
92
  link_approve,
78
  link_leave,
93
  link_leave,
79
  link_admin,
94
  link_admin,
80
  link_impersonate,
95
  link_impersonate,
81
  btnAcceptTitle = "Ver",
96
  btnAcceptTitle = 'Ver',
82
  btnCancelTitle = "Borrar",
97
  btnCancelTitle = 'Borrar',
83
  btnEditTitle = "Editar",
98
  btnEditTitle = 'Editar',
84
  btnLeaveTitle = "Dejar",
99
  btnLeaveTitle = 'Dejar',
85
  isTopData,
100
  isTopData
86
}) => {
101
}) => {
87
  const [isShowConfirmation, setIsShowConfirmation] = useState(false);
102
  const [isShowConfirmation, setIsShowConfirmation] = useState(false)
88
  const [loading, setLoading] = useState(false);
103
  const [loading, setLoading] = useState(false)
89
  const confirmUrl = useRef("");
104
  const confirmUrl = useRef('')
90
  const labels = useSelector(({ intl }) => intl.labels);
105
  const labels = useSelector(({ intl }) => intl.labels)
91
  const dispatch = useDispatch();
106
  const dispatch = useDispatch()
92
  const history = useHistory();
107
  const history = useHistory()
93
 
108
 
94
  const showConfirm = (url = "") => {
109
  const showConfirm = (url = '') => {
95
    setIsShowConfirmation(true);
110
    setIsShowConfirmation(true)
96
    confirmUrl.current = url;
111
    confirmUrl.current = url
97
  };
112
  }
Línea 98... Línea 113...
98
 
113
 
99
  const closeConfirm = () => {
114
  const closeConfirm = () => {
100
    setIsShowConfirmation(false);
115
    setIsShowConfirmation(false)
101
    confirmUrl.current = "";
116
    confirmUrl.current = ''
Línea 102... Línea 117...
102
  };
117
  }
103
 
118
 
104
  const getImpersonateUrl = async (url = "") => {
119
  const getImpersonateUrl = async (url = '') => {
105
    try {
120
    try {
106
      const { data } = await axios.get(url);
121
      const { data } = await axios.get(url)
107
      if (data.success) window.location.href = data.data;
122
      if (data.success) window.location.href = data.data
108
    } catch (error) {
123
    } catch (error) {
109
      console.log(">>: error > ", error);
124
      console.log('>>: error > ', error)
Línea 110... Línea 125...
110
    }
125
    }
111
  };
126
  }
112
 
127
 
113
  const onConfirm = (url) => {
128
  const onConfirm = (url) => {
114
    setLoading(true);
129
    setLoading(true)
115
    axios
130
    axios
Línea 116... Línea 131...
116
      .post(url)
131
      .post(url)
117
      .then((response) => {
132
      .then((response) => {
118
        const { success, data } = response.data;
133
        const { success, data } = response.data
119
 
134
 
120
        if (!success) {
135
        if (!success) {
Línea 121... Línea 136...
121
          const errorMessage =
136
          const errorMessage =
122
            typeof data === "string"
137
            typeof data === 'string'
123
              ? data
138
              ? data
Línea 124... Línea 139...
124
              : "Error interno. Por favor, inténtelo de nuevo más tarde.";
139
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
125
 
140
 
126
          dispatch(addNotification({ style: "danger", msg: errorMessage }));
141
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
127
          return;
142
          return
128
        }
143
        }
129
 
144
 
130
        if (fetchCallback) fetchCallback();
145
        if (fetchCallback) fetchCallback()
131
        dispatch(addNotification({ style: "success", msg: data }));
146
        dispatch(addNotification({ style: 'success', msg: data }))
132
      })
147
      })
133
      .catch(() => {
148
      .catch(() => {
134
        dispatch(
149
        dispatch(
135
          addNotification({
150
          addNotification({
136
            style: "error",
151
            style: 'error',
137
            msg: "Error interno. Por favor, inténtelo de nuevo más tarde.",
152
            msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.'
138
          })
153
          })
139
        );
154
        )
Línea 140... Línea 155...
140
      })
155
      })
141
      .finally(() => {
156
      .finally(() => {
142
        confirmUrl.current = "";
157
        confirmUrl.current = ''
143
        setLoading(false);
158
        setLoading(false)
144
      });
159
      })
145
  };
160
  }
Línea 146... Línea 161...
146
 
161
 
147
  const handleUnfollow = (link_unfollow) => {
162
  const handleUnfollow = (link_unfollow) => {
148
    setLoading(true);
163
    setLoading(true)
149
    axios
164
    axios
150
      .post(link_unfollow)
165
      .post(link_unfollow)
Línea 151... Línea 166...
151
      .then((response) => {
166
      .then((response) => {
152
        const { data, success } = response.data;
167
        const { data, success } = response.data
153
 
168
 
Línea 154... Línea 169...
154
        if (!success) {
169
        if (!success) {
155
          const errorMessage =
170
          const errorMessage =
156
            typeof data === "string"
171
            typeof data === 'string'
157
              ? data
172
              ? data
158
              : "Error interno. Por favor, inténtelo de nuevo más tarde.";
173
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
Línea 159... Línea 174...
159
 
174
 
160
          dispatch(addNotification({ style: "danger", msg: errorMessage }));
175
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
161
          return;
176
          return
162
        }
177
        }
163
 
178
 
164
        if (fetchCallback) fetchCallback();
179
        if (fetchCallback) fetchCallback()
165
        dispatch(addNotification({ style: "success", msg: data }));
180
        dispatch(addNotification({ style: 'success', msg: data }))
166
      })
181
      })
Línea 167... Línea 182...
167
      .finally(() => setLoading(false));
182
      .finally(() => setLoading(false))
168
  };
183
  }
169
 
184
 
170
  const getManageUrl = async () => {
185
  const getManageUrl = async () => {
171
    try {
186
    try {
-
 
187
      const { data } = await axios.get(link_admin)
-
 
188
      if (data.success) window.open(data.data, '_backend')
-
 
189
    } catch (error) {
-
 
190
      console.log('>>: error > ', error)
-
 
191
    }
-
 
192
  }
-
 
193
 
-
 
194
  const linksOptions = [
-
 
195
    {
-
 
196
      label: btnAcceptTitle || labels.accept,
-
 
197
      url: link_view,
-
 
198
      color: 'primary',
-
 
199
      icon: OpenInNew
-
 
200
    },
-
 
201
    {
-
 
202
      label: btnEditTitle || labels.edit,
172
      const { data } = await axios.get(link_admin);
203
      url: link_edit,
173
      if (data.success) window.open(data.data, "_backend");
-
 
174
    } catch (error) {
-
 
175
      console.log(">>: error > ", error);
-
 
176
    }
-
 
177
  };
-
 
178
 
204
      color: 'secondary',
179
  const linksOptions = [
205
      icon: Edit
180
    {
206
    },
181
      label: btnAcceptTitle || labels.accept,
207
    { label: labels.approve, url: link_approve, color: 'tertiary', icon: Done },
-
 
208
    { label: btnLeaveTitle, url: link_remove, color: 'tertiary', icon: Remove },
182
      url: link_view,
209
    { label: labels.accept, url: link_accept, color: 'secondary', icon: Done },
183
      color: "primary",
210
    {
184
    },
211
      label: labels.reject,
185
    { label: btnEditTitle || labels.edit, url: link_edit, color: "secondary" },
212
      url: link_reject,
186
    { label: labels.approve, url: link_approve, color: "tertiary" },
213
      color: 'tertiary',
-
 
214
      icon: CancelOutlined
187
    { label: btnLeaveTitle, url: link_remove, color: "tertiary" },
215
    },
-
 
216
    {
188
    { label: labels.accept, url: link_accept, color: "secondary" },
217
      label: btnCancelTitle || labels.cancel,
-
 
218
      url: link_delete,
-
 
219
      color: 'tertiary',
-
 
220
      icon: DeleteOutline
-
 
221
    },
-
 
222
    {
189
    { label: labels.reject, url: link_reject, color: "tertiary" },
223
      label: labels.message || 'Mensaje',
-
 
224
      url: link_inmail,
-
 
225
      color: 'secondary',
-
 
226
      icon: ChatOutlined
-
 
227
    },
-
 
228
    {
190
    {
229
      label: labels.administrate,
-
 
230
      url: link_admin,
-
 
231
      color: 'secondary',
-
 
232
      icon: SupervisorAccountOutlined
-
 
233
    },
-
 
234
    {
191
      label: btnCancelTitle || labels.cancel,
235
      label: labels.unfollow,
-
 
236
      url: link_unfollow,
-
 
237
      color: 'tertiary',
-
 
238
      icon: PersonRemoveOutlined
-
 
239
    },
-
 
240
    {
192
      url: link_delete,
241
      label: labels.block,
-
 
242
      url: link_block,
-
 
243
      color: 'tertiary',
-
 
244
      icon: LockOutlined
-
 
245
    },
-
 
246
    {
193
      color: "tertiary",
247
      label: labels.unblock,
-
 
248
      url: link_unblock,
-
 
249
      color: 'tertiary',
-
 
250
      icon: LockOpenOutlined
-
 
251
    },
-
 
252
    {
194
    },
253
      label: labels.connect,
-
 
254
      url: link_request,
-
 
255
      color: 'tertiary',
-
 
256
      icon: PersonAddOutlined
-
 
257
    },
-
 
258
    {
-
 
259
      label: labels.cancel,
195
    {
260
      url: link_cancel,
-
 
261
      color: 'tertiary',
-
 
262
      icon: CancelOutlined
-
 
263
    },
196
      label: labels.message || "Mensaje",
264
    {
Línea 197... Línea 265...
197
      url: link_inmail,
265
      label: btnLeaveTitle,
198
      color: "secondary",
266
      url: link_leave,
199
    },
267
      color: 'tertiary',
200
    { label: labels.administrate, url: link_admin, color: "secondary" },
268
      icon: LogoutOutlined
Línea 222... Línea 290...
222
                {link_view && (
290
                {link_view && (
223
                  <li>
291
                  <li>
224
                    <Link
292
                    <Link
225
                      to={link_view}
293
                      to={link_view}
226
                      data-link={link_view}
294
                      data-link={link_view}
227
                      className="btn btn-primary"
295
                      className='btn btn-primary'
228
                    >
296
                    >
229
                       <EditIcon />
297
                      <EditIcon />
230
                      {btnAcceptTitle}
298
                      {btnAcceptTitle}
231
                    </Link>
299
                    </Link>
232
                  </li>
300
                  </li>
233
                )}
301
                )}
234
                {link_inmail && (
302
                {link_inmail && (
235
                  <li>
303
                  <li>
236
                    <Link
304
                    <Link
237
                      to={link_inmail}
305
                      to={link_inmail}
238
                      data-link={link_inmail}
306
                      data-link={link_inmail}
239
                      className="btn btn-tertiary"
307
                      className='btn btn-tertiary'
240
                    >
308
                    >
241
                      {labels.message}
309
                      {labels.message}
242
                    </Link>
310
                    </Link>
243
                  </li>
311
                  </li>
244
                )}
312
                )}
245
              </ul>
313
              </ul>
246
            )}
314
            )}
247
          </StyledContent>
315
          </StyledContent>
248
        </StyledHeader>
316
        </StyledHeader>
249
        <StyledItemContainer.Actions>
317
        <StyledItemContainer.Actions>
250
          {linksOptions.map(({ label, url }) => {
318
          {linksOptions.map(({ label, url, icon: Icon }) => {
251
            const breakOptions = [link_view, link_edit, link_inmail];
319
            const breakOptions = [link_view, link_edit, link_inmail]
Línea 252... Línea 320...
252
 
320
 
253
            if (!url) {
321
            if (!url) {
254
              return null;
322
              return null
Línea 255... Línea 323...
255
            }
323
            }
256
 
324
 
257
            if (url === link_view && isTopData) {
325
            if (url === link_view && isTopData) {
Línea 258... Línea 326...
258
              return null;
326
              return null
259
            }
327
            }
260
 
328
 
Línea 261... Línea 329...
261
            if (url === link_inmail && isTopData) {
329
            if (url === link_inmail && isTopData) {
262
              return null;
330
              return null
263
            }
331
            }
264
 
332
 
265
            return (
333
            return (
266
              <button
334
              <button
267
                key={url}
335
                key={url}
Línea 268... Línea 336...
268
                onClick={() => {
336
                onClick={() => {
269
                  if (url === link_unfollow) {
337
                  if (url === link_unfollow) {
270
                    return handleUnfollow(url);
338
                    return handleUnfollow(url)
Línea 271... Línea 339...
271
                  }
339
                  }
272
 
340
 
273
                  if (url === link_admin) {
341
                  if (url === link_admin) {
Línea 274... Línea 342...
274
                    return getManageUrl();
342
                    return getManageUrl()
275
                  }
343
                  }
276
 
344
 
277
                  if (url === link_impersonate) {
345
                  if (url === link_impersonate) {
278
                    return getImpersonateUrl(url);
346
                    return getImpersonateUrl(url)
279
                  }
347
                  }
280
 
348
 
-
 
349
                  if (!breakOptions.includes(url)) {
281
                  if (!breakOptions.includes(url)) {
350
                    return showConfirm(url)
282
                    return showConfirm(url);
351
                  } else {
283
                  } else {
352
                    history.push(url)
284
                    history.push(url);
353
                  }
285
                  }
354
                }}
286
                }}
355
              >
287
              >
356
                <Icon />
288
                {label}
357
                {label}
Línea 300... Línea 369...
300
        show={isShowConfirmation}
369
        show={isShowConfirmation}
301
        onClose={() => closeConfirm()}
370
        onClose={() => closeConfirm()}
302
        onAccept={() => onConfirm(confirmUrl.current)}
371
        onAccept={() => onConfirm(confirmUrl.current)}
303
      />
372
      />
304
    </>
373
    </>
305
  );
374
  )
306
};
375
}
Línea 307... Línea 376...
307
 
376