|
1 | 1 | import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
2 | 2 | import axios from "axios";
|
3 |
| - |
| 3 | +axios.defaults.baseURL = "https://api.recruitingwebsite.online"; |
4 | 4 | const config = {
|
5 |
| - headers: { |
6 |
| - "content-type": "application/json", |
7 |
| - }, |
8 |
| - withCredentials: true, |
| 5 | + headers: { |
| 6 | + "content-type": "application/json", |
| 7 | + }, |
| 8 | + withCredentials: true, |
9 | 9 | };
|
10 | 10 |
|
11 |
| -export const createJobForms = createAsyncThunk('jobs/createJobForms', async (content, { rejectWithValue }) => { |
| 11 | +export const createJobForms = createAsyncThunk( |
| 12 | + "jobs/createJobForms", |
| 13 | + async (content, { rejectWithValue }) => { |
12 | 14 | try {
|
13 |
| - const response = await axios.post('/api/jobs/createJobForm', content, config); |
14 |
| - return response.data; |
| 15 | + const response = await axios.post( |
| 16 | + "/api/jobs/createJobForm", |
| 17 | + content, |
| 18 | + config |
| 19 | + ); |
| 20 | + return response.data; |
15 | 21 | } catch (exception) {
|
16 |
| - return rejectWithValue(exception.response?.data || exception.message); |
| 22 | + return rejectWithValue(exception.response?.data || exception.message); |
17 | 23 | }
|
18 |
| -}); |
| 24 | + } |
| 25 | +); |
19 | 26 |
|
20 |
| -export const fetchMyJobForms = createAsyncThunk("jobs/fetchMyJobForms", async (_, { rejectWithValue }) => { |
| 27 | +export const fetchMyJobForms = createAsyncThunk( |
| 28 | + "jobs/fetchMyJobForms", |
| 29 | + async (_, { rejectWithValue }) => { |
21 | 30 | try {
|
22 |
| - const response = await axios.get(`/api/jobs/fetchMyJobForms`, config); |
23 |
| - if (response.data.error === "Forms not found") { |
24 |
| - return rejectWithValue('No Jobs available.'); |
25 |
| - } |
26 |
| - return response.data; |
| 31 | + const response = await axios.get(`/api/jobs/fetchMyJobForms`, config); |
| 32 | + if (response.data.error === "Forms not found") { |
| 33 | + return rejectWithValue("No Jobs available."); |
| 34 | + } |
| 35 | + return response.data; |
27 | 36 | } catch (exception) {
|
28 |
| - return rejectWithValue(exception.response?.data || exception.message); |
| 37 | + return rejectWithValue(exception.response?.data || exception.message); |
29 | 38 | }
|
30 |
| -}); |
| 39 | + } |
| 40 | +); |
31 | 41 |
|
32 |
| -export const fetchAllJobForms = createAsyncThunk("jobs/fetchAllJobForms",async(_,{rejectWithValue})=>{ |
| 42 | +export const fetchAllJobForms = createAsyncThunk( |
| 43 | + "jobs/fetchAllJobForms", |
| 44 | + async (_, { rejectWithValue }) => { |
33 | 45 | try {
|
34 |
| - const response = await axios.get(`/api/jobs/fetchAllJobForms`, config); |
35 |
| - if (response.data.error === "Forms not found") { |
36 |
| - return rejectWithValue('No Jobs available.'); |
37 |
| - } |
38 |
| - return response.data; |
| 46 | + const response = await axios.get(`/api/jobs/fetchAllJobForms`, config); |
| 47 | + if (response.data.error === "Forms not found") { |
| 48 | + return rejectWithValue("No Jobs available."); |
| 49 | + } |
| 50 | + return response.data; |
39 | 51 | } catch (exception) {
|
40 |
| - return rejectWithValue(exception.response?.data || exception.message); |
| 52 | + return rejectWithValue(exception.response?.data || exception.message); |
41 | 53 | }
|
42 |
| -}) |
43 |
| - |
| 54 | + } |
| 55 | +); |
44 | 56 |
|
45 |
| -export const fetchJobById = createAsyncThunk('jobs/fetchJobById',async (formId, { rejectWithValue }) => { |
46 |
| - try { |
47 |
| - const response = await axios.get(`/api/jobs/fetchJobById/${formId}`,config); |
48 |
| - return response.data; |
49 |
| - } catch (exception) { |
50 |
| - return rejectWithValue(exception.response?.data || exception.message); |
51 |
| - } |
| 57 | +export const fetchJobById = createAsyncThunk( |
| 58 | + "jobs/fetchJobById", |
| 59 | + async (formId, { rejectWithValue }) => { |
| 60 | + try { |
| 61 | + const response = await axios.get( |
| 62 | + `/api/jobs/fetchJobById/${formId}`, |
| 63 | + config |
| 64 | + ); |
| 65 | + return response.data; |
| 66 | + } catch (exception) { |
| 67 | + return rejectWithValue(exception.response?.data || exception.message); |
52 | 68 | }
|
| 69 | + } |
53 | 70 | );
|
54 | 71 |
|
55 |
| -export const applyForJob = createAsyncThunk("jobs/applyForJob", async (formId, { rejectWithValue }) => { |
| 72 | +export const applyForJob = createAsyncThunk( |
| 73 | + "jobs/applyForJob", |
| 74 | + async (formId, { rejectWithValue }) => { |
56 | 75 | try {
|
57 |
| - const response = await axios.put(`/api/jobs/applyForJob`,{formId:formId},config); |
58 |
| - return response.data; |
| 76 | + const response = await axios.put( |
| 77 | + `/api/jobs/applyForJob`, |
| 78 | + { formId: formId }, |
| 79 | + config |
| 80 | + ); |
| 81 | + return response.data; |
59 | 82 | } catch (exception) {
|
60 |
| - return rejectWithValue(exception.response?.data || exception.message); |
| 83 | + return rejectWithValue(exception.response?.data || exception.message); |
61 | 84 | }
|
62 |
| -}); |
| 85 | + } |
| 86 | +); |
63 | 87 |
|
64 | 88 | const JobSlice = createSlice({
|
65 |
| - name: 'jobs', |
66 |
| - initialState: { |
67 |
| - isLoading: false, |
68 |
| - allJobForms: [], |
69 |
| - myJobForms:[], |
70 |
| - jobFormById: {}, |
71 |
| - isError: false, |
72 |
| - message: '', |
73 |
| - errorMessage: '', |
74 |
| - }, |
75 |
| - reducers: {}, |
76 |
| - extraReducers: (builder) => { |
77 |
| - builder |
78 |
| - .addCase(createJobForms.pending, (state) => { |
79 |
| - state.isLoading = true; |
80 |
| - }) |
81 |
| - .addCase(createJobForms.fulfilled, (state, action) => { |
82 |
| - state.isLoading = false; |
83 |
| - state.myJobForms.push(action.payload); |
84 |
| - }) |
85 |
| - .addCase(createJobForms.rejected, (state, action) => { |
86 |
| - state.isLoading = false; |
87 |
| - state.isError = true; |
88 |
| - state.errorMessage = action.payload; |
89 |
| - }) |
90 |
| - .addCase(fetchMyJobForms.pending, (state) => { |
91 |
| - state.isLoading = true; |
92 |
| - }) |
93 |
| - .addCase(fetchMyJobForms.fulfilled, (state, action) => { |
94 |
| - state.isLoading = false; |
95 |
| - state.myJobForms = action.payload; |
96 |
| - }) |
97 |
| - .addCase(fetchMyJobForms.rejected, (state, action) => { |
98 |
| - state.isLoading = false; |
99 |
| - state.isError = true; |
100 |
| - state.errorMessage = action.payload; |
101 |
| - }) |
102 |
| - .addCase(fetchAllJobForms.pending, (state) => { |
103 |
| - state.isLoading = true; |
104 |
| - }) |
105 |
| - .addCase(fetchAllJobForms.fulfilled, (state, action) => { |
106 |
| - state.isLoading = false; |
107 |
| - state.allJobForms = action.payload; |
108 |
| - }) |
109 |
| - .addCase(fetchAllJobForms.rejected, (state, action) => { |
110 |
| - state.isLoading = false; |
111 |
| - state.isError = true; |
112 |
| - state.errorMessage = action.payload; |
113 |
| - }) |
114 |
| - .addCase(fetchJobById.pending, (state) => { |
115 |
| - state.isLoading = true; |
116 |
| - }) |
117 |
| - .addCase(fetchJobById.fulfilled, (state, action) => { |
118 |
| - state.isLoading = false; |
119 |
| - state.jobFormById = action.payload; |
120 |
| - }) |
121 |
| - .addCase(fetchJobById.rejected, (state, action) => { |
122 |
| - state.isLoading = false; |
123 |
| - state.isError = true; |
124 |
| - state.errorMessage = action.payload; |
125 |
| - }) |
126 |
| - .addCase(applyForJob.pending, (state) => { |
127 |
| - state.isLoading = true; |
128 |
| - }) |
129 |
| - .addCase(applyForJob.fulfilled, (state, action) => { |
130 |
| - state.isLoading = false; |
131 |
| - state.message = "Successfully Applied.."; |
132 |
| - }) |
133 |
| - .addCase(applyForJob.rejected, (state, action) => { |
134 |
| - state.isLoading = false; |
135 |
| - state.isError = true; |
136 |
| - state.errorMessage = action.payload; |
137 |
| - }); |
138 |
| - } |
| 89 | + name: "jobs", |
| 90 | + initialState: { |
| 91 | + isLoading: false, |
| 92 | + allJobForms: [], |
| 93 | + myJobForms: [], |
| 94 | + jobFormById: {}, |
| 95 | + isError: false, |
| 96 | + message: "", |
| 97 | + errorMessage: "", |
| 98 | + }, |
| 99 | + reducers: {}, |
| 100 | + extraReducers: (builder) => { |
| 101 | + builder |
| 102 | + .addCase(createJobForms.pending, (state) => { |
| 103 | + state.isLoading = true; |
| 104 | + }) |
| 105 | + .addCase(createJobForms.fulfilled, (state, action) => { |
| 106 | + state.isLoading = false; |
| 107 | + state.myJobForms.push(action.payload); |
| 108 | + }) |
| 109 | + .addCase(createJobForms.rejected, (state, action) => { |
| 110 | + state.isLoading = false; |
| 111 | + state.isError = true; |
| 112 | + state.errorMessage = action.payload; |
| 113 | + }) |
| 114 | + .addCase(fetchMyJobForms.pending, (state) => { |
| 115 | + state.isLoading = true; |
| 116 | + }) |
| 117 | + .addCase(fetchMyJobForms.fulfilled, (state, action) => { |
| 118 | + state.isLoading = false; |
| 119 | + state.myJobForms = action.payload; |
| 120 | + }) |
| 121 | + .addCase(fetchMyJobForms.rejected, (state, action) => { |
| 122 | + state.isLoading = false; |
| 123 | + state.isError = true; |
| 124 | + state.errorMessage = action.payload; |
| 125 | + }) |
| 126 | + .addCase(fetchAllJobForms.pending, (state) => { |
| 127 | + state.isLoading = true; |
| 128 | + }) |
| 129 | + .addCase(fetchAllJobForms.fulfilled, (state, action) => { |
| 130 | + state.isLoading = false; |
| 131 | + state.allJobForms = action.payload; |
| 132 | + }) |
| 133 | + .addCase(fetchAllJobForms.rejected, (state, action) => { |
| 134 | + state.isLoading = false; |
| 135 | + state.isError = true; |
| 136 | + state.errorMessage = action.payload; |
| 137 | + }) |
| 138 | + .addCase(fetchJobById.pending, (state) => { |
| 139 | + state.isLoading = true; |
| 140 | + }) |
| 141 | + .addCase(fetchJobById.fulfilled, (state, action) => { |
| 142 | + state.isLoading = false; |
| 143 | + state.jobFormById = action.payload; |
| 144 | + }) |
| 145 | + .addCase(fetchJobById.rejected, (state, action) => { |
| 146 | + state.isLoading = false; |
| 147 | + state.isError = true; |
| 148 | + state.errorMessage = action.payload; |
| 149 | + }) |
| 150 | + .addCase(applyForJob.pending, (state) => { |
| 151 | + state.isLoading = true; |
| 152 | + }) |
| 153 | + .addCase(applyForJob.fulfilled, (state, action) => { |
| 154 | + state.isLoading = false; |
| 155 | + state.message = "Successfully Applied.."; |
| 156 | + }) |
| 157 | + .addCase(applyForJob.rejected, (state, action) => { |
| 158 | + state.isLoading = false; |
| 159 | + state.isError = true; |
| 160 | + state.errorMessage = action.payload; |
| 161 | + }); |
| 162 | + }, |
139 | 163 | });
|
140 | 164 |
|
141 | 165 | export default JobSlice.reducer;
|
0 commit comments