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: (callback) => {
|
---|
50 | return dispatch => {
|
---|
51 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
52 | axios.get("/my-applications/" + currentUser.id)
|
---|
53 | .then(response => {
|
---|
54 | dispatch({
|
---|
55 | type: FETCH_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
56 | applicationsByJobSeeker: response.data
|
---|
57 | })
|
---|
58 | callback(true, response)
|
---|
59 | }).catch(error => {
|
---|
60 | callback(false, error)
|
---|
61 | })
|
---|
62 | }
|
---|
63 | },
|
---|
64 |
|
---|
65 | fetchApplicationsByJobAdId: (jobAdId, callback) => {
|
---|
66 | return dispatch => {
|
---|
67 | axios.get("/job-advertisements/" + jobAdId + "/applications")
|
---|
68 | .then(response => {
|
---|
69 | dispatch({
|
---|
70 | type: FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
71 | applicationsByJobAdId: response.data
|
---|
72 | })
|
---|
73 | callback(true, response)
|
---|
74 | }
|
---|
75 | ).catch(error => {
|
---|
76 | callback(false, error)
|
---|
77 | })
|
---|
78 | }
|
---|
79 | },
|
---|
80 | downloadResume: (fileName, callback) => {
|
---|
81 | return dispatch => {
|
---|
82 | return axios.get("/resume/" + fileName, {responseType: "blob"})
|
---|
83 | .then(response => {
|
---|
84 | const blob = new Blob([response.data], { type: 'application/pdf' });
|
---|
85 | const url = window.URL.createObjectURL(blob);
|
---|
86 | callback(true, url);
|
---|
87 | })
|
---|
88 |
|
---|
89 | .catch(error => {
|
---|
90 | callback(false, error)
|
---|
91 | })
|
---|
92 | }
|
---|
93 | }
|
---|
94 | } |
---|