Skip to content

Commit

Permalink
Merge pull request #238 from yalla-coop/lead-add-trainer
Browse files Browse the repository at this point in the history
[local lead] add trainer to the group
  • Loading branch information
amusameh authored May 28, 2019
2 parents 854e736 + ccbf5cc commit 82adceb
Show file tree
Hide file tree
Showing 20 changed files with 731 additions and 100 deletions.
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

0 comments on commit 82adceb

Please sign in to comment.