Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { axios } from '../../utils'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import parse from 'html-react-parser'
6
import Avatar from '@mui/material/Avatar'
7
import { Favorite, FavoriteBorder } from '@mui/icons-material'
8
import AccessTimeIcon from '@mui/icons-material/AccessTime'
9
import LocationOnIcon from '@mui/icons-material/LocationOn'
10
import VisibilityIcon from '@mui/icons-material/Visibility'
11
import EmailIcon from '@mui/icons-material/Email'
12
 
13
import styled from 'styled-components'
14
import WidgetLayout from '../widgets/WidgetLayout'
15
 
16
const StyledContainer = styled(WidgetLayout)`
17
  padding: 1rem;
18
  h3 {
19
    font-size: 1.1rem;
20
    font-weight: 600;
21
    color: var(--title-color);
22
  }
23
  span {
24
    font-weight: 600;
25
    color: var(--subtitle-color);
26
    display: flex;
27
    align-items: center;
28
  }
29
  p {
30
    font-size: 1rem;
31
    color: var(--font-color);
32
  }
33
  .info {
34
    align-items: center;
35
    display: inline-flex;
36
    gap: 0.5rem;
37
  }
38
  .name {
39
    display: flex;
40
    flex-direction: column;
41
  }
42
  .details {
43
    display: flex;
44
    align-items: center;
45
    justify-content: space-between;
46
    gap: 0.5rem;
47
  }
48
  .job {
49
    display: flex;
50
    flex-direction: column;
51
    gap: 5px;
52
  }
53
`
54
 
55
const StyledHeart = styled(Favorite)`
56
  animation: heartBeatAnimation 0.2s linear;
57
 
58
  @keyframes heartBeatAnimation {
59
    0% {
60
      transform: scale(1);
61
    }
62
    50% {
63
      transform: scale(1.3);
64
    }
65
    100% {
66
      transform: scale(1);
67
    }
68
  }
69
`
70
 
71
const StyledHeartOutline = styled(FavoriteBorder)`
72
  animation: heartBeatAnimation 0.2s linear;
73
 
74
  @keyframes heartBeatAnimation {
75
    0% {
76
      transform: scale(1);
77
    }
78
    50% {
79
      transform: scale(1.3);
80
    }
81
    100% {
82
      transform: scale(1);
83
    }
84
  }
85
`
86
 
87
const Description = ({
88
  jobId = '',
89
  companyId = '',
90
  companyImage = '',
91
  jobTitle = '',
92
  companyName = '',
93
  timeElapsed = '',
94
  location = '',
95
  jobSaved = false,
96
  lastDateOfApplication = '',
97
  employmentType = '',
98
  jobCategory = '',
99
  jobDescription = '',
100
  jobSkills = [],
101
  totalApplications = 0,
102
  jobVisits = 0,
103
}) => {
104
  const [isJobSaved, setIsJobSaved] = useState(false)
105
  const dispatch = useDispatch()
106
 
107
  const handleClickFollow = () => {
108
    setIsJobSaved(!isJobSaved)
109
    likeHandler()
110
  }
111
 
112
  const likeHandler = () => {
113
    axios
114
      .post(`/job/${isJobSaved ? 'remove-' : ''}save-job/${jobId}`)
115
      .then((response) => {
116
        const { success } = response.data
117
 
118
        if (!success) {
119
          setIsJobSaved((currentState) => !currentState)
120
          dispatch(
121
            addNotification({
122
              style: 'danger',
123
              msg: 'Ha ocurrido un error, por favor intente más tarde',
124
            })
125
          )
126
        }
127
      })
128
  }
129
 
130
  useEffect(() => {
131
    setIsJobSaved(jobSaved !== 'job-save')
132
  }, [jobSaved])
133
 
134
  return (
135
    <StyledContainer>
136
      <div className="info">
137
        <Avatar
138
          src={`/storage/type/company/code/${companyId}/${
139
            companyImage ? `filename/${companyImage}` : ''
140
          }`}
141
          sx={{ width: '50px', height: '50px' }}
142
        />
143
 
144
        <div className="name">
145
          <h3>{jobTitle}</h3>
146
          <p>{companyName}</p>
147
          <span>
148
            <AccessTimeIcon sx={{ fontSize: '1rem' }} />
149
            Posteado hace {timeElapsed}
150
          </span>
151
        </div>
152
      </div>
153
 
154
      <div className="details">
155
        <span>
156
          <LocationOnIcon sx={{ color: '#cd5c5c' }} />
157
          {location}
158
        </span>
159
 
160
        <span>
161
          {isJobSaved ? (
162
            <StyledHeart sx={{ color: 'red' }} onClick={handleClickFollow} />
163
          ) : (
164
            <StyledHeartOutline
165
              sx={{ color: 'red' }}
166
              onClick={handleClickFollow}
167
            />
168
          )}
169
          Última aplicación : {lastDateOfApplication}
170
        </span>
171
      </div>
172
 
173
      <div className="job">
174
        <h3>{employmentType}</h3>
175
        <h3>{jobCategory}</h3>
176
        <div>{jobDescription && parse(jobDescription)}</div>
177
 
178
        {jobSkills && !!jobSkills.length && (
179
          <ul className="skill-tags">
180
            {jobSkills.map((skill, index) => (
181
              <li key={index}>
182
                <span>{skill}</span>
183
              </li>
184
            ))}
185
          </ul>
186
        )}
187
        <span>
188
          <EmailIcon />
189
          Solicitantes {totalApplications}
190
        </span>
191
      </div>
192
 
193
      <span>
194
        <VisibilityIcon /> Visto {jobVisits}
195
      </span>
196
    </StyledContainer>
197
  )
198
}
199
 
200
export default Description