|
1 | 1 | import axios from "axios"; |
2 | 2 | import { errorHandler } from "../utils/errorHandler"; |
3 | 3 | import { setRequestStatus } from "../utils/setRequestStatus"; |
4 | | -import { CREATE_PROPOSAL, GET_PROPOSAL } from "../actions/types"; |
| 4 | +import { |
| 5 | + CREATE_PROPOSAL, |
| 6 | + GET_PROPOSAL, |
| 7 | + GET_USER_PROPOSAL_NOTIFICATIONS, |
| 8 | + GET_ALL_PROPOSALS, |
| 9 | + GET_USER_PROPOSALS, |
| 10 | +} from "../actions/types"; |
5 | 11 |
|
6 | 12 | // CREATE PROPOSAL |
7 | 13 | export const createProposal = (proposalInfo) => async (dispatch) => { |
8 | 14 | try { |
9 | | - console.log("proposalInfo", proposalInfo); |
10 | 15 | const res = await axios.post("/proposal", proposalInfo); |
11 | 16 | dispatch(setRequestStatus(false)); |
12 | 17 | if (res.status === 201) { |
@@ -39,3 +44,116 @@ export const getProposal = (proposalId) => async (dispatch) => { |
39 | 44 | dispatch(errorHandler(error)); |
40 | 45 | } |
41 | 46 | }; |
| 47 | + |
| 48 | +// SAVE PROPOSAL DATA |
| 49 | +export const saveProposal = (proposalData) => async (dispatch) => { |
| 50 | + try { |
| 51 | + const res = await axios.patch( |
| 52 | + "/proposal/" + proposalData.proposalId, |
| 53 | + proposalData |
| 54 | + ); |
| 55 | + dispatch(setRequestStatus(false)); |
| 56 | + if (res.status === 200) { |
| 57 | + dispatch(setRequestStatus(true)); |
| 58 | + } |
| 59 | + } catch (error) { |
| 60 | + dispatch(errorHandler(error)); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +// SUBMIT PROPOSAL |
| 65 | +export const submitProposal = (proposalData) => async (dispatch) => { |
| 66 | + console.log(proposalData); |
| 67 | + try { |
| 68 | + const res = await axios.patch( |
| 69 | + "/proposal/change/" + proposalData.proposalId, |
| 70 | + proposalData |
| 71 | + ); |
| 72 | + dispatch(setRequestStatus(false)); |
| 73 | + if (res.status === 200) { |
| 74 | + dispatch(setRequestStatus(true)); |
| 75 | + } |
| 76 | + } catch (error) { |
| 77 | + dispatch(errorHandler(error)); |
| 78 | + } |
| 79 | +}; |
| 80 | + |
| 81 | +// DELETE PROPOSAL |
| 82 | +export const deleteProposal = (proposalId) => async (dispatch) => { |
| 83 | + try { |
| 84 | + const res = await axios.delete("/proposal", { |
| 85 | + headers: {}, |
| 86 | + data: { proposalId: proposalId }, |
| 87 | + }); |
| 88 | + dispatch(setRequestStatus(false)); |
| 89 | + if (res.status === 200) { |
| 90 | + dispatch(setRequestStatus(true)); |
| 91 | + } |
| 92 | + } catch (error) { |
| 93 | + dispatch(errorHandler(error)); |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +// COMMENT ON PROPOSAL |
| 98 | +export const commentProposal = (commentData) => async (dispatch) => { |
| 99 | + try { |
| 100 | + const res = await axios.post("/proposal/comment", commentData); |
| 101 | + dispatch(setRequestStatus(false)); |
| 102 | + if (res.status === 200) { |
| 103 | + dispatch(setRequestStatus(true)); |
| 104 | + } |
| 105 | + } catch (error) { |
| 106 | + dispatch(errorHandler(error)); |
| 107 | + } |
| 108 | +}; |
| 109 | + |
| 110 | +// GET USER RELATED PROPOSAL NOTIFICATIONS |
| 111 | +export const getUserProposalNotifications = (data) => async (dispatch) => { |
| 112 | + try { |
| 113 | + const res = await axios.post("/proposal/notifications", data); |
| 114 | + console.log(res); |
| 115 | + if (res.status === 200) { |
| 116 | + dispatch(setRequestStatus(true)); |
| 117 | + dispatch({ |
| 118 | + type: GET_USER_PROPOSAL_NOTIFICATIONS, |
| 119 | + payload: res.data.proposal || res.data.msg, |
| 120 | + }); |
| 121 | + } |
| 122 | + } catch (error) { |
| 123 | + dispatch(errorHandler(error)); |
| 124 | + } |
| 125 | +}; |
| 126 | + |
| 127 | +// GET ALL PROPOSALS |
| 128 | +export const getAllProposals = () => async (dispatch) => { |
| 129 | + try { |
| 130 | + const res = await axios.post("/proposal/all"); |
| 131 | + dispatch(setRequestStatus(false)); |
| 132 | + if (res.status === 200) { |
| 133 | + dispatch(setRequestStatus(true)); |
| 134 | + dispatch({ |
| 135 | + type: GET_ALL_PROPOSALS, |
| 136 | + payload: res.data.proposals || res.data.msg, |
| 137 | + }); |
| 138 | + } |
| 139 | + } catch (error) { |
| 140 | + dispatch(errorHandler(error)); |
| 141 | + } |
| 142 | +}; |
| 143 | + |
| 144 | +// GET PROPOSALS BY USER ID |
| 145 | +export const getProposalsByUser = (userId) => async (dispatch) => { |
| 146 | + try { |
| 147 | + const res = await axios.get(`/proposal/user/${userId}`); |
| 148 | + dispatch(setRequestStatus(false)); |
| 149 | + if (res.status === 200) { |
| 150 | + dispatch(setRequestStatus(true)); |
| 151 | + dispatch({ |
| 152 | + type: GET_USER_PROPOSALS, |
| 153 | + payload: res.data.proposal || res.data.msg, |
| 154 | + }); |
| 155 | + } |
| 156 | + } catch (error) { |
| 157 | + dispatch(errorHandler(error)); |
| 158 | + } |
| 159 | +}; |
0 commit comments