Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3086 | Rev 3089 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useEffect, useState } from 'react'
import { useDispatch } from 'react-redux'
import { Avatar, Chip, List, styled, Typography } from '@mui/material'
import {
  Favorite,
  FavoriteBorder,
  AccessTime,
  LocationOn,
  Email,
  Visibility
} from '@mui/icons-material'

import { axios, parse } from '@utils'
import { addNotification } from '@store/notification/notification.actions'

import Widget from '@components/UI/Widget'

const StyledHeart = styled(Favorite)`
  animation: heartBeatAnimation 0.2s linear;

  @keyframes heartBeatAnimation {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.3);
    }
    100% {
      transform: scale(1);
    }
  }
`

const StyledHeartOutline = styled(FavoriteBorder)`
  animation: heartBeatAnimation 0.2s linear;

  @keyframes heartBeatAnimation {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.3);
    }
    100% {
      transform: scale(1);
    }
  }
`

export default function JobCard({
  job: {
    company_uuid: companyUuid,
    company_image: companyImage,
    job_uuid: jobUuid,
    job_title: jobTitle,
    job_description: jobDescription,
    total_applications: totalApplications,
    location,
    employment_type: employmentType,
    last_date_of_application: lastDateOfApplication,
    job_category: jobCategory,
    timeElapsed,
    job_skills: jobSkills,
    job_visits: jobVisits,
    job_save_operation: jobSaveOperation,
    company_name: companyName
  }
}) {
  const [isJobSaved, setIsJobSaved] = useState(false)
  const dispatch = useDispatch()

  const handleClickFollow = () => {
    setIsJobSaved(!isJobSaved)
    likeHandler()
  }

  const likeHandler = () => {
    axios
      .post(`/job/${isJobSaved ? 'remove-' : ''}save-job/${jobUuid}`)
      .then((response) => {
        const { success } = response.data

        if (!success) {
          setIsJobSaved((currentState) => !currentState)
          dispatch(
            addNotification({
              style: 'danger',
              msg: 'Ha ocurrido un error, por favor intente más tarde'
            })
          )
        }
      })
  }

  useEffect(() => {
    setIsJobSaved(jobSaveOperation !== 'job-save')
  }, [jobSaveOperation])

  return (
    <Widget>
      <Widget.Body>
        <Avatar
          src={`/storage/type/company/code/${companyUuid}/${
            companyImage ? `filename/${companyImage}` : ''
          }`}
          sx={{ width: '50px', height: '50px' }}
        />

        <Typography variant='h3'>{jobTitle}</Typography>
        <Typography>{companyName}</Typography>
        <Typography variant='overline'>
          <AccessTime sx={{ fontSize: '1rem' }} />
          Posteado hace {timeElapsed}
        </Typography>

        <Typography variant='overline'>
          <LocationOn sx={{ color: '#cd5c5c' }} />
          {location}
        </Typography>

        <Typography variant='overline'>
          {isJobSaved ? (
            <StyledHeart sx={{ color: 'red' }} onClick={handleClickFollow} />
          ) : (
            <StyledHeartOutline
              sx={{ color: 'red' }}
              onClick={handleClickFollow}
            />
          )}
          Última aplicación : {lastDateOfApplication}
        </Typography>

        <Typography variant='overline'>{employmentType}</Typography>
        <Typography variant='overline'>{jobCategory}</Typography>

        <div>{jobDescription && parse(jobDescription)}</div>

        {jobSkills && !!jobSkills.length && (
          <List>
            {jobSkills.map((skill) => (
              <Chip key={skill} label={skill} />
            ))}
          </List>
        )}

        <Typography variant='overline'>
          <Email />
          Solicitantes {totalApplications}
        </Typography>

        <Typography variant='overline'>
          <Visibility /> Visto {jobVisits}
        </Typography>
      </Widget.Body>
    </Widget>
  )
}