Skip to content

Commit

Permalink
feature: Implement Add user
Browse files Browse the repository at this point in the history
- Add search page for users
- Add Add User option
- Create Api route to add User to group
- Add footer to app
- Add heading to login and register form
- Add navbar to PageNotFound
- Fix heroku issue

[Delivers #152948431]
  • Loading branch information
bumsyalao committed Nov 17, 2017
1 parent 4aed19b commit 8c87991
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 110 deletions.
2 changes: 1 addition & 1 deletion assetsTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const path = require('path');

module.exports = {
process(src, filename, config, options) {
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
},
};
20 changes: 17 additions & 3 deletions client/actions/groups.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global localStorage */
import axios from 'axios';
import {
LIST_GROUPS, ADD_USER_TO_GROUP, GET_GROUP_USERS, LIST_ALL_USERS, LIST_GROUP }
LIST_GROUPS, ADD_USER_TO_GROUP, GET_GROUP_USERS, LIST_GROUP }
from './types';
import attachAuthorizationToken from '../utils/attachAuthorizationToken';

Expand Down Expand Up @@ -86,14 +86,28 @@ export const listAllUsers = groupId => dispatch =>
});

/**
* api call to addMemberToGroup
* api call to joinGroup
* @param {object} groupId
* @return {object} returns newGroup if the call is successful
*/
export const addMemberToGroup = groupId =>
export const joinGroup = groupId =>
dispatch => axios.post(`/api/v1/group/${groupId}/user`)
.then((response) => {
dispatch(addUser(response.data.newGroup));
}).catch((error) => {
throw (error);
});

/**
* api call to addMemberToGroup
* @param {object} groupId
* @return {object} returns newGroup if the call is successful
*/
export const addMemberToGroup = (groupId, userId) =>
dispatch => axios.post(`/api/v1/group/${groupId}/user/${userId}`)
.then((response) => {
dispatch(addUser(response.data.newGroup));
}).catch((error) => {
throw (error);
});

7 changes: 4 additions & 3 deletions client/components/Group/GroupCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GroupCard extends Component {
}
/* eslint-enable */
render() {
const { groupName, id, joinGroup, listUsers, users } = this.props;
const { groupName, id, joinAGroup, listUsers, users } = this.props;

return (
<div className="col s6">
Expand All @@ -46,7 +46,7 @@ class GroupCard extends Component {
>
<li>
<i className="material-icons tiny">games</i>
<div onClick={joinGroup} id={id} className="card-title">
<div onClick={joinAGroup} id={id} className="card-title">
Join group
</div>
</li>
Expand Down Expand Up @@ -74,7 +74,8 @@ class GroupCard extends Component {
<div className="users-list">
{users &&
users.map(user => (
<div id={id} key={user.userId} className="card-title">
<div id={id} key={user.userId}
className="card-title">
{user.username}
</div>
))}
Expand Down
33 changes: 21 additions & 12 deletions client/components/Group/GroupChat.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { withRouter, Link } from 'react-router-dom';
import MessageCard from './MessageCard';
import { newMessage, getMessages } from '../../actions/messages';
import { getUserGroups, allUserGroups } from '../../actions/users';
Expand All @@ -12,7 +12,6 @@ import { getGroup } from '../../actions/groups';
* @extends {React.Component}
*/
class GroupChat extends React.Component {

/**
* Creates an instance of GroupChat.
* Binds class methods
Expand All @@ -39,8 +38,6 @@ class GroupChat extends React.Component {
componentDidMount() {
$('select').material_select();
const { groupId } = this.props.match.params;
const userid = this.props.access.user.userId;
this.props.allUserGroups(userid);
this.props.getMessages(groupId);
this.props.getGroup(groupId);
}
Expand Down Expand Up @@ -97,11 +94,17 @@ class GroupChat extends React.Component {
this.props.history.push('/homepage/groups');
return null;
}
const id = this.props.group.id;
return (
<div>
<div className="row">
<div className="col s12 m12 l12 form-margin message-form">
<h5> {(this.props.group.groupName || '').toUpperCase()} </h5>
<Link to={`/homepage/group/${id}/add-user`}
className="waves-effect waves-light red lighten-2 btn">
<i className="material-icons left">add</i>
Add User
</Link>
<div className="message-box">
<ul className="collection">
{this.props.messages.map(message => (
Expand All @@ -126,13 +129,16 @@ class GroupChat extends React.Component {
onChange={this.onChange}
value={this.state.messagePriority}
>
<option value="normal" defaultValue>Normal</option>
<option value="normal" defaultValue>
Normal
</option>
<option value="urgent">Urgent</option>
<option value="critical">Critical</option>
</select>
<button
id="submit-message"
onClick={this.onSubmit}> Send </button>
<button id="submit-message" onClick={this.onSubmit}>
{' '}
Send{' '}
</button>
</div>
</div>
</div>
Expand All @@ -149,11 +155,14 @@ const mapStateToProps = (state, ownProps) => {
messages: state.messages[groupId] || [],
group: state.group[groupId] || {},
userGroups: state.users.usergroups || [],
access: state.access,
access: state.access
};
};

export default connect(mapStateToProps, {
newMessage, getMessages, getGroup, getUserGroups, allUserGroups })(withRouter(
GroupChat
));
newMessage,
getMessages,
getGroup,
getUserGroups,
allUserGroups
})(withRouter(GroupChat));
16 changes: 8 additions & 8 deletions client/components/Group/ListGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { getMessages } from '../../actions/messages';
import {
getGroups, listAllUsers, addMemberToGroup
getGroups, listAllUsers, joinGroup
} from '../../actions/groups';
import GroupCard from './GroupCard';

Expand All @@ -11,7 +11,7 @@ import GroupCard from './GroupCard';
* @class ListGroup
* @extends {React.Component}
*/
export class ListGroup extends React.Component {
class ListGroup extends React.Component {

/**
* Creates an instance of ListGroup.
Expand All @@ -23,7 +23,7 @@ export class ListGroup extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
this.joinGroup = this.joinGroup.bind(this);
this.joinAGroup = this.joinAGroup.bind(this);
this.listUsers = this.listUsers.bind(this);
}

Expand All @@ -48,16 +48,16 @@ export class ListGroup extends React.Component {

/**
*
* Makes an action call to addMemberToGroup
* Makes an action call to joinGroup
* @param {object} event The event of the HTML component
*
* @memberOf ListGroup
*/
joinGroup(event) {
joinAGroup(event) {
event.preventDefault();
const id = event.target.id;
this.props
.addMemberToGroup(id)
.joinGroup(id)
.then(() => {
Materialize.toast('Member successfully added', 5000, 'green');
})
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ListGroup extends React.Component {
key={group.id}
id={group.id}
onClick={() => this.onClick(group.id)}
joinGroup={this.joinGroup}
joinAGroup={this.joinAGroup}
{...group}
users={group.users}
listUsers={this.listUsers}
Expand All @@ -132,7 +132,7 @@ const mapStateToProps = state => ({
const actions = {
getGroups,
getMessages,
addMemberToGroup,
joinGroup,
listAllUsers,
};

Expand Down
6 changes: 6 additions & 0 deletions client/components/Group/MessageCard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';

/**
*
*
* @param {any} props
* @returns
*/
const MessageCard = (props) => {
const date = new Date(props.createdAt);
return (
Expand Down
Loading

0 comments on commit 8c87991

Please sign in to comment.