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("/job-advertisements/apply", 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 | },
|
---|
30 | updateApplicationStatus: (id, status, callback) => {
|
---|
31 | console.log(status)
|
---|
32 | return dispatch => {
|
---|
33 | // TO DO: REFACTOR
|
---|
34 | axios.post("/applications/" + id + "/update", {
|
---|
35 | id: id,
|
---|
36 | status: status
|
---|
37 | })
|
---|
38 | .then(response => {
|
---|
39 | dispatch({
|
---|
40 | type: UPDATE_APPLICATION_STATUS,
|
---|
41 | application: response.data,
|
---|
42 | })
|
---|
43 | callback(true, response)
|
---|
44 | }).catch(error => {
|
---|
45 | callback(false, error)
|
---|
46 | })
|
---|
47 | }
|
---|
48 | },
|
---|
49 | fetchApplicationsByJobSeeker: (jobSeekerId, callback) => {
|
---|
50 | return dispatch => {
|
---|
51 | axios.get("/my-applications/" + jobSeekerId)
|
---|
52 | .then(response => {
|
---|
53 | dispatch({
|
---|
54 | type: FETCH_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
55 | applicationsByJobSeeker: response.data
|
---|
56 | })
|
---|
57 | callback(true, response)
|
---|
58 | }).catch(error => {
|
---|
59 | callback(false, error)
|
---|
60 | })
|
---|
61 | }
|
---|
62 | },
|
---|
63 |
|
---|
64 | fetchApplicationsByJobAdId: (jobAdId, callback) => {
|
---|
65 | return dispatch => {
|
---|
66 | axios.get("/job-advertisements/" + jobAdId + "/applications")
|
---|
67 | .then(response => {
|
---|
68 | dispatch({
|
---|
69 | type: FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
70 | applicationsByJobAdId: response.data
|
---|
71 | })
|
---|
72 | callback(true, response)
|
---|
73 | }
|
---|
74 | ).catch(error => {
|
---|
75 | callback(false, error)
|
---|
76 | })
|
---|
77 | }
|
---|
78 | },
|
---|
79 | downloadResume: (fileName, callback) => {
|
---|
80 | return dispatch => {
|
---|
81 | return axios.get("/resume/" + fileName, {responseType: "blob"})
|
---|
82 | .then(response => {
|
---|
83 | const blob = new Blob([response.data], { type: 'application/pdf' });
|
---|
84 | const url = window.URL.createObjectURL(blob);
|
---|
85 | callback(true, url);
|
---|
86 | })
|
---|
87 |
|
---|
88 | .catch(error => {
|
---|
89 | callback(false, error)
|
---|
90 | })
|
---|
91 | }
|
---|
92 | }
|
---|
93 | } |
---|