Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3089 Rev 3416
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from "react";
2
import { useParams } from 'react-router-dom'
2
import { useParams } from "react-router-dom";
3
import { useDispatch } from 'react-redux'
3
import { useDispatch } from "react-redux";
4
import { Button, Grid } from '@mui/material'
4
import { Button, Grid } from "@mui/material";
5
 
5
 
6
import { axios, parse } from '@utils'
6
import { axios, parse } from "@utils";
7
import { useFetch } from '@hooks'
7
import { useFetch } from "@hooks";
8
import { addNotification } from '@store/notification/notification.actions'
8
import { addNotification } from "@store/notification/notification.actions";
9
 
9
 
10
import Spinner from '@components/UI/Spinner'
10
import Spinner from "@components/UI/Spinner";
11
import JobCard from '@components/job/job-card'
11
import JobCard from "@components/job/job-card";
12
import JobAttr from '@components/job/job-attr'
12
import JobAttr from "@components/job/job-attr";
13
import CompanyInfo from '@components/job/company-info'
13
import CompanyInfo from "@components/job/company-info";
14
import ApplyModal from '@components/job/apply-modal'
14
import ApplyModal from "@components/job/apply-modal";
Línea 15... Línea 15...
15
 
15
 
16
const JobViewPage = () => {
16
const JobViewPage = () => {
17
  const [showApplyModal, setShowApplyModal] = useState(false)
-
 
18
  const [loading, setLoading] = useState(false)
-
 
19
  const { uuid } = useParams()
-
 
Línea 20... Línea 17...
20
  const dispatch = useDispatch()
17
  const [showApplyModal, setShowApplyModal] = useState(false);
21
 
18
 
Línea -... Línea 19...
-
 
19
  const { uuid } = useParams();
-
 
20
  const dispatch = useDispatch();
-
 
21
 
22
  const { data: job, isLoading, mutate } = useFetch(`/job/view/${uuid}`)
22
  const { data: job, loading, mutate } = useFetch(`/job/view/${uuid}`);
Línea 23... Línea 23...
23
  const isJobApplied = job?.job_apply_operation === 'remove-apply'
23
  const isJobApplied = job?.job_apply_operation === "remove-apply";
24
 
24
 
25
  const toggleApplyModal = () => setShowApplyModal(!showApplyModal)
25
  const toggleApplyModal = () => setShowApplyModal(!showApplyModal);
26
 
26
 
27
  const toggleApplication = () => {
27
  const toggleApplication = () => {
28
    mutate({
28
    mutate({
Línea 29... Línea 29...
29
      ...job,
29
      ...job,
30
      job_apply_operation: isJobApplied ? 'apply' : 'remove-apply'
-
 
31
    })
30
      job_apply_operation: isJobApplied ? "apply" : "remove-apply",
-
 
31
    });
32
  }
32
  };
-
 
33
 
33
 
34
  const removeApply = async () => {
34
  const removeApply = async () => {
35
    try {
35
    setLoading(true)
36
      const response = await axios.post(
36
    try {
37
        `/job/remove-apply-job/${job.job_uuid}`
37
      const response = await axios.post(`/job/remove-apply-job/${job.job_uuid}`)
38
      );
38
      const { data, success } = response.data
39
      const { data, success } = response.data;
39
      if (!success) throw new Error('Error al eliminar la aplicación')
-
 
40
      dispatch(addNotification({ style: 'success', msg: data }))
-
 
41
      toggleApplication()
40
      if (!success) throw new Error("Error al eliminar la aplicación");
42
    } catch (error) {
41
      dispatch(addNotification({ style: "success", msg: data }));
43
      dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
44
    } finally {
-
 
45
      setLoading(false)
-
 
Línea -... Línea 42...
-
 
42
      toggleApplication();
46
    }
43
    } catch (error) {
47
  }
44
      dispatch(addNotification({ style: "danger", msg: error.message }));
48
 
-
 
49
  const apply = async (jobApply) => {
-
 
50
    setLoading(true)
-
 
51
 
-
 
52
    try {
-
 
53
      const url = `/job/apply-job/${job.job_uuid}`
-
 
54
      const formData = new FormData()
-
 
55
      Object.entries(jobApply).map(([key, value]) =>
-
 
56
        formData.append(key, value)
-
 
57
      )
-
 
58
 
45
    }
59
      const response = await axios.post(url, formData)
46
  };
60
      const { data, success } = response.data
47
 
61
 
48
  const apply = async (apply) => {
-
 
49
    try {
-
 
50
      const msg = await axios.post(`/job/apply-job/${job.job_uuid}`, apply);
-
 
51
      dispatch(addNotification({ style: "success", msg }));
62
      if (!success) throw new Error('Error al aplicar al trabajo')
52
      toggleApplication();
63
 
53
      toggleApplyModal();
64
      dispatch(addNotification({ style: 'success', msg: data }))
54
    } catch (error) {
65
      toggleApplication()
55
      dispatch(
66
      toggleApplyModal()
56
        addNotification({
Línea 67... Línea 57...
67
    } catch (error) {
57
          styled: "danger",
68
      dispatch(addNotification({ styled: 'danger', msg: error.message }))
58
          msg: "Error al aplicar al trabajo",
69
    } finally {
59
        })
Línea 70... Línea 60...
70
      setLoading(false)
60
      );
71
    }
61
    }
72
  }
62
  };
73
 
63
 
74
  if (isLoading) {
64
  if (loading) {
Línea 75... Línea 65...
75
    return <Spinner />
65
    return <Spinner />;
76
  }
66
  }
77
 
67
 
78
  return (
68
  return (
79
    <>
69
    <>
80
      <Grid container spacing={1}>
70
      <Grid container spacing={1}>
81
        <Grid item xs md={8} display='flex' direction='column' gap={0.5}>
71
        <Grid item xs md={8} display="flex" direction="column" gap={0.5}>
82
          <JobCard job={job} />
72
          <JobCard job={job} />
83
 
73
 
84
          <JobAttr title='Visión general' info={parse(job?.job_description)} />
74
          <JobAttr title="Visión general" info={parse(job?.job_description)} />
85
          <JobAttr
75
          <JobAttr
86
            title='Último día de aplicación'
76
            title="Último día de aplicación"
87
            info={job?.last_date_of_application}
77
            info={job?.last_date_of_application}
88
          />
78
          />
Línea 89... Línea 79...
89
          <JobAttr title='Tipo de empleo' info={job?.employment_type} />
79
          <JobAttr title="Tipo de empleo" info={job?.employment_type} />
90
          <JobAttr title='Ubicación' info={job?.location} />
80
          <JobAttr title="Ubicación" info={job?.location} />
91
          <JobAttr title='Experiencia' info={job?.experience} />
81
          <JobAttr title="Experiencia" info={job?.experience} />
92
          <JobAttr title='Salario' info={job?.salary} />
82
          <JobAttr title="Salario" info={job?.salary} />
93
          <JobAttr title='Categoría' info={job?.job_category} />
83
          <JobAttr title="Categoría" info={job?.job_category} />
94
          <JobAttr title='Habilidades' info={job?.job_skills} />
84
          <JobAttr title="Habilidades" info={job?.job_skills} />
95
          <JobAttr title='Idiomas' info={job?.job_languages} />
85
          <JobAttr title="Idiomas" info={job?.job_languages} />
96
          <JobAttr title='Grados' info={job?.job_degrees} />
86
          <JobAttr title="Grados" info={job?.job_degrees} />
Línea 97... Línea 87...
97
        </Grid>
87
        </Grid>
98
 
88
 
99
        <Grid item xs md={4} display='flex' direction='column' gap={0.5}>
89
        <Grid item xs md={4} display="flex" direction="column" gap={0.5}>
Línea 114... Línea 104...
114
        profiles={job?.user_profiles}
104
        profiles={job?.user_profiles}
115
        onConfirm={apply}
105
        onConfirm={apply}
116
        onClose={toggleApplyModal}
106
        onClose={toggleApplyModal}
117
      />
107
      />
118
    </>
108
    </>
119
  )
109
  );
120
}
110
};
Línea 121... Línea 111...
121
 
111