Skip to content

Commit

Permalink
fix: add loading and notification
Browse files Browse the repository at this point in the history
  • Loading branch information
henilp105 committed Jun 25, 2023
1 parent 64b679e commit dddedc5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
14 changes: 6 additions & 8 deletions registry/src/pages/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const Account = () => {
const isLoading = useSelector((state) => state.account.isLoading);
const isLoadingEmail = useSelector((state) => state.account.isLoadingEmail);
const messageEmail = useSelector((state) => state.account.message);
const isLoadingPassword = useSelector(
(state) => state.account.isLoadingPassword
);
const dispatch = useDispatch();
const navigate = useNavigate();

Expand All @@ -49,10 +52,6 @@ const Account = () => {
} else {
dispatch(getUserAccount(uuid));
}

if (error !== null || successMsg !== null) {
dispatch(resetMessages());
}
});

const validateForm = () => {
Expand Down Expand Up @@ -229,17 +228,16 @@ const Account = () => {
{fromValidationErrors.password && (
<p className="error">{fromValidationErrors.password}</p>
)}
<p className={`success ${error ? "error" : ""}`}>
{error ? error : messageEmail}
</p>
<p className="error">{error}</p>
<p className="success">{messageEmail}</p>
</Form>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleCloseModal}>
Close
</Button>
<Button variant="primary" onClick={handleSubmit}>
{isLoadingEmail ? "Loading..." : "Submit"}
{isLoadingPassword ? "Loading..." : "Submit"}
</Button>
</Modal.Footer>
</Modal>
Expand Down
1 change: 1 addition & 0 deletions registry/src/store/actions/accountActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const getUserAccount = (uuid) => async (dispatch) => {

export const reset = (oldpassword, password, uuid) => async (dispatch) => {
let formData = new FormData();
dispatch({ type: RESET_PASSWORD });
formData.append("oldpassword", oldpassword);
formData.append("password", password);
formData.append("uuid", uuid);
Expand Down
4 changes: 4 additions & 0 deletions registry/src/store/reducers/accountReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const initialState = {
dateJoined: "",
isLoading: true,
isLoadingEmail: false,
isLoadingPassword: false,
message: null,
resetPasswordSuccessMsg: null,
};
Expand All @@ -34,6 +35,7 @@ const accountReducer = (state = initialState, action) => {
return {
...state,
resetPasswordSuccessMsg: action.payload,
isLoadingPassword: true,
};
case CHANGE_EMAIL_SUCCESS:
return {
Expand All @@ -57,11 +59,13 @@ const accountReducer = (state = initialState, action) => {
return {
...state,
message: action.payload,
isLoadingPassword: false,
};
case RESET_PASSWORD_ERROR:
return {
...state,
error: action.payload,
isLoadingPassword: false,
};
case RESET_MESSAGES:
return {
Expand Down

0 comments on commit dddedc5

Please sign in to comment.