[28b3398] | 1 | import axios from "../../axios/axiosInstance";
|
---|
| 2 | import {
|
---|
| 3 | CURRENT_USER,
|
---|
| 4 | FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
[4d97b63] | 5 | FETCH_APPLICATIONS_BY_JOB_SEEKER_ID, FILTER_APPLICATIONS_BY_JOB_ID, FILTER_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
| 6 | SUBMIT_APPLICATION, UPDATE_APPLICATION, UPDATE_APPLICATION_STATUS, UPDATE_APPLICATIONS
|
---|
[28b3398] | 7 | } from "../actionTypes";
|
---|
| 8 |
|
---|
| 9 | export const ApplicationActions = {
|
---|
| 10 | submitApplication: (application, callback) => {
|
---|
| 11 | return dispatch => {
|
---|
[08f82ec] | 12 | axios.post("/applications/submit", application, {
|
---|
[28b3398] | 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 | },
|
---|
[4d97b63] | 29 |
|
---|
| 30 | updateApplication: (applicationId, additionalFiles, callback) => {
|
---|
| 31 | console.log(additionalFiles)
|
---|
| 32 | return dispatch => {
|
---|
| 33 | axios.post("/applications/"+ applicationId + "/update", additionalFiles, {
|
---|
| 34 | headers: {
|
---|
| 35 | 'Content-Type': 'multipart/form-data'
|
---|
| 36 | }
|
---|
| 37 | })
|
---|
| 38 | .then(response => {
|
---|
| 39 | dispatch({
|
---|
| 40 | type: UPDATE_APPLICATION,
|
---|
| 41 | application: response.data
|
---|
| 42 | })
|
---|
| 43 | callback(true, response)
|
---|
| 44 | }).catch(error => {
|
---|
| 45 | callback(false, error)
|
---|
| 46 | console.log(error)
|
---|
| 47 | })
|
---|
| 48 | }
|
---|
| 49 | },
|
---|
[28b3398] | 50 | updateApplicationStatus: (id, status, callback) => {
|
---|
| 51 | console.log(status)
|
---|
[08f82ec] | 52 | return dispatch => {
|
---|
| 53 | axios.post("/applications/" + id + "/update", {
|
---|
| 54 | id: id,
|
---|
| 55 | status: status
|
---|
| 56 | })
|
---|
| 57 | .then(response => {
|
---|
| 58 | dispatch({
|
---|
| 59 | type: UPDATE_APPLICATION_STATUS,
|
---|
| 60 | application: response.data,
|
---|
| 61 | })
|
---|
| 62 | callback(true, response)
|
---|
| 63 | }).catch(error => {
|
---|
| 64 | callback(false, error)
|
---|
| 65 | })
|
---|
| 66 | }
|
---|
[28b3398] | 67 | },
|
---|
[4d97b63] | 68 |
|
---|
| 69 | updateApplications: (changes, callback) => {
|
---|
| 70 | return dispatch => {
|
---|
| 71 | axios.post("/applications/update", changes)
|
---|
| 72 | .then(response => {
|
---|
| 73 | dispatch({
|
---|
| 74 | type: UPDATE_APPLICATIONS,
|
---|
| 75 | applications: response.data
|
---|
| 76 | })
|
---|
| 77 | callback(true, response)
|
---|
| 78 | }).catch(error => {
|
---|
| 79 | callback(false, error)
|
---|
| 80 | })
|
---|
| 81 | }
|
---|
| 82 | },
|
---|
| 83 |
|
---|
[befb988] | 84 | fetchApplicationsByJobSeeker: (jobSeekerId, callback) => {
|
---|
[08f82ec] | 85 | return dispatch => {
|
---|
| 86 | axios.get("/my-applications/" + jobSeekerId)
|
---|
| 87 | .then(response => {
|
---|
| 88 | dispatch({
|
---|
| 89 | type: FETCH_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
| 90 | applicationsByJobSeeker: response.data
|
---|
| 91 | })
|
---|
| 92 | callback(true, response)
|
---|
| 93 | }).catch(error => {
|
---|
| 94 | callback(false, error)
|
---|
| 95 | })
|
---|
| 96 | }
|
---|
[28b3398] | 97 | },
|
---|
| 98 |
|
---|
[4d97b63] | 99 | filterApplicationsByJobSeeker: (jobSeekerId, status, callback) => {
|
---|
| 100 | return dispatch => {
|
---|
| 101 | axios.post("/my-applications/" + jobSeekerId + "/filtered", status)
|
---|
| 102 | .then(response => {
|
---|
| 103 | dispatch({
|
---|
| 104 | type: FILTER_APPLICATIONS_BY_JOB_SEEKER_ID,
|
---|
| 105 | applicationsByJobSeeker: response.data
|
---|
| 106 | })
|
---|
| 107 | callback(true, response)
|
---|
| 108 | }).catch(error => {
|
---|
| 109 | callback(false, error)
|
---|
| 110 | })
|
---|
| 111 | }
|
---|
| 112 | },
|
---|
| 113 |
|
---|
[28b3398] | 114 | fetchApplicationsByJobAdId: (jobAdId, callback) => {
|
---|
| 115 | return dispatch => {
|
---|
| 116 | axios.get("/job-advertisements/" + jobAdId + "/applications")
|
---|
| 117 | .then(response => {
|
---|
| 118 | dispatch({
|
---|
| 119 | type: FETCH_APPLICATIONS_BY_JOB_ID,
|
---|
| 120 | applicationsByJobAdId: response.data
|
---|
| 121 | })
|
---|
| 122 | callback(true, response)
|
---|
| 123 | }
|
---|
| 124 | ).catch(error => {
|
---|
| 125 | callback(false, error)
|
---|
| 126 | })
|
---|
| 127 | }
|
---|
| 128 | },
|
---|
[4d97b63] | 129 |
|
---|
| 130 | filterApplicationsByJobAdId: (jobAdId, status, callback) => {
|
---|
| 131 | return dispatch => {
|
---|
| 132 | axios.post("/job-advertisements/" + jobAdId + "/applications/filtered", status)
|
---|
| 133 | .then(response => {
|
---|
| 134 | dispatch({
|
---|
| 135 | type: FILTER_APPLICATIONS_BY_JOB_ID,
|
---|
| 136 | applicationsByJobAdId: response.data
|
---|
| 137 | })
|
---|
| 138 | callback(true, response)
|
---|
| 139 | }
|
---|
| 140 | ).catch(error => {
|
---|
| 141 | callback(false, error)
|
---|
| 142 | })
|
---|
| 143 | }
|
---|
| 144 | },
|
---|
[08f82ec] | 145 | downloadResume: (id, callback) => {
|
---|
| 146 | return axios.get("/applications/" + id + "/download-resume", {responseType: "blob"})
|
---|
| 147 | .then(response => {
|
---|
| 148 | const blob = new Blob([response.data], {type: 'application/pdf'});
|
---|
| 149 | const url = window.URL.createObjectURL(blob);
|
---|
| 150 | callback(true, url);
|
---|
| 151 | })
|
---|
| 152 | .catch(error => {
|
---|
| 153 | callback(false, error)
|
---|
| 154 | })
|
---|
[28b3398] | 155 |
|
---|
[4d97b63] | 156 | },
|
---|
| 157 | downloadAdditionalFiles: (id, callback) => {
|
---|
| 158 | return axios.get("/applications/" + id + "/download-additional-files")
|
---|
| 159 | .then(response => {
|
---|
| 160 | const urls = response.data; // This will be a list of URLs
|
---|
| 161 | callback(true, urls);
|
---|
| 162 | })
|
---|
| 163 | .catch(error => {
|
---|
| 164 | callback(false, error);
|
---|
| 165 | });
|
---|
| 166 |
|
---|
[28b3398] | 167 | }
|
---|
| 168 | } |
---|