-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from thembones79/feature/users-list-and-change…
…=password initial commit
- Loading branch information
Showing
18 changed files
with
630 additions
and
17,509 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ActionTypes } from "../../actions"; | ||
|
||
export type BackToUsersListAction = { | ||
type: ActionTypes.BACK_TO_USERS_LIST; | ||
}; | ||
|
||
export const backToUsersList = (): BackToUsersListAction => { | ||
return { | ||
type: ActionTypes.BACK_TO_USERS_LIST, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import axios from "axios"; | ||
import { Dispatch } from "redux"; | ||
import { ActionTypes } from ".."; | ||
import { ROOT_URL, headers } from "../../config"; | ||
|
||
export interface IChangePassword { | ||
password: string; | ||
_id: string; | ||
} | ||
|
||
export type ChangePasswordAction = { | ||
type: ActionTypes.CHANGE_PASSWORD; | ||
payload: string; | ||
}; | ||
|
||
export type ChangePasswordActionError = { | ||
type: ActionTypes.CHANGE_PASSWORD_ERROR; | ||
payload: string; | ||
}; | ||
|
||
export const changePassword = | ||
( | ||
{ password, | ||
_id }: IChangePassword | ||
) => | ||
async (dispatch: Dispatch) => { | ||
try { | ||
const response = await axios.put( | ||
`${ROOT_URL}/api/user/password/${_id}`, | ||
{ | ||
password, | ||
}, | ||
{ | ||
headers, | ||
} | ||
); | ||
dispatch<ChangePasswordAction>({ | ||
type: ActionTypes.CHANGE_PASSWORD, | ||
payload: response.data, | ||
}); | ||
} catch (e: any) { | ||
dispatch<ChangePasswordActionError>({ | ||
type: ActionTypes.CHANGE_PASSWORD_ERROR, | ||
payload: e.response.data.error, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import axios from "axios"; | ||
import { Dispatch } from "redux"; | ||
import { ActionTypes } from ".."; | ||
import { ROOT_URL, headers } from "../../config"; | ||
|
||
export type UserType = { | ||
_id: string; | ||
firstname: string; | ||
lastname: string; | ||
type: string; | ||
email: string; | ||
password: string; | ||
}; | ||
|
||
export type GetUsersBeginAction = { | ||
type: ActionTypes.GET_USERS_BEGIN; | ||
}; | ||
|
||
export type GetUsersSuccessAction = { | ||
type: ActionTypes.GET_USERS_SUCCESS; | ||
payload: UserType[]; | ||
}; | ||
|
||
export type GetUsersActionError = { | ||
type: ActionTypes.GET_USERS_ERROR; | ||
payload: string; | ||
}; | ||
|
||
export const getUsers = () => async (dispatch: Dispatch) => { | ||
dispatch<GetUsersBeginAction>({ | ||
type: ActionTypes.GET_USERS_BEGIN, | ||
}); | ||
try { | ||
const response = await axios.get(`${ROOT_URL}/api/user`, { | ||
headers, | ||
}); | ||
dispatch<GetUsersSuccessAction>({ | ||
type: ActionTypes.GET_USERS_SUCCESS, | ||
payload: response.data.users, | ||
}); | ||
} catch (e: any) { | ||
dispatch<GetUsersActionError>({ | ||
type: ActionTypes.GET_USERS_ERROR, | ||
payload: e.response ? e.response.data.error : "server is not responding", | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ActionTypes } from "../../actions"; | ||
|
||
export type StartAddingUserAction = { | ||
type: ActionTypes.START_ADDING_USER; | ||
}; | ||
|
||
export const startAddingUser = (): StartAddingUserAction => { | ||
return { | ||
type: ActionTypes.START_ADDING_USER, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ActionTypes } from "../../actions"; | ||
|
||
export type StartChangingPasswordAction = { | ||
type: ActionTypes.START_CHANGING_PASSWORD; | ||
payload: string; | ||
}; | ||
|
||
export const startChangingPassword = (userId:string): StartChangingPasswordAction => { | ||
return { | ||
type: ActionTypes.START_CHANGING_PASSWORD, | ||
payload: userId, | ||
}; | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/Dashboard/AddUserStyle.scss → ...ponents/Dashboard/Users/AddUserStyle.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@import "../base"; | ||
@import "../../base"; | ||
|
||
.add-user-page { | ||
height: $page-height; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { Component, ElementType } from "react"; | ||
import { reduxForm, Field, InjectedFormProps } from "redux-form"; | ||
import { compose } from "redux"; | ||
import { connect } from "react-redux"; | ||
import { withRouter, RouteComponentProps } from "react-router-dom"; | ||
import * as actions from "../../../actions"; | ||
import { IChangePassword, ChangePasswordAction, ChangePasswordActionError } from "../../../actions"; | ||
import requireAuth from "../../requireAuth"; | ||
import { StoreState } from "../../../reducers"; | ||
import "./AddUserStyle.scss"; | ||
|
||
interface IChangePasswordProps extends RouteComponentProps { | ||
errorMessage: string; | ||
_id: string; | ||
changePassword: ({ password, _id }: IChangePassword) => ChangePasswordAction | ChangePasswordActionError; | ||
} | ||
|
||
class ChangePassword extends Component<InjectedFormProps<IChangePassword> & IChangePasswordProps> { | ||
onSubmit = (formProps: IChangePassword) => { | ||
const { _id, changePassword } = this.props; | ||
const { password } = formProps; | ||
changePassword({ password, _id }) | ||
}; | ||
|
||
render() { | ||
const { handleSubmit, submitting } = this.props; | ||
return ( | ||
<div className="add-user-page"> | ||
<form className="add-user-form " onSubmit={handleSubmit(this.onSubmit)}> | ||
<fieldset> | ||
<label className="add-user-form__label" htmlFor="password"> | ||
Password | ||
</label> | ||
<Field | ||
className="add-user-form__select" | ||
name="password" | ||
type="password" | ||
component="input" | ||
label="Password" | ||
required | ||
autoComplete="none" | ||
/> | ||
</fieldset> | ||
<fieldset> | ||
<label className="add-user-form__label" htmlFor="passwordConfirm"> | ||
Confirm Password | ||
</label> | ||
<Field | ||
className="add-user-form__select" | ||
name="passwordConfirm" | ||
type="password" | ||
component="input" | ||
required | ||
autoComplete="none" | ||
/> | ||
</fieldset> | ||
<div>{this.props.errorMessage}</div> | ||
|
||
<button className="btn btn--accent spacer" disabled={submitting}> | ||
Change Password | ||
</button> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
interface IValidate { | ||
passwordConfirm?: string; | ||
password?: string; | ||
} | ||
|
||
const validate: (values: IValidate) => IValidate = (values) => { | ||
const errors: IValidate = {}; | ||
|
||
if (values.password !== values.passwordConfirm) { | ||
errors.password = "Passwords must match"; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
function mapStateToProps(state: StoreState) { | ||
return { errorMessage: state.auth.errorMessage, _id: state.dashboard.userId }; | ||
} | ||
|
||
export default compose( | ||
connect(mapStateToProps, actions), | ||
reduxForm({ form: "changePassword", validate: validate }) | ||
)(requireAuth(withRouter(ChangePassword))) as ElementType; |
Oops, something went wrong.