Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1588 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1587 steven 1
import React, { useState } from "react";
2
import { addNotification } from "../redux/notification/notification.actions";
3
import ConfirmationBox from "../shared/confirmation-box/ConfirmationBox";
4
import Spinner from "../shared/loading-spinner/Spinner";
5
import { axios } from "../utils";
6
import styled from 'styled-components'
7
 
8
const StyledSpinnerContainer = styled.div`
9
  position: absolute;
10
  left: 0;
11
  top: 0;
12
  width: 100%;
13
  height: 100%;
14
  background: rgba(255, 255, 255, 0.4);
15
  display: flex;
16
  justify-content: center;
17
  align-items: center;
18
  z-index: 300;
19
`;
20
const Profile = (props) => {
21
  // props destructuring
22
  const {
23
    image,
24
    name,
25
    status,
26
    link_view,
27
    link_edit,
28
    link_delete,
29
    link_cancel,
30
    link_block,
31
    link_reject,
32
    link_approve,
33
    link_inmail,
34
    link_request,
35
    link_unblock,
36
    link_admin,
37
    fetchCallback
38
  } = props;
39
 
40
  // states
41
  const [showConfirmationBox, setShowConfirmationBox] = useState(false);
42
  const [showCancelConfirmationBox, setShowCancelConfirmationBox] = useState(false);
43
  const [showBlockConfirmationBox, setShowBlockConfirmationBox] = useState(false);
44
  const [showRejectConfirmationBox, setShowRejectConfirmationBox] = useState(false);
45
  const [showApproveConfirmationBox, setShowApproveConfirmationBox] = useState(false);
46
  const [showRequestConfirmationBox, setShowRequestConfirmationBox] = useState(false);
47
  const [showUnblockConfirmationBox, setShowUnblockConfirmationBox] = useState(false);
48
 
49
  const [loading, setLoading] = useState(false)
50
  const handleShowConfirmationBox = (show = !showConfirmationBox) => {
51
    setShowConfirmationBox(show);
52
  };
53
  const handleCancelConfirmationBox = (show = !showConfirmationBox) => {
54
    setShowCancelConfirmationBox(show);
55
  };
56
  const handleBlockConfirmationBox = (show = !showConfirmationBox) => {
57
    setShowBlockConfirmationBox(show);
58
  };
59
  const handleRejectConfirmationBox = (show = !showConfirmationBox) => {
60
    setShowRejectConfirmationBox(show);
61
  };
62
  const handleApproveConfirmationBox = (show = !showConfirmationBox) => {
63
    setShowApproveConfirmationBox(show);
64
  };
65
  const handleRequestConfirmationBox = (show = !showConfirmationBox) => {
66
    setShowRequestConfirmationBox(show);
67
  };
68
  const handleUnblockConfirmationBox = (show = !showConfirmationBox) => {
69
    setShowUnblockConfirmationBox(show);
70
  };
71
 
72
  const handleCancelApply = (url = link_delete) => {
73
    setLoading(true);
74
    axios
75
      .post(url)
76
      .then((response) => {
77
        const resData = response.data;
78
         (resData);
79
        if (resData.success) {
80
          const msg = resData.data;
81
          addNotification({
82
            style: "success",
83
            msg: msg,
84
          });
85
          if(fetchCallback)
86
            fetchCallback();
87
        } else {
88
          const errorMsg =
89
            typeof resData.data === "string"
90
              ? resData.data
91
              : "Ha ocurrido un error, Por favor intente más tarde";
92
          addNotification({
93
            style: "danger",
94
            msg: errorMsg,
95
          });
96
          setLoading(false);
97
        }
98
      })
99
      .catch((error) => {
100
        console.log('>>: error > ', error)
101
      })
102
      .finally(() => {
103
        setLoading(false);
104
      });
105
  };
106
 
107
  const getManageUrl = async () => {
108
    try {
109
      const res = await axios.get(link_admin)
110
      if(res.data.success){
111
        window.open(res.data.data, '_backend')
112
      }
113
    } catch (error) {
114
      console.log('>>: error > ', error)
115
    }
116
  }
117
 
118
  return (
119
    <div className="col-md-3 col-sm-6 col-12">
120
      <div className="company_profile_info border-radius border-gray">
121
        <div className="company-up-info border-radius">
122
          <div className="ph-15">
123
            <div
124
              className="row border-bottom-gray mb-2"
125
            >
126
              {
127
                !!image && (
128
                  <div className="col-md-4 col-sm-12 p-0">
129
                    <img src={image} className="object-fit-contain" style={{borderRadius: 0}} alt="" />
130
                  </div>
131
                )
132
              }
133
              <div className={image ? 'col-md-8 d-flex justify-content-center align-items-center' : 'col-md-12 '+ ' col-sm-12 col-12'}>
134
                <h3 className={status ? '' : "col-sm-12 d-flex justify-content-center align-items-center"}>
135
                  {name}
136
                  {
137
                    status && (
138
                      <>
139
                        <br />
140
                        <h4 className="col-sm-12 d-flex justify-content-center align-items-center">{status}</h4>
141
                      </>
142
                    )
143
                  }
144
                </h3>
145
              </div>
146
            </div>
147
          </div>
148
 
149
          <ul>
150
            {
151
              link_view && (
152
                <li>
153
                  <a
154
                    href={link_view}
155
                    data-link={link_view}
156
                    title=""
157
                    className="btn btn-primary"
158
                  >
159
                    Ver perfil
160
                  </a>
161
                </li>
162
              )
163
            }
164
            {
165
              link_edit && (
166
                <li>
167
                  <a
168
                    href={link_edit}
169
                    data-link={link_edit}
170
                    title=""
171
                    className="btn btn-secondary"
172
                  >
173
                    Editar perfil
174
                  </a>
175
                </li>
176
              )
177
            }
178
            {
179
              link_approve && (
180
                <li>
181
                  <a
182
                    href="#"
183
                    className="btn btn-tertiary"
184
                    onClick={(e) => {
185
                      e.preventDefault();
186
                      handleApproveConfirmationBox();
187
                    }}
188
                  >
189
                    Aprobar
190
                  </a>
191
                </li>
192
              )
193
            }
194
            {
195
              link_reject && (
196
                <li>
197
                  <a
198
                    href="#"
199
                    className="btn btn-tertiary"
200
                    onClick={(e) => {
201
                      e.preventDefault();
202
                      handleRejectConfirmationBox();
203
                    }}
204
                  >
205
                    Rechazar
206
                  </a>
207
                </li>
208
              )
209
            }
210
            {
211
              link_delete && (
212
                <li>
213
                  <a
214
                    href="#"
215
                    className="btn btn-tertiary"
216
                    onClick={(e) => {
217
                      e.preventDefault();
218
                      handleShowConfirmationBox();
219
                    }}
220
                  >
221
                    Borrar perfil
222
                  </a>
223
                </li>
224
              )
225
            }
226
            {
227
              link_inmail && (
228
                <li>
229
                  <a
230
                    href={link_inmail}
231
                    data-link={link_inmail}
232
                    title=""
233
                    className="btn btn-tertiary"
234
                  >
235
                    Mensaje
236
                  </a>
237
                </li>
238
              )
239
            }
240
            {
241
              link_admin && (
242
                <li>
243
                  <a
244
                    onClick={() => getManageUrl()}
245
                    data-link={link_admin}
246
                    title="Administrar empresa"
247
                    className="btn btn-tertiary"
248
                  >
249
                    Administrar
250
                  </a>
251
                </li>
252
              )
253
            }
254
 
255
            {
256
              link_block && (
257
                <li>
258
                  <a
259
                    href="#"
260
                    className="btn btn-secondary"
261
                    onClick={(e) => {
262
                      e.preventDefault();
263
                      handleBlockConfirmationBox();
264
                    }}
265
                  >
266
                    Bloquear
267
                  </a>
268
                </li>
269
              )
270
            }
271
            {
272
              link_unblock && (
273
                <li>
274
                  <a
275
                    href="#"
276
                    className="btn btn-secondary"
277
                    onClick={(e) => {
278
                      e.preventDefault();
279
                      handleUnblockConfirmationBox();
280
                    }}
281
                  >
282
                    Desbloquear
283
                  </a>
284
                </li>
285
              )
286
            }
287
            {
288
              link_request && (
289
                <li>
290
                  <a
291
                    href="#"
292
                    className="btn btn-secondary"
293
                    onClick={(e) => {
294
                      e.preventDefault();
295
                      handleRequestConfirmationBox();
296
                    }}
297
                  >
298
                    Conectar
299
                  </a>
300
                </li>
301
              )
302
            }
303
            {
304
              link_cancel && (
305
                <li>
306
                  <a
307
                    href="#"
308
                    className="btn btn-primary"
309
                    onClick={(e) => {
310
                      e.preventDefault();
311
                      handleCancelConfirmationBox();
312
                    }}
313
                  >
314
                    Cancelar
315
                  </a>
316
                </li>
317
              )
318
            }
319
 
320
          </ul>
321
        </div>
322
        {link_delete && (
323
          <div style={{ position: "relative" }}>
324
            <ConfirmationBox
325
              show={showConfirmationBox}
326
              onClose={() => handleShowConfirmationBox(false)}
327
              onAccept={() => handleCancelApply(link_delete)}
328
            />
329
          </div>
330
        )}
331
        {link_cancel && (
332
          <div style={{ position: "relative" }}>
333
            <ConfirmationBox
334
              show={showCancelConfirmationBox}
335
              onClose={() => handleCancelConfirmationBox(false)}
336
              onAccept={() => handleCancelApply(link_cancel)}
337
            />
338
          </div>
339
        )}
340
        {link_block && (
341
          <div style={{ position: "relative" }}>
342
            <ConfirmationBox
343
              show={showBlockConfirmationBox}
344
              onClose={() => handleBlockConfirmationBox(false)}
345
              onAccept={() => handleCancelApply(link_block)}
346
            />
347
          </div>
348
        )}
349
        {link_approve && (
350
          <div style={{ position: "relative" }}>
351
            <ConfirmationBox
352
              show={showApproveConfirmationBox}
353
              onClose={() => handleApproveConfirmationBox(false)}
354
              onAccept={() => handleCancelApply(link_approve)}
355
            />
356
          </div>
357
        )}
358
        {link_reject && (
359
          <div style={{ position: "relative" }}>
360
            <ConfirmationBox
361
              show={showRejectConfirmationBox}
362
              onClose={() => handleRejectConfirmationBox(false)}
363
              onAccept={() => handleCancelApply(link_reject)}
364
            />
365
          </div>
366
        )}
367
        {link_request && (
368
          <div style={{ position: "relative" }}>
369
            <ConfirmationBox
370
              show={showRequestConfirmationBox}
371
              onClose={() => handleRequestConfirmationBox(false)}
372
              onAccept={() => handleCancelApply(link_request)}
373
            />
374
          </div>
375
        )}
376
        {link_unblock && (
377
          <div style={{ position: "relative" }}>
378
            <ConfirmationBox
379
              show={showUnblockConfirmationBox}
380
              onClose={() => handleUnblockConfirmationBox(false)}
381
              onAccept={() => handleCancelApply(link_unblock)}
382
            />
383
          </div>
384
        )}
385
        {loading && (
386
          <StyledSpinnerContainer>
387
            <Spinner />
388
          </StyledSpinnerContainer>
389
        )}
390
      </div>
391
    </div>
392
  );
393
};
394
 
395
export default Profile;