Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3156 Rev 3432
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 { useNavigate } from 'react-router-dom'
4
import { useNavigate } 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 styled from 'styled-components'
7
import styled from "styled-components";
8
 
8
 
9
import Spinner from '../UI/Spinner'
9
import Spinner from "../UI/Spinner";
10
import WidgetWrapper from '../widgets/WidgetLayout'
10
import WidgetWrapper from "../widgets/WidgetLayout";
11
import ConfirmModal from '../modals/ConfirmModal'
11
import ConfirmModal from "../modals/ConfirmModal";
12
import Button from '../UI/buttons/Buttons'
12
import Button from "../UI/buttons/Buttons";
Línea 13... Línea 13...
13
 
13
 
14
const StyledSpinnerContainer = styled.div`
14
const StyledSpinnerContainer = styled.div`
15
  position: absolute;
15
  position: absolute;
16
  left: 0;
16
  left: 0;
17
  top: 0;
17
  top: 0;
18
  width: 100%;
18
  width: 100%;
19
  height: 100%;
19
  height: 100%;
20
  background: rgba(255, 255, 255, 0.4);
20
  background: rgba(255, 255, 255, 0.4);
21
  place-items: center;
21
  place-items: center;
22
  z-index: 50;
22
  z-index: 50;
Línea 23... Línea 23...
23
`
23
`;
24
 
24
 
25
const StyledItemContainer = styled(WidgetWrapper)`
25
const StyledItemContainer = styled(WidgetWrapper)`
26
  display: flex;
26
  display: flex;
27
  flex-direction: column;
27
  flex-direction: column;
28
  justify-content: center;
28
  justify-content: center;
29
  height: fit-content;
29
  height: fit-content;
Línea 30... Línea 30...
30
  border-radius: 5px;
30
  border-radius: 5px;
31
`
31
`;
32
 
32
 
33
const StyledHeader = styled.div`
33
const StyledHeader = styled.div`
34
  align-items: center;
34
  align-items: center;
35
  display: flex;
35
  display: flex;
36
  gap: 0.5rem;
36
  gap: 0.5rem;
37
  justify-content: flex-start;
37
  justify-content: flex-start;
Línea 38... Línea 38...
38
  position: relative;
38
  position: relative;
39
  padding: 0.5rem;
39
  padding: 0.5rem;
40
`
40
`;
41
 
41
 
Línea 47... Línea 47...
47
    align-items: center;
47
    align-items: center;
48
    display: flex;
48
    display: flex;
49
    justify-content: center;
49
    justify-content: center;
50
    gap: 0.5rem;
50
    gap: 0.5rem;
51
  }
51
  }
52
`
52
`;
Línea 53... Línea 53...
53
 
53
 
54
const Actions = styled.div`
54
const Actions = styled.div`
55
  display: flex;
55
  display: flex;
56
  flex-wrap: wrap;
56
  flex-wrap: wrap;
57
  justify-content: space-around;
57
  justify-content: space-around;
58
  border-top: 1px solid rgb(211, 211, 211);
58
  border-top: 1px solid rgb(211, 211, 211);
59
  padding: 0.5rem;
59
  padding: 0.5rem;
60
  gap: 0.5rem;
60
  gap: 0.5rem;
Línea 61... Línea 61...
61
`
61
`;
62
 
62
 
63
const StyledAvatar = styled(Avatar)`
63
const StyledAvatar = styled(Avatar)`
64
  height: 60px !important;
64
  height: 60px !important;
Línea 65... Línea 65...
65
  width: 60px !important;
65
  width: 60px !important;
66
`
66
`;
67
 
67
 
68
const ProfileItem = ({
68
const ProfileItem = ({
Línea 91... Línea 91...
91
  btnAcceptTitle,
91
  btnAcceptTitle,
92
  btnCancelTitle,
92
  btnCancelTitle,
93
  btnEditTitle,
93
  btnEditTitle,
94
  btnLeaveTitle,
94
  btnLeaveTitle,
95
  btnRemoveLabel,
95
  btnRemoveLabel,
96
  isTopData
96
  isTopData,
97
}) => {
97
}) => {
98
  const [isShowConfirmation, setIsShowConfirmation] = useState(false)
98
  const [isShowConfirmation, setIsShowConfirmation] = useState(false);
99
  const [loading, setLoading] = useState(false)
99
  const [loading, setLoading] = useState(false);
100
  const confirmUrl = useRef('')
100
  const confirmUrl = useRef("");
101
  const labels = useSelector(({ intl }) => intl.labels)
101
  const labels = useSelector(({ intl }) => intl.labels);
102
  const dispatch = useDispatch()
102
  const dispatch = useDispatch();
103
  const navigate = useNavigate()
103
  const navigate = useNavigate();
104
 
104
 
105
  const showConfirm = (url = '') => {
105
  const showConfirm = (url = "") => {
106
    setIsShowConfirmation(true)
106
    setIsShowConfirmation(true);
107
    confirmUrl.current = url
107
    confirmUrl.current = url;
108
  }
108
  };
Línea 109... Línea 109...
109
 
109
 
110
  const closeConfirm = () => {
110
  const closeConfirm = () => {
111
    setIsShowConfirmation(false)
111
    setIsShowConfirmation(false);
112
    confirmUrl.current = ''
112
    confirmUrl.current = "";
Línea 113... Línea 113...
113
  }
113
  };
114
 
114
 
115
  const getImpersonateUrl = async (url = '') => {
115
  const getImpersonateUrl = async (url = "") => {
116
    try {
116
    try {
Línea 117... Línea 117...
117
      const { data: response } = await axios.get(url)
117
      const response = await axios.get(url);
118
      const { data, success } = response
118
      const { data, success } = response.data;
119
 
119
 
120
      if (success) {
120
      if (success) {
121
        window.location.href = data
121
        window.location.href = data;
122
      }
122
      }
123
    } catch (error) {
123
    } catch (error) {
Línea 124... Línea 124...
124
      console.log('>>: error > ', error)
124
      console.log(">>: error > ", error);
125
    }
125
    }
126
  }
126
  };
127
 
127
 
128
  const onConfirm = (url) => {
128
  const onConfirm = (url) => {
129
    setLoading(true)
129
    setLoading(true);
Línea 130... Línea 130...
130
    axios
130
    axios
131
      .post(url)
131
      .post(url)
132
      .then((response) => {
132
      .then((response) => {
133
        const { success, data } = response.data
133
        const { success, data } = response.data;
134
 
134
 
Línea 135... Línea 135...
135
        if (!success) {
135
        if (!success) {
136
          const errorMessage =
136
          const errorMessage =
137
            typeof data === 'string'
137
            typeof data === "string"
Línea 138... Línea 138...
138
              ? data
138
              ? data
139
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
139
              : "Error interno. Por favor, inténtelo de nuevo más tarde.";
140
 
140
 
141
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
141
          dispatch(addNotification({ style: "danger", msg: errorMessage }));
142
          return
142
          return;
143
        }
143
        }
144
 
144
 
145
        if (fetchCallback) fetchCallback()
145
        if (fetchCallback) fetchCallback();
146
        dispatch(addNotification({ style: 'success', msg: data }))
146
        dispatch(addNotification({ style: "success", msg: data }));
147
      })
147
      })
148
      .catch(() => {
148
      .catch(() => {
149
        dispatch(
149
        dispatch(
150
          addNotification({
150
          addNotification({
151
            style: 'error',
151
            style: "error",
152
            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.",
153
          })
153
          })
Línea 154... Línea 154...
154
        )
154
        );
155
      })
155
      })
156
      .finally(() => {
156
      .finally(() => {
157
        confirmUrl.current = ''
157
        confirmUrl.current = "";
158
        setLoading(false)
158
        setLoading(false);
159
      })
159
      });
Línea 160... Línea 160...
160
  }
160
  };
161
 
161
 
162
  const handleUnfollow = (link_unfollow) => {
162
  const handleUnfollow = (link_unfollow) => {
163
    setLoading(true)
163
    setLoading(true);
164
    axios
164
    axios
Línea 165... Línea 165...
165
      .post(link_unfollow)
165
      .post(link_unfollow)
166
      .then((response) => {
166
      .then((response) => {
167
        const { data, success } = response.data
167
        const { data, success } = response.data;
Línea 168... Línea 168...
168
 
168
 
169
        if (!success) {
169
        if (!success) {
170
          const errorMessage =
170
          const errorMessage =
171
            typeof data === 'string'
171
            typeof data === "string"
172
              ? data
172
              ? data
Línea 173... Línea 173...
173
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
173
              : "Error interno. Por favor, inténtelo de nuevo más tarde.";
174
 
174
 
175
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
175
          dispatch(addNotification({ style: "danger", msg: errorMessage }));
176
          return
176
          return;
177
        }
177
        }
Línea 178... Línea 178...
178
 
178
 
179
        if (fetchCallback) fetchCallback()
179
        if (fetchCallback) fetchCallback();
180
        dispatch(addNotification({ style: 'success', msg: data }))
180
        dispatch(addNotification({ style: "success", msg: data }));
Línea 181... Línea 181...
181
      })
181
      })
182
      .finally(() => setLoading(false))
182
      .finally(() => setLoading(false));
183
  }
183
  };
184
 
184
 
185
  const getManageUrl = () => {
185
  const getManageUrl = () => {
186
    axios
186
    axios
187
      .get(link_admin)
187
      .get(link_admin)
188
      .then((response) => {
188
      .then((response) => {
Línea 189... Línea 189...
189
        const { data, success } = response.data
189
        const { data, success } = response.data;
190
 
190
 
191
        if (!success) {
191
        if (!success) {
Línea 192... Línea 192...
192
          throw new Error(data)
192
          throw new Error(data);
193
        }
193
        }
194
 
194
 
195
        setTimeout(() => {
195
        setTimeout(() => {
Línea 218... Línea 218...
218
            {isTopData && (
218
            {isTopData && (
219
              <ul>
219
              <ul>
220
                {link_view && (
220
                {link_view && (
221
                  <li>
221
                  <li>
222
                    <Button
222
                    <Button
223
                      color='primary'
223
                      color="primary"
224
                      onClick={() => navigateTo(link_view)}
224
                      onClick={() => navigateTo(link_view)}
225
                    >
225
                    >
226
                      {btnAcceptTitle || labels.view_profile}
226
                      {btnAcceptTitle || labels.view_profile}
227
                    </Button>
227
                    </Button>
228
                  </li>
228
                  </li>
229
                )}
229
                )}
230
                {link_inmail && (
230
                {link_inmail && (
231
                  <li>
231
                  <li>
232
                    <Button
232
                    <Button
233
                      color='secondary'
233
                      color="secondary"
234
                      onClick={() => navigateTo(link_inmail)}
234
                      onClick={() => navigateTo(link_inmail)}
235
                    >
235
                    >
236
                      {labels.message}
236
                      {labels.message}
237
                    </Button>
237
                    </Button>
238
                  </li>
238
                  </li>
Línea 241... Línea 241...
241
            )}
241
            )}
242
          </StyledContent>
242
          </StyledContent>
243
        </StyledHeader>
243
        </StyledHeader>
244
        <Actions>
244
        <Actions>
245
          {link_view && !isTopData ? (
245
          {link_view && !isTopData ? (
246
            <Button color='primary' onClick={() => navigateTo(link_view)}>
246
            <Button color="primary" onClick={() => navigateTo(link_view)}>
247
              {btnAcceptTitle || labels.view_profile}
247
              {btnAcceptTitle || labels.view_profile}
248
            </Button>
248
            </Button>
249
          ) : null}
249
          ) : null}
Línea 250... Línea 250...
250
 
250
 
251
          {link_edit ? (
251
          {link_edit ? (
252
            <Button onClick={() => navigateTo(link_edit)} color='secondary'>
252
            <Button onClick={() => navigateTo(link_edit)} color="secondary">
253
              {btnEditTitle || labels.edit}
253
              {btnEditTitle || labels.edit}
254
            </Button>
254
            </Button>
Línea 255... Línea 255...
255
          ) : null}
255
          ) : null}
256
 
256
 
257
          {link_accept ? (
257
          {link_accept ? (
258
            <Button onClick={() => onConfirm(link_accept)} color='secondary'>
258
            <Button onClick={() => onConfirm(link_accept)} color="secondary">
259
              {labels.accept}
259
              {labels.accept}
Línea 260... Línea 260...
260
            </Button>
260
            </Button>
261
          ) : null}
261
          ) : null}
262
 
262
 
263
          {link_inmail && !isTopData ? (
263
          {link_inmail && !isTopData ? (
264
            <Button color='secondary' onClick={() => navigateTo(link_inmail)}>
264
            <Button color="secondary" onClick={() => navigateTo(link_inmail)}>
Línea 265... Línea 265...
265
              {labels.message}
265
              {labels.message}
266
            </Button>
266
            </Button>
267
          ) : null}
267
          ) : null}
268
 
268
 
269
          {link_admin ? (
269
          {link_admin ? (
Línea 270... Línea 270...
270
            <Button color='secondary' onClick={() => getManageUrl(link_admin)}>
270
            <Button color="secondary" onClick={() => getManageUrl(link_admin)}>
271
              {labels.administrate}
271
              {labels.administrate}
272
            </Button>
272
            </Button>
273
          ) : null}
273
          ) : null}
274
 
274
 
Línea 275... Línea 275...
275
          {link_approve ? (
275
          {link_approve ? (
276
            <Button color='secondary' onClick={() => onConfirm(link_approve)}>
276
            <Button color="secondary" onClick={() => onConfirm(link_approve)}>
277
              {labels.approve}
277
              {labels.approve}
278
            </Button>
278
            </Button>
279
          ) : null}
279
          ) : null}
Línea 280... Línea 280...
280
 
280
 
281
          {link_unblock ? (
281
          {link_unblock ? (
282
            <Button color='secondary' onClick={() => onConfirm(link_unblock)}>
282
            <Button color="secondary" onClick={() => onConfirm(link_unblock)}>
283
              {labels.unblock}
283
              {labels.unblock}
284
            </Button>
284
            </Button>
Línea 285... Línea 285...
285
          ) : null}
285
          ) : null}
286
 
286
 
287
          {link_request ? (
287
          {link_request ? (
288
            <Button color='secondary' onClick={() => onConfirm(link_request)}>
288
            <Button color="secondary" onClick={() => onConfirm(link_request)}>
289
              {labels.connect}
289
              {labels.connect}
290
            </Button>
290
            </Button>
291
          ) : null}
291
          ) : null}
292
 
292
 
Línea 293... Línea 293...
293
          {link_impersonate ? (
293
          {link_impersonate ? (
294
            <Button
294
            <Button
295
              color='secondary'
295
              color="secondary"
296
              onClick={() => getImpersonateUrl(link_impersonate)}
296
              onClick={() => getImpersonateUrl(link_impersonate)}
297
            >
297
            >
Línea 298... Línea 298...
298
              Personificar
298
              Personificar
299
            </Button>
299
            </Button>
300
          ) : null}
300
          ) : null}
301
 
301
 
302
          {link_remove ? (
302
          {link_remove ? (
Línea 303... Línea 303...
303
            <Button color='info' onClick={() => showConfirm(link_remove)}>
303
            <Button color="info" onClick={() => showConfirm(link_remove)}>
304
              {btnRemoveLabel}
304
              {btnRemoveLabel}
305
            </Button>
305
            </Button>
306
          ) : null}
306
          ) : null}
307
 
307
 
Línea 308... Línea 308...
308
          {link_reject ? (
308
          {link_reject ? (
309
            <Button color='info' onClick={() => showConfirm(link_reject)}>
309
            <Button color="info" onClick={() => showConfirm(link_reject)}>
310
              {labels.reject}
310
              {labels.reject}
311
            </Button>
311
            </Button>
312
          ) : null}
312
          ) : null}
Línea 313... Línea 313...
313
 
313
 
314
          {link_delete ? (
314
          {link_delete ? (
315
            <Button color='info' onClick={() => showConfirm(link_delete)}>
315
            <Button color="info" onClick={() => showConfirm(link_delete)}>
316
              {btnCancelTitle || labels.cancel}
316
              {btnCancelTitle || labels.cancel}
317
            </Button>
317
            </Button>
Línea 318... Línea 318...
318
          ) : null}
318
          ) : null}
319
 
319
 
320
          {link_unfollow ? (
320
          {link_unfollow ? (
321
            <Button color='info' onClick={() => handleUnfollow(link_unfollow)}>
321
            <Button color="info" onClick={() => handleUnfollow(link_unfollow)}>
322
              {labels.unfollow}
322
              {labels.unfollow}
Línea 323... Línea 323...
323
            </Button>
323
            </Button>
324
          ) : null}
324
          ) : null}
325
 
325
 
326
          {link_block ? (
326
          {link_block ? (
327
            <Button color='info' onClick={() => showConfirm(link_block)}>
327
            <Button color="info" onClick={() => showConfirm(link_block)}>
328
              {labels.block}
328
              {labels.block}
329
            </Button>
329
            </Button>
Línea 351... Línea 351...
351
        show={isShowConfirmation}
351
        show={isShowConfirmation}
352
        onClose={() => closeConfirm()}
352
        onClose={() => closeConfirm()}
353
        onAccept={() => onConfirm(confirmUrl.current)}
353
        onAccept={() => onConfirm(confirmUrl.current)}
354
      />
354
      />
355
    </>
355
    </>
356
  )
356
  );
357
}
357
};
Línea 358... Línea 358...
358
 
358