Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5822 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useState } from 'react'
3
import { axios } from '../../../../utils'
4
import { Spinner } from 'react-bootstrap'
5
import { useDispatch } from 'react-redux'
6
import { addNotification } from '../../../../redux/notification/notification.actions'
7
 
8
const ApplicationSidebar = ({
9
  jobId,
10
  isJobApplied,
11
  onApply,
12
  onWithdrawApply,
13
}) => {
14
  const [loading, setLoading] = useState(false)
15
  const dispatch = useDispatch()
16
 
17
  const handleClick = () => {
18
    if (isJobApplied) return handleWithdrawApply()
19
 
20
    return onApply()
21
  }
22
 
23
  const handleWithdrawApply = async () => {
24
    setLoading(true)
25
    axios
26
      .post(`/job/remove-apply-job/${jobId}`)
27
      .then(({ data: response }) => {
28
        const { data, success } = response
29
 
30
        if (!success) {
31
          const errorMessage =
32
            typeof data === 'string'
33
              ? data
34
              : 'Ha ocurrido un error, por favor intente más tarde'
35
 
36
          dispatch(addNotification({ styled: 'danger', msg: errorMessage }))
37
        }
38
 
39
        onWithdrawApply()
40
      })
41
      .finally(() => setLoading(false))
42
  }
43
 
44
  return (
45
    <>
46
      <div id="div-apply-job" className={`applicationSidebar bid-place`}>
47
        <button
48
          type="button"
49
          className="btn btn-primary btn-apply"
50
          onClick={handleClick}
51
          disabled={loading}
52
        >
53
          {loading ? (
54
            <Spinner animation="border" variant="dark" size="sm" />
55
          ) : isJobApplied ? (
56
            'Quitar aplicación'
57
          ) : (
58
            'Aplicar'
59
          )}
60
        </button>
61
      </div>
62
    </>
63
  )
64
}
65
 
66
export default ApplicationSidebar