1 | import axios from "../../axios/axiosInstance";
|
---|
2 | import {
|
---|
3 | CURRENT_USER,
|
---|
4 | FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
5 | FETCH_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
6 | SUBMIT_APPLICATION, UPDATE_APPLICATION_STATUS
|
---|
7 | } from "../actionTypes";
|
---|
8 |
|
---|
9 | export const ApplicationActions = {
|
---|
10 | submitApplication: (application, callback) => {
|
---|
11 | return dispatch => {
|
---|
12 | axios.post("/applications/submit", application, {
|
---|
13 | headers: {
|
---|
14 | 'Content-Type': 'multipart/form-data'
|
---|
15 | }
|
---|
16 | })
|
---|
17 | .then(response => {
|
---|
18 | dispatch({
|
---|
19 | type: SUBMIT_APPLICATION,
|
---|
20 | application: response.data
|
---|
21 | })
|
---|
22 | callback(true, response)
|
---|
23 | }).catch(error => {
|
---|
24 | callback(false, error)
|
---|
25 | console.log(error)
|
---|
26 | })
|
---|
27 | }
|
---|
28 | },
|
---|
29 | updateApplicationStatus: (id, status, callback) => {
|
---|
30 | console.log(status)
|
---|
31 | return dispatch => {
|
---|
32 | axios.post("/applications/" + id + "/update", {
|
---|
33 | id: id,
|
---|
34 | status: status
|
---|
35 | })
|
---|
36 | .then(response => {
|
---|
37 | dispatch({
|
---|
38 | type: UPDATE_APPLICATION_STATUS,
|
---|
39 | application: response.data,
|
---|
40 | })
|
---|
41 | callback(true, response)
|
---|
42 | }).catch(error => {
|
---|
43 | callback(false, error)
|
---|
44 | })
|
---|
45 | }
|
---|
46 | },
|
---|
47 | fetchApplicationsByJobSeeker: (jobSeekerId, callback) => {
|
---|
48 | return dispatch => {
|
---|
49 | axios.get("/my-applications/" + jobSeekerId)
|
---|
50 | .then(response => {
|
---|
51 | dispatch({
|
---|
52 | type: FETCH_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
53 | applicationsByJobSeeker: response.data
|
---|
54 | })
|
---|
55 | callback(true, response)
|
---|
56 | }).catch(error => {
|
---|
57 | callback(false, error)
|
---|
58 | })
|
---|
59 | }
|
---|
60 | },
|
---|
61 |
|
---|
62 | fetchApplicationsByJobAdId: (jobAdId, callback) => {
|
---|
63 | return dispatch => {
|
---|
64 | axios.get("/job-advertisements/" + jobAdId + "/applications")
|
---|
65 | .then(response => {
|
---|
66 | dispatch({
|
---|
67 | type: FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
68 | applicationsByJobAdId: response.data
|
---|
69 | })
|
---|
70 | callback(true, response)
|
---|
71 | }
|
---|
72 | ).catch(error => {
|
---|
73 | callback(false, error)
|
---|
74 | })
|
---|
75 | }
|
---|
76 | },
|
---|
77 | downloadResume: (id, callback) => {
|
---|
78 | return axios.get("/applications/" + id + "/download-resume", {responseType: "blob"})
|
---|
79 | .then(response => {
|
---|
80 | const blob = new Blob([response.data], {type: 'application/pdf'});
|
---|
81 | const url = window.URL.createObjectURL(blob);
|
---|
82 | callback(true, url);
|
---|
83 | })
|
---|
84 | .catch(error => {
|
---|
85 | callback(false, error)
|
---|
86 | })
|
---|
87 |
|
---|
88 | }
|
---|
89 | } |
---|