Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local lead] add trainer to the group #238

Merged
merged 9 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 56 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions v2/client/src/actions/authAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import axios from 'axios';
import {
LOGIN_SUCCESS,
LOGIN_FAIL,
CHECK_UNIQUE_EMAIL,
CHECK_UNIQUE_EMAIL_UNIQUE,
CHECK_UNIQUE_EMAIL_UNUNIQUE,
USER_AUTHENTICATED,
USER_UNAUTHENTICATED,
ADD_TRAINER_TO_GROUP_SUCCESS,
CHECK_UNIQUE_EMAIL_ERROR,
} from '../constants/actionTypes';
import { returnErrors } from './errorAction';

Expand Down Expand Up @@ -57,13 +60,26 @@ export const checkUniqeEmail = email => async dispatch => {
try {
const res = await axios.get(`/api/users/?email=${email}`);
const { data } = res;

if (data.isUnique) {
dispatch({
type: CHECK_UNIQUE_EMAIL_UNIQUE,
payload: data,
});
} else {
dispatch({
type: CHECK_UNIQUE_EMAIL_UNUNIQUE,
payload: data,
});
}
} catch (error) {
dispatch({
type: CHECK_UNIQUE_EMAIL,
payload: data.isUnique,
type: ADD_TRAINER_TO_GROUP_SUCCESS,
payload: error.response.data.error,
});
dispatch({
type: CHECK_UNIQUE_EMAIL_ERROR,
payload: error.response.data.error,
});
} catch (error) {
console.log(error);
}
};

Expand Down
15 changes: 15 additions & 0 deletions v2/client/src/actions/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// reset the store data

import * as types from '../constants/actionTypes';

export const resetgroup = () => {
return {
type: types.RESET_GROUPS_STATE,
};
};

export const resetUniqueEmail = () => {
return {
type: types.RESET_UNIQUE_EMAIL,
};
};
16 changes: 16 additions & 0 deletions v2/client/src/actions/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ export const fetchStatsData = userType => async dispatch => {
console.log(error);
}
};

export const addTrainerToGroup = trianerInfo => async dispatch => {
try {
const res = await axios.post('/api/users/local-leads/group', trianerInfo);

dispatch({
type: types.ADD_TRAINER_TO_GROUP_SUCCESS,
payload: res.data,
});
} catch (error) {
dispatch({
type: types.ADD_TRAINER_TO_GROUP_FAIL,
payload: error.response.data.error,
});
}
};
11 changes: 11 additions & 0 deletions v2/client/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Dashboard from './pages/Dashboard';
import Home from './pages/LandingPage';
import SignUp from './pages/SignUp';
import UserResults from './pages/UserResults';
import AddTrainer from './pages/AddTrainer';
import Survey from './pages/survey/Survey';
import TrainerListPage from './pages/TrainerListPage';
import ParticipantBehavioral from './pages/ParticipantBehavioral';
Expand Down Expand Up @@ -57,6 +58,16 @@ class App extends Component {
<Route exact path="/users/:id/results" component={UserResults} />
<Route exact path={HOME_URL} component={Home} />

<PrivateRoute
exact
path="/add-trainer"
Component={AddTrainer}
isAuthenticated={isAuthenticated}
loaded={loaded}
allowedRoles={['admin', 'localLead', 'trainer']}
role={role}
/>

<PrivateRoute
exact
path={DASHBOARD_URL}
Expand Down
42 changes: 42 additions & 0 deletions v2/client/src/components/pages/AddTrainer/AddTrainer.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import styled from 'styled-components';
import { Form as AntForm, Input as AntInput, Select as AntSelect } from 'antd';

const { Item: AntItem } = AntForm;

export const Wrapper = styled.div``;

export const ContentWrapper = styled.div`
max-width: 25rem;
margin: 0 auto;
padding: 5rem 15px;
`;

export const Form = styled(AntForm)`
margin: 0 auto;
text-align: center;
padding: 20px 0;
`;

export const Input = styled(AntInput)`
width: 90%;
margin: 0 auto;
height: 50px;
`;

export const Select = styled(AntSelect)`
width: 90%;
`;

export const Item = styled(AntItem)`
width: 90%;
margin: 0 auto;
margin-bottom: 20px;
text-align: center;
`;

export const Bold = styled.span`
font-weight: 900;
text-transform: capitalize;
`;

export const Paragraph = styled.p``;
Loading