Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12162bb
commit a277b63
Showing
15 changed files
with
153 additions
and
61 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { usersCollectionExactFiltered } from "./collection"; | ||
|
||
const NAME_REGEX = /^[a-z0-9_.-]*$/; | ||
|
||
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/; | ||
|
||
export const isValidUserName = name => name.length > 4 && NAME_REGEX.test(name); | ||
|
||
export const isValidUserEmail = email => EMAIL_REGEX.test(email); | ||
|
||
export const isUserNameRepeated = name => | ||
usersCollectionExactFiltered | ||
.filter({ | ||
name | ||
}) | ||
.read() | ||
.then(results => results.length > 0); | ||
|
||
export const isUserEmailRepeated = email => | ||
usersCollectionExactFiltered | ||
.filter({ | ||
}) | ||
.read() | ||
.then(results => results.length > 0); |
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,15 @@ | ||
import React from "react"; | ||
import { withRouter } from "react-router-dom"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { UpdateUserMe } from "./views/UpdateUserMe"; | ||
|
||
// UPDATE USER | ||
|
||
export const AccountBase = ({ history }) => <UpdateUserMe goBack={() => history.goBack()} />; | ||
|
||
AccountBase.propTypes = { | ||
history: PropTypes.any | ||
}; | ||
|
||
export const Account = withRouter(AccountBase); |
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,3 @@ | ||
import { Account } from "./Layouts"; | ||
|
||
export const Module = Account; |
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,44 @@ | ||
import { pickBy, identity } from "lodash"; | ||
|
||
import { plugins } from "reactive-data-source"; | ||
|
||
import { Component as UserComponent } from "src/components/user"; | ||
|
||
import { | ||
usersModels, | ||
usersModelsWithExtraData, | ||
userAllowedRoles, | ||
userMeIsAdmin, | ||
isValidUserName, | ||
isValidUserEmail, | ||
isUserNameRepeated, | ||
isUserEmailRepeated | ||
} from "src/data-sources/users"; | ||
|
||
export const mapDataSourceToProps = ({ id }) => { | ||
const readUser = usersModelsWithExtraData.byId(id).read; | ||
const user = usersModels.byId(id); | ||
const updateUser = user.update; | ||
const deleteUser = user.delete; | ||
|
||
const submitUpdateUser = userData => updateUser(pickBy(userData, identity)); | ||
|
||
return { | ||
currentUserIsAdmin: userMeIsAdmin.read.getters.value, | ||
roles: userAllowedRoles.byId(id).read.getters.value, | ||
onSubmit: submitUpdateUser, | ||
submitLoading: updateUser.getters.loading, | ||
submitError: updateUser.getters.error, | ||
user: readUser.getters.value, | ||
userLoading: readUser.getters.loading, | ||
userError: readUser.getters.error, | ||
userDeleteLoading: deleteUser.getters.loading, | ||
userDeleteError: deleteUser.getters.error, | ||
isUserNameRepeated, | ||
isUserEmailRepeated, | ||
isValidUserName, | ||
isValidUserEmail | ||
}; | ||
}; | ||
|
||
export const UpdateUser = plugins.connect(mapDataSourceToProps)(UserComponent); |
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,21 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { plugins } from "reactive-data-source"; | ||
|
||
import { UpdateUser } from "./UpdateUser"; | ||
|
||
import { userMe } from "src/data-sources/users"; | ||
|
||
export const UpdateUserMeComponent = ({ user, goBack }) => | ||
user._id ? <UpdateUser id={user._id} onCancel={goBack} /> : null; | ||
|
||
UpdateUserMeComponent.propTypes = { | ||
goBack: PropTypes.func, | ||
user: PropTypes.any | ||
}; | ||
|
||
export const mapDataSourceToProps = () => ({ | ||
user: userMe.read.getters.value | ||
}); | ||
|
||
export const UpdateUserMe = plugins.connect(mapDataSourceToProps)(UpdateUserMeComponent); |
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
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 was deleted.
Oops, something went wrong.