| 91 | // Create or update profile |
| 92 | export const createProfile = |
| 93 | (formData, edit = false) => |
| 94 | async (dispatch) => { |
| 95 | try { |
| 96 | const res = await api.post('/profile', formData); |
| 97 | |
| 98 | dispatch({ |
| 99 | type: GET_PROFILE, |
| 100 | payload: res.data |
| 101 | }); |
| 102 | |
| 103 | dispatch( |
| 104 | setAlert(edit ? 'Profile Updated' : 'Profile Created', 'success') |
| 105 | ); |
| 106 | } catch (err) { |
| 107 | const errors = err.response.data.errors; |
| 108 | |
| 109 | if (errors) { |
| 110 | errors.forEach((error) => dispatch(setAlert(error.msg, 'danger'))); |
| 111 | } |
| 112 | |
| 113 | dispatch({ |
| 114 | type: PROFILE_ERROR, |
| 115 | payload: { msg: err.response.statusText, status: err.response.status } |
| 116 | }); |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | // Add Experience |
| 121 | export const addExperience = (formData) => async (dispatch) => { |