Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3416 Rev 3432
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 17... Línea 20...
17
  const [showApplyModal, setShowApplyModal] = useState(false);
20
  const dispatch = useDispatch()
18
 
21
 
Línea 19... Línea -...
19
  const { uuid } = useParams();
-
 
20
  const dispatch = useDispatch();
-
 
21
 
-
 
22
  const { data: job, loading, mutate } = useFetch(`/job/view/${uuid}`);
22
  const { data: job, isLoading, 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'
30
      job_apply_operation: isJobApplied ? "apply" : "remove-apply",
31
    })
31
    });
-
 
32
  };
32
  }
33
 
-
 
34
  const removeApply = async () => {
33
 
35
    try {
34
  const removeApply = async () => {
36
      const response = await axios.post(
35
    setLoading(true)
37
        `/job/remove-apply-job/${job.job_uuid}`
36
    try {
38
      );
37
      const response = await axios.post(`/job/remove-apply-job/${job.job_uuid}`)
39
      const { data, success } = response.data;
38
      const { data, success } = response.data
-
 
39
      if (!success) throw new Error('Error al eliminar la aplicación')
-
 
40
      dispatch(addNotification({ style: 'success', msg: data }))
40
      if (!success) throw new Error("Error al eliminar la aplicación");
41
      toggleApplication()
41
      dispatch(addNotification({ style: "success", msg: data }));
42
    } catch (error) {
-
 
43
      dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
44
    } finally {
-
 
45
      setLoading(false)
Línea 42... Línea -...
42
      toggleApplication();
-
 
43
    } catch (error) {
46
    }
44
      dispatch(addNotification({ style: "danger", msg: error.message }));
47
  }
-
 
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
      )
45
    }
58
 
46
  };
59
      const response = await axios.post(url, formData)
47
 
60
      const { data, success } = response.data
48
  const apply = async (apply) => {
61
 
49
    try {
-
 
50
      const msg = await axios.post(`/job/apply-job/${job.job_uuid}`, apply);
-
 
51
      dispatch(addNotification({ style: "success", msg }));
-
 
52
      toggleApplication();
62
      if (!success) throw new Error('Error al aplicar al trabajo')
53
      toggleApplyModal();
63
 
54
    } catch (error) {
64
      dispatch(addNotification({ style: 'success', msg: data }))
55
      dispatch(
65
      toggleApplication()
56
        addNotification({
66
      toggleApplyModal()
Línea 57... Línea 67...
57
          styled: "danger",
67
    } catch (error) {
58
          msg: "Error al aplicar al trabajo",
68
      dispatch(addNotification({ styled: 'danger', msg: error.message }))
59
        })
69
    } finally {
Línea 60... Línea 70...
60
      );
70
      setLoading(false)
61
    }
71
    }
62
  };
72
  }
63
 
73
 
64
  if (loading) {
74
  if (isLoading) {
Línea 65... Línea 75...
65
    return <Spinner />;
75
    return <Spinner />
66
  }
76
  }
67
 
77
 
68
  return (
78
  return (
69
    <>
79
    <>
70
      <Grid container spacing={1}>
80
      <Grid container spacing={1}>
71
        <Grid item xs md={8} display="flex" direction="column" gap={0.5}>
81
        <Grid item xs md={8} display='flex' direction='column' gap={0.5}>
72
          <JobCard job={job} />
82
          <JobCard job={job} />
73
 
83
 
74
          <JobAttr title="Visión general" info={parse(job?.job_description)} />
84
          <JobAttr title='Visión general' info={parse(job?.job_description)} />
75
          <JobAttr
85
          <JobAttr
76
            title="Último día de aplicación"
86
            title='Último día de aplicación'
77
            info={job?.last_date_of_application}
87
            info={job?.last_date_of_application}
78
          />
88
          />
Línea 79... Línea 89...
79
          <JobAttr title="Tipo de empleo" info={job?.employment_type} />
89
          <JobAttr title='Tipo de empleo' info={job?.employment_type} />
80
          <JobAttr title="Ubicación" info={job?.location} />
90
          <JobAttr title='Ubicación' info={job?.location} />
81
          <JobAttr title="Experiencia" info={job?.experience} />
91
          <JobAttr title='Experiencia' info={job?.experience} />
82
          <JobAttr title="Salario" info={job?.salary} />
92
          <JobAttr title='Salario' info={job?.salary} />
83
          <JobAttr title="Categoría" info={job?.job_category} />
93
          <JobAttr title='Categoría' info={job?.job_category} />
84
          <JobAttr title="Habilidades" info={job?.job_skills} />
94
          <JobAttr title='Habilidades' info={job?.job_skills} />
85
          <JobAttr title="Idiomas" info={job?.job_languages} />
95
          <JobAttr title='Idiomas' info={job?.job_languages} />
86
          <JobAttr title="Grados" info={job?.job_degrees} />
96
          <JobAttr title='Grados' info={job?.job_degrees} />
Línea 87... Línea 97...
87
        </Grid>
97
        </Grid>
88
 
98
 
89
        <Grid item xs md={4} display="flex" direction="column" gap={0.5}>
99
        <Grid item xs md={4} display='flex' direction='column' gap={0.5}>
Línea 104... Línea 114...
104
        profiles={job?.user_profiles}
114
        profiles={job?.user_profiles}
105
        onConfirm={apply}
115
        onConfirm={apply}
106
        onClose={toggleApplyModal}
116
        onClose={toggleApplyModal}
107
      />
117
      />
108
    </>
118
    </>
109
  );
119
  )
110
};
120
}
Línea 111... Línea 121...
111
 
121