diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f948237..0e82108 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -22,7 +22,7 @@ jobs: - run: yarn install --frozen-lockfile - run: yarn run build --if-present - run: yarn test - env: + env: REACT_APP_BACKEND_URL: ${{ secrets.REACT_APP_BACKEND_URL }} - name: Coveralls GitHub Action uses: coverallsapp/github-action@v1.1.2 diff --git a/Assets/forgot.png b/Assets/forgot.png new file mode 100644 index 0000000..001ddc9 Binary files /dev/null and b/Assets/forgot.png differ diff --git a/Assets/reset.png b/Assets/reset.png new file mode 100644 index 0000000..d2f1edc Binary files /dev/null and b/Assets/reset.png differ diff --git a/package.json b/package.json index 764754b..786b690 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@fortawesome/free-brands-svg-icons": "^5.15.1", "@fortawesome/free-regular-svg-icons": "^5.15.1", "@fortawesome/free-solid-svg-icons": "^5.15.1", - "@fortawesome/react-fontawesome": "^0.1.12", + "@fortawesome/react-fontawesome": "^0.1.13", "axios": "^0.21.0", "babel-loader": "8.0.6", "babel-plugin-transform-class-properties": "^6.24.1", diff --git a/redux/actions/forgotPassword.js b/redux/actions/forgotPassword.js new file mode 100644 index 0000000..afb90da --- /dev/null +++ b/redux/actions/forgotPassword.js @@ -0,0 +1,23 @@ +import * as actions from "./types"; +import http from '../../src/utils/axios'; + +export const forgotAction = (data) => (dispatch) =>{ + dispatch({ type: actions.SET_FORGOT_LOADING }); + http.post( + "/api/forgotPassword", + data + ) + + .then((res) => { + dispatch({ + type: actions.SET_FORGOT_SUCCESS, + payload: res.data.message, + }); + }) + .catch((error) => { + dispatch({ + type: actions.SET_FORGOT_ERROR, + payload: error.response.data.err, + }); + }); +}; diff --git a/redux/actions/resetPassword.js b/redux/actions/resetPassword.js new file mode 100644 index 0000000..71866dd --- /dev/null +++ b/redux/actions/resetPassword.js @@ -0,0 +1,24 @@ +import * as actions from "./types"; +import http from '../../src/utils/axios'; + +export const resetAction = (data) => (dispatch) => { + let token = data.token.token + let password = data.password + let confirmPassword = data.confirmPassword + let resetData = {password, confirmPassword} + dispatch({ type: actions.SET_RESET_LOADING }); + http + .post(`/api/resetPassword/${token}`, resetData) + .then((res) => { + dispatch({ + type: actions.SET_RESET_SUCCESS, + payload: res.data.message, + }); + }) + .catch((error) => { + dispatch({ + type: actions.SET_RESET_INVALID, + payload: error.response.data.err, + }); + }); +}; diff --git a/redux/actions/types.js b/redux/actions/types.js index 370a4f3..45fba6b 100644 --- a/redux/actions/types.js +++ b/redux/actions/types.js @@ -20,3 +20,10 @@ export const SET_RESOLVED = "SET_RESOLVED"; export const SET_SUCCESS = "SET_SUCCESS"; export const GET_REQUESTS= 'GET_REQUESTS' export const GET_REQUESTS_ERROR= 'GET_REQUESTS_ERROR' +export const SET_FORGOT_LOADING = 'SET_FORGOT_LOADING'; +export const SET_FORGOT_ERROR = 'SET_FORGOT_ERROR'; +export const SET_FORGOT_SUCCESS = 'SET_FORGOT_SUCCESS'; +export const SET_RESET_INVALID = 'SET_RESET_INVALID'; +export const SET_RESET_ERROR = 'SET_RESET_ERROR'; +export const SET_RESET_SUCCESS = 'SET_RESET_SUCCESS'; +export const SET_RESET_LOADING = 'SET_RESET_LOADING'; diff --git a/redux/reducers/forgotPassword.js b/redux/reducers/forgotPassword.js new file mode 100644 index 0000000..67f5ea4 --- /dev/null +++ b/redux/reducers/forgotPassword.js @@ -0,0 +1,31 @@ +import * as actions from "../actions/types"; + +const initialState = { + error: null, + message: null, + loading: false, +}; + +export default (state = initialState, action) => { + switch (action.type) { + case actions.SET_FORGOT_LOADING: + return { + ...state, + loading: true, + }; + case actions.SET_FORGOT_ERROR: + return { + ...state, + error: action.payload, + loading: false, + }; + case actions.SET_FORGOT_SUCCESS: + return { + ...state, + message: action.payload, + loading: false, + }; + default: + return state; + } +}; diff --git a/redux/reducers/index.js b/redux/reducers/index.js index 32eaa5e..1b1cc94 100644 --- a/redux/reducers/index.js +++ b/redux/reducers/index.js @@ -9,6 +9,8 @@ import users from "./users"; import statuses from "./statuses"; import alerts from "./alerts"; import adminRequests from './adminRequests' +import forgot from './forgotPassword'; +import resetPassword from './resetPassword' // function that contains all reducer objects. const allReducers = combineReducers({ @@ -22,7 +24,9 @@ const allReducers = combineReducers({ users, alerts, signup, - adminRequests + adminRequests, + forgot, + resetPassword }); export default allReducers; diff --git a/redux/reducers/resetPassword.js b/redux/reducers/resetPassword.js new file mode 100644 index 0000000..a579841 --- /dev/null +++ b/redux/reducers/resetPassword.js @@ -0,0 +1,32 @@ +import * as actions from "../actions/types"; + +const initialState = { + error: null, + message: null, + err: null, + loading: false, +}; + +export default (state = initialState, action) => { + switch (action.type) { + case actions.SET_RESET_LOADING: + return { + ...state, + loading: true, + }; + case actions.SET_RESET_SUCCESS: + return { + ...state, + message: action.payload, + loading: false, + }; + case actions.SET_RESET_INVALID: + return { + ...state, + err: action.payload, + loading: false, + }; + default: + return state; + } +}; diff --git a/src/App.js b/src/App.js index 6871e27..59c99ef 100644 --- a/src/App.js +++ b/src/App.js @@ -10,8 +10,14 @@ import Signup from "./Views/Signup"; import ViewProfile from "./components/profile/View"; import CompleteProfile from "./components/profile/Complete"; import UpdateProfile from "./components/profile/Update"; +import { + ForgotPassword, + Success, +} from "./components/resetPassword/forgotPassword"; +import ResetPassword from "./components/resetPassword/resetPassword"; import Navigation from "./components/Navigation"; import Footer from "./components/Footer"; + import Roles from "./views/Roles/Roles"; import "./App.scss"; @@ -39,6 +45,9 @@ const App = () => ( + + +