mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +08:00
removes modalContaine, move leaveTeamModal under teams
This commit is contained in:
parent
7d6d95630d
commit
545cf50993
17 changed files with 173 additions and 167 deletions
|
@ -1,7 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
import LeaveTeamModal from "./modals/LeaveTeamModal";
|
|
||||||
|
|
||||||
export default () =>
|
|
||||||
<div>
|
|
||||||
<LeaveTeamModal />
|
|
||||||
</div>;
|
|
|
@ -1,41 +1,37 @@
|
||||||
import axios from "../../config/axios";
|
// @flow
|
||||||
import _ from "lodash";
|
import type {
|
||||||
import { TEAMS_PATH, CHANGE_TEAM_PATH } from "../../config/api_endpoints";
|
Teams$Team,
|
||||||
|
Action$LeaveTeam,
|
||||||
|
Action$AddTeamData,
|
||||||
|
Actopm$SetCurrentTeam
|
||||||
|
} from "flow-typed";
|
||||||
|
import type { Dispatch } from "redux-thunk";
|
||||||
|
import { getTeams, changeCurrentTeam } from "../../services/api/teams_api";
|
||||||
import {
|
import {
|
||||||
GET_LIST_OF_TEAMS,
|
GET_LIST_OF_TEAMS,
|
||||||
SET_CURRENT_TEAM,
|
SET_CURRENT_TEAM
|
||||||
SHOW_LEAVE_TEAM_MODAL
|
|
||||||
} from "../../config/action_types";
|
} from "../../config/action_types";
|
||||||
|
|
||||||
export function leaveTeamModalShow(show = false, team = {}) {
|
export function addTeamsData(data: Array<Teams$Team>): Action$AddTeamData {
|
||||||
return {
|
|
||||||
payload: { team, show },
|
|
||||||
type: SHOW_LEAVE_TEAM_MODAL
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addTeamsData(data) {
|
|
||||||
return {
|
return {
|
||||||
type: GET_LIST_OF_TEAMS,
|
type: GET_LIST_OF_TEAMS,
|
||||||
payload: data
|
payload: data
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setCurrentTeam(team) {
|
export function setCurrentTeam(team: Teams$Team): Actopm$SetCurrentTeam {
|
||||||
return {
|
return {
|
||||||
team,
|
team,
|
||||||
type: SET_CURRENT_TEAM
|
type: SET_CURRENT_TEAM
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTeamsList() {
|
export function getTeamsList(): Dispatch {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
axios
|
getTeams()
|
||||||
.get(TEAMS_PATH, { withCredentials: true })
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const teams = response.data.teams.collection;
|
const { teams, currentTeam } = response;
|
||||||
dispatch(addTeamsData(teams));
|
dispatch(addTeamsData(teams));
|
||||||
const currentTeam = _.find(teams, team => team.current_team);
|
|
||||||
dispatch(setCurrentTeam(currentTeam));
|
dispatch(setCurrentTeam(currentTeam));
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -44,14 +40,12 @@ export function getTeamsList() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeTeam(team_id) {
|
export function changeTeam(teamID: number): Dispatch {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
axios
|
changeCurrentTeam(teamID)
|
||||||
.post(CHANGE_TEAM_PATH, { team_id }, { withCredentials: true })
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const teams = response.data.teams.collection;
|
const { teams, currentTeam } = response;
|
||||||
dispatch(addTeamsData(teams));
|
dispatch(addTeamsData(teams));
|
||||||
const currentTeam = _.find(teams, team => team.current_team);
|
|
||||||
dispatch(setCurrentTeam(currentTeam));
|
dispatch(setCurrentTeam(currentTeam));
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
SET_CURRENT_TEAM,
|
SET_CURRENT_TEAM,
|
||||||
GET_LIST_OF_TEAMS,
|
GET_LIST_OF_TEAMS
|
||||||
SHOW_LEAVE_TEAM_MODAL
|
|
||||||
} from "../../config/action_types";
|
} from "../../config/action_types";
|
||||||
|
|
||||||
export const setCurrentTeam = (
|
export const setCurrentTeam = (
|
||||||
|
@ -23,13 +22,3 @@ export const getListOfTeams = (state = { collection: [] }, action) => {
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const showLeaveTeamModal = (
|
|
||||||
state = { show: false, team: { id: 0, name: "", user_team_id: 0 } },
|
|
||||||
action
|
|
||||||
) => {
|
|
||||||
if (action.type === SHOW_LEAVE_TEAM_MODAL) {
|
|
||||||
return { ...state, ...action.payload };
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
// teams
|
// teams
|
||||||
export const SET_CURRENT_TEAM = "SET_CURRENT_TEAM";
|
export const SET_CURRENT_TEAM: string = "SET_CURRENT_TEAM";
|
||||||
export const GET_LIST_OF_TEAMS = "GET_LIST_OF_TEAMS";
|
export const GET_LIST_OF_TEAMS: string = "GET_LIST_OF_TEAMS";
|
||||||
export const SET_TEAM_DETAILS = "SET_TEAM_DETAILS";
|
export const SET_TEAM_DETAILS: string = "SET_TEAM_DETAILS";
|
||||||
|
|
||||||
// users
|
// users
|
||||||
export const USER_LOGOUT = "USER_LOGOUT";
|
export const USER_LOGOUT: string = "USER_LOGOUT";
|
||||||
export const SET_CURRENT_USER = "SET_CURRENT_USER";
|
export const SET_CURRENT_USER: string = "SET_CURRENT_USER";
|
||||||
|
|
||||||
// user teams
|
// user teams
|
||||||
export const LEAVE_TEAM = "LEAVE_TEAM";
|
export const LEAVE_TEAM: string = "LEAVE_TEAM";
|
||||||
|
|
||||||
// modals
|
|
||||||
export const SHOW_LEAVE_TEAM_MODAL = "SHOW_LEAVE_TEAM_MODAL";
|
|
||||||
export const UPDATE_TEAM_DESCRIPTION_MODAL = "UPDATE_TEAM_DESCRIPTION_MODAL";
|
|
||||||
|
|
||||||
// alerts
|
// alerts
|
||||||
export const ADD_ALERT = "ADD_ALERT";
|
export const ADD_ALERT: string = "ADD_ALERT";
|
||||||
export const CLEAR_ALERT = "CLEAR_ALERT";
|
export const CLEAR_ALERT: string = "CLEAR_ALERT";
|
||||||
export const CLEAR_ALL_ALERTS = "CLEAR_ALL_ALERTS";
|
export const CLEAR_ALL_ALERTS: string = "CLEAR_ALL_ALERTS";
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
// settings
|
|
||||||
export const SETTINGS_PATH = "/settings";
|
|
||||||
export const SETTINGS_ACCOUNT_PATH = "/settings/account";
|
|
||||||
// teams
|
|
||||||
export const TEAMS_PATH = "/client_api/teams";
|
|
||||||
export const CHANGE_TEAM_PATH = "/client_api/teams/change_team";
|
|
||||||
export const TEAM_DETAILS_PATH = "/client_api/teams/:team_id/details";
|
|
||||||
|
|
||||||
// search
|
|
||||||
export const SEARCH_PATH = "/search";
|
|
||||||
|
|
||||||
// notifications
|
|
||||||
export const RECENT_NOTIFICATIONS_PATH = "/client_api/recent_notifications";
|
|
||||||
// info dropdown_title
|
|
||||||
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";
|
|
||||||
export const TUTORIALS_LINK = "http://scinote.net/product/tutorials/";
|
|
||||||
export const RELEASE_NOTES_LINK = "http://scinote.net/docs/release-notes/";
|
|
||||||
export const PREMIUM_LINK = "http://scinote.net/premium/";
|
|
||||||
export const CONTACT_US_LINK =
|
|
||||||
"http://scinote.net/story-of-scinote/#contact-scinote";
|
|
||||||
|
|
||||||
// user teams
|
|
||||||
export const LEAVE_TEAM_PATH = "/client_api/users/leave_team";
|
|
||||||
|
|
||||||
// settings
|
|
||||||
export const SETTINGS_TEAMS = "/settings/teams";
|
|
|
@ -1,19 +0,0 @@
|
||||||
// @TODO remove this file ASAP the preferences/profile refactoring is merged
|
|
||||||
import axios from "axios";
|
|
||||||
import store from "./store";
|
|
||||||
import { SIGN_IN_PATH } from "./routes";
|
|
||||||
import { destroyState } from "../components/actions/UsersActions";
|
|
||||||
|
|
||||||
export default axios.create({
|
|
||||||
withCredentials: true,
|
|
||||||
headers: {
|
|
||||||
"X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]').content
|
|
||||||
},
|
|
||||||
validateStatus(status) {
|
|
||||||
if (status === 401) {
|
|
||||||
store.dispatch(destroyState);
|
|
||||||
window.location = SIGN_IN_PATH;
|
|
||||||
}
|
|
||||||
return status >= 200 && status < 300;
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -2,8 +2,7 @@ import { combineReducers } from "redux";
|
||||||
import { USER_LOGOUT } from "./action_types";
|
import { USER_LOGOUT } from "./action_types";
|
||||||
import {
|
import {
|
||||||
setCurrentTeam,
|
setCurrentTeam,
|
||||||
getListOfTeams,
|
getListOfTeams
|
||||||
showLeaveTeamModal
|
|
||||||
} from "../components/reducers/TeamReducers";
|
} from "../components/reducers/TeamReducers";
|
||||||
import { currentUser } from "../components/reducers/UsersReducer";
|
import { currentUser } from "../components/reducers/UsersReducer";
|
||||||
import { alerts } from "../components/reducers/AlertsReducers";
|
import { alerts } from "../components/reducers/AlertsReducers";
|
||||||
|
@ -12,7 +11,6 @@ const appReducer = combineReducers({
|
||||||
current_team: setCurrentTeam,
|
current_team: setCurrentTeam,
|
||||||
all_teams: getListOfTeams,
|
all_teams: getListOfTeams,
|
||||||
current_user: currentUser,
|
current_user: currentUser,
|
||||||
showLeaveTeamModal,
|
|
||||||
alerts
|
alerts
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,21 @@ export const ROOT_PATH = "/";
|
||||||
export const SIGN_IN_PATH = "/users/sign_in";
|
export const SIGN_IN_PATH = "/users/sign_in";
|
||||||
|
|
||||||
// Settings page
|
// Settings page
|
||||||
|
export const SETTINGS_PATH = "/settings";
|
||||||
export const SETTINGS_TEAMS_ROUTE = "/settings/teams";
|
export const SETTINGS_TEAMS_ROUTE = "/settings/teams";
|
||||||
export const SETTINGS_TEAM_ROUTE = "/settings/teams/:id";
|
export const SETTINGS_TEAM_ROUTE = "/settings/teams/:id";
|
||||||
export const SETTINGS_NEW_TEAM_ROUTE = "/settings/teams/new";
|
export const SETTINGS_NEW_TEAM_ROUTE = "/settings/teams/new";
|
||||||
export const SETTINGS_ACCOUNT_PROFILE = "/settings/account/profile";
|
export const SETTINGS_ACCOUNT_PROFILE = "/settings/account/profile";
|
||||||
export const SETTINGS_ACCOUNT_PREFERENCES = "/settings/account/preferences";
|
export const SETTINGS_ACCOUNT_PREFERENCES = "/settings/account/preferences";
|
||||||
|
|
||||||
|
// search
|
||||||
|
export const SEARCH_PATH = "/search";
|
||||||
|
|
||||||
|
|
||||||
|
// info dropdown_title
|
||||||
|
export const CUSTOMER_SUPPORT_LINK = "http://scinote.net/support";
|
||||||
|
export const TUTORIALS_LINK = "http://scinote.net/product/tutorials/";
|
||||||
|
export const RELEASE_NOTES_LINK = "http://scinote.net/docs/release-notes/";
|
||||||
|
export const PREMIUM_LINK = "http://scinote.net/premium/";
|
||||||
|
export const CONTACT_US_LINK =
|
||||||
|
"http://scinote.net/story-of-scinote/#contact-scinote";
|
||||||
|
|
|
@ -9,7 +9,6 @@ import messages from "./config/locales/messages";
|
||||||
import store from "./config/store";
|
import store from "./config/store";
|
||||||
|
|
||||||
import AlertsContainer from "./components/AlertsContainer";
|
import AlertsContainer from "./components/AlertsContainer";
|
||||||
import ModalsContainer from "./components/ModalsContainer";
|
|
||||||
import SettingsPage from "./scenes/SettingsPage";
|
import SettingsPage from "./scenes/SettingsPage";
|
||||||
import Navigation from "./components/Navigation";
|
import Navigation from "./components/Navigation";
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ const ScinoteApp = () =>
|
||||||
</ContentWrapper>
|
</ContentWrapper>
|
||||||
</div>
|
</div>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
<ModalsContainer />
|
|
||||||
</div>
|
</div>
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
</Provider>;
|
</Provider>;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ROOT_PATH,
|
ROOT_PATH,
|
||||||
|
SETTINGS_PATH,
|
||||||
SETTINGS_TEAMS_ROUTE,
|
SETTINGS_TEAMS_ROUTE,
|
||||||
SETTINGS_TEAM_ROUTE,
|
SETTINGS_TEAM_ROUTE,
|
||||||
SETTINGS_ACCOUNT_PROFILE,
|
SETTINGS_ACCOUNT_PROFILE,
|
||||||
|
@ -14,8 +15,6 @@ import {
|
||||||
SETTINGS_NEW_TEAM_ROUTE
|
SETTINGS_NEW_TEAM_ROUTE
|
||||||
} from "../../config/routes";
|
} from "../../config/routes";
|
||||||
|
|
||||||
import { SETTINGS_PATH, SETTINGS_TEAMS } from "../../config/api_endpoints";
|
|
||||||
|
|
||||||
import PageTitle from "../../components/PageTitle";
|
import PageTitle from "../../components/PageTitle";
|
||||||
import NotFound from "../../components/404/NotFound";
|
import NotFound from "../../components/404/NotFound";
|
||||||
import SettingsProfile from "./scenes/profile";
|
import SettingsProfile from "./scenes/profile";
|
||||||
|
@ -74,7 +73,7 @@ export default class SettingsPage extends Component<*, State> {
|
||||||
</NavItem>
|
</NavItem>
|
||||||
</LinkContainer>
|
</LinkContainer>
|
||||||
<LinkContainer
|
<LinkContainer
|
||||||
to={SETTINGS_TEAMS}
|
to={SETTINGS_TEAMS_ROUTE}
|
||||||
active={this.state.active === "2"}
|
active={this.state.active === "2"}
|
||||||
>
|
>
|
||||||
<NavItem eventKey="2">
|
<NavItem eventKey="2">
|
||||||
|
|
|
@ -3,14 +3,12 @@ import PropTypes, { bool, number, string, func } from "prop-types";
|
||||||
import { Modal, Button, Alert, Glyphicon } from "react-bootstrap";
|
import { Modal, Button, Alert, Glyphicon } from "react-bootstrap";
|
||||||
import { FormattedMessage, FormattedHTMLMessage } from "react-intl";
|
import { FormattedMessage, FormattedHTMLMessage } from "react-intl";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import axios from "../../../config/axios";
|
import { leaveTeam } from "../../../../../services/api/teams_api";
|
||||||
|
|
||||||
import { LEAVE_TEAM_PATH } from "../../../config/api_endpoints";
|
|
||||||
import {
|
import {
|
||||||
addTeamsData,
|
addTeamsData,
|
||||||
setCurrentTeam,
|
setCurrentTeam
|
||||||
leaveTeamModalShow
|
} from "../../../../../components/actions/TeamsActions";
|
||||||
} from "../../actions/TeamsActions";
|
|
||||||
|
|
||||||
class LeaveTeamModal extends Component {
|
class LeaveTeamModal extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -20,26 +18,22 @@ class LeaveTeamModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onCloseModal() {
|
onCloseModal() {
|
||||||
this.props.leaveTeamModalShow(false);
|
this.props.hideLeaveTeamModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveTeam() {
|
leaveTeam() {
|
||||||
const teamUrl = `${LEAVE_TEAM_PATH}?team=${this.props.team
|
const { id, user_team_id } = this.props.team;
|
||||||
.id}&user_team=${this.props.team.user_team_id}`;
|
leaveTeam(id, user_team_id)
|
||||||
axios
|
|
||||||
.delete(teamUrl, {
|
|
||||||
withCredentials: true
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const teams = response.data.teams.collection;
|
const { teams, currentTeam } = response;
|
||||||
|
this.props.updateTeamsState(teams);
|
||||||
this.props.addTeamsData(teams);
|
this.props.addTeamsData(teams);
|
||||||
const currentTeam = _.find(teams, team => team.current_team);
|
|
||||||
this.props.setCurrentTeam(currentTeam);
|
this.props.setCurrentTeam(currentTeam);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log("error: ", error.response.data.message);
|
console.log("error: ", error.response.data.message);
|
||||||
});
|
});
|
||||||
this.props.leaveTeamModalShow(false);
|
this.props.hideLeaveTeamModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -90,6 +84,7 @@ class LeaveTeamModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaveTeamModal.propTypes = {
|
LeaveTeamModal.propTypes = {
|
||||||
|
updateTeamsState: func.isRequired,
|
||||||
showModal: bool.isRequired,
|
showModal: bool.isRequired,
|
||||||
team: PropTypes.shape({
|
team: PropTypes.shape({
|
||||||
id: number.isRequired,
|
id: number.isRequired,
|
||||||
|
@ -97,17 +92,11 @@ LeaveTeamModal.propTypes = {
|
||||||
user_team_id: number.isRequired
|
user_team_id: number.isRequired
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
addTeamsData: func.isRequired,
|
addTeamsData: func.isRequired,
|
||||||
leaveTeamModalShow: func.isRequired,
|
hideLeaveTeamModel: func.isRequired,
|
||||||
setCurrentTeam: func.isRequired
|
setCurrentTeam: func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = ({ showLeaveTeamModal }) => ({
|
export default connect(null, {
|
||||||
showModal: showLeaveTeamModal.show,
|
|
||||||
team: showLeaveTeamModal.team
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, {
|
|
||||||
leaveTeamModalShow,
|
|
||||||
addTeamsData,
|
addTeamsData,
|
||||||
setCurrentTeam
|
setCurrentTeam
|
||||||
})(LeaveTeamModal);
|
})(LeaveTeamModal);
|
|
@ -1,24 +1,40 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import PropTypes, { func, number, string, bool } from "prop-types";
|
import PropTypes, { func, number, string, bool } from "prop-types";
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { Button } from "react-bootstrap";
|
import { Button } from "react-bootstrap";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
import { leaveTeamModalShow } from "../../../../../components/actions/TeamsActions";
|
|
||||||
import DataTable from "../../../../../components/data_table";
|
import DataTable from "../../../../../components/data_table";
|
||||||
import { SETTINGS_TEAMS_ROUTE } from "../../../../../config/routes";
|
import { SETTINGS_TEAMS_ROUTE } from "../../../../../config/routes";
|
||||||
|
import LeaveTeamModal from "./LeaveTeamModal";
|
||||||
|
|
||||||
|
const DefaultTeam = {
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
current_team: false,
|
||||||
|
user_team_id: 0,
|
||||||
|
role: "",
|
||||||
|
members: 0,
|
||||||
|
can_be_leaved: false
|
||||||
|
};
|
||||||
class TeamsDataTable extends Component {
|
class TeamsDataTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
leaveTeamModalShow: false,
|
||||||
|
team: DefaultTeam
|
||||||
|
};
|
||||||
this.leaveTeamModal = this.leaveTeamModal.bind(this);
|
this.leaveTeamModal = this.leaveTeamModal.bind(this);
|
||||||
this.leaveTeamButton = this.leaveTeamButton.bind(this);
|
this.leaveTeamButton = this.leaveTeamButton.bind(this);
|
||||||
this.linkToTeam = this.linkToTeam.bind(this);
|
this.linkToTeam = this.linkToTeam.bind(this);
|
||||||
|
this.hideLeaveTeamModel = this.hideLeaveTeamModel.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveTeamModal(e, team) {
|
leaveTeamModal(e, team) {
|
||||||
this.props.leaveTeamModalShow(true, team);
|
this.setState({ leaveTeamModalShow: true, team });
|
||||||
|
}
|
||||||
|
|
||||||
|
hideLeaveTeamModel() {
|
||||||
|
this.setState({ leaveTeamModalShow: false, team: DefaultTeam });
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveTeamButton(id, team) {
|
leaveTeamButton(id, team) {
|
||||||
|
@ -90,18 +106,26 @@ class TeamsDataTable extends Component {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
<DataTable
|
<DataTable
|
||||||
data={this.props.teams}
|
data={this.props.teams}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
pagination
|
pagination
|
||||||
options={options}
|
options={options}
|
||||||
/>
|
/>
|
||||||
|
<LeaveTeamModal
|
||||||
|
updateTeamsState={this.props.updateTeamsState}
|
||||||
|
showModal={this.state.leaveTeamModalShow}
|
||||||
|
team={this.state.team}
|
||||||
|
hideLeaveTeamModel={this.hideLeaveTeamModel}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TeamsDataTable.propTypes = {
|
TeamsDataTable.propTypes = {
|
||||||
leaveTeamModalShow: func.isRequired,
|
updateTeamsState: func.isRequired,
|
||||||
teams: PropTypes.arrayOf(
|
teams: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
id: number.isRequired,
|
id: number.isRequired,
|
||||||
|
@ -114,4 +138,4 @@ TeamsDataTable.propTypes = {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(null, { leaveTeamModalShow })(TeamsDataTable);
|
export default TeamsDataTable;
|
||||||
|
|
|
@ -3,11 +3,8 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { Breadcrumb } from "react-bootstrap";
|
import { Breadcrumb } from "react-bootstrap";
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
import type { State } from "flow-typed";
|
import { getTeams } from "../../../../services/api/teams_api";
|
||||||
import type { MapStateToProps } from "react-redux";
|
|
||||||
|
|
||||||
import { BORDER_LIGHT_COLOR } from "../../../../config/constants/colors";
|
import { BORDER_LIGHT_COLOR } from "../../../../config/constants/colors";
|
||||||
|
|
||||||
import PageTitle from "../../../../components/PageTitle";
|
import PageTitle from "../../../../components/PageTitle";
|
||||||
|
@ -24,22 +21,44 @@ const Wrapper = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
tabState: Function,
|
tabState: Function
|
||||||
|
};
|
||||||
|
|
||||||
|
type State = {
|
||||||
teams: Array<Teams$Team>
|
teams: Array<Teams$Team>
|
||||||
};
|
};
|
||||||
|
|
||||||
class SettingsTeams extends Component<Props> {
|
class SettingsTeams extends Component<Props, State> {
|
||||||
static defaultProps = {
|
constructor(props: Props) {
|
||||||
teams: [{ id: 0, name: "", current_team: "", role: "", members: 0 }]
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
teams: [
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
current_team: true,
|
||||||
|
role: "",
|
||||||
|
members: 0,
|
||||||
|
can_be_leaved: false
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
(this: any).updateTeamsState = this.updateTeamsState.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
getTeams().then(({ teams }) => {
|
||||||
|
this.updateTeamsState(teams);
|
||||||
|
});
|
||||||
// set team tab on active
|
// set team tab on active
|
||||||
this.props.tabState("2");
|
this.props.tabState("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTeamsState(teams: Array<Teams$Team>): void {
|
||||||
|
this.setState({ teams });
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { teams } = this.props;
|
|
||||||
return (
|
return (
|
||||||
<PageTitle localeID="page_title.all_teams_page">
|
<PageTitle localeID="page_title.all_teams_page">
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
|
@ -48,16 +67,15 @@ class SettingsTeams extends Component<Props> {
|
||||||
<FormattedMessage id="settings_page.all_teams" />
|
<FormattedMessage id="settings_page.all_teams" />
|
||||||
</Breadcrumb.Item>
|
</Breadcrumb.Item>
|
||||||
</Breadcrumb>
|
</Breadcrumb>
|
||||||
<TeamsPageDetails teams={teams} />
|
<TeamsPageDetails teams={this.state.teams} />
|
||||||
<TeamsDataTable teams={teams} />
|
<TeamsDataTable
|
||||||
|
teams={this.state.teams}
|
||||||
|
updateTeamsState={this.updateTeamsState}
|
||||||
|
/>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<*, *, *> = (state: State) => ({
|
export default SettingsTeams;
|
||||||
teams: state.all_teams.collection
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(SettingsTeams);
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const ACTIVITIES_PATH = "/client_api/activities";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
export const SETTINGS_PATH = "/settings";
|
export const SETTINGS_PATH = "/settings";
|
||||||
export const SETTINGS_ACCOUNT_PATH = "/settings/account";
|
|
||||||
// teams
|
// teams
|
||||||
export const TEAMS_PATH = "/client_api/teams";
|
export const TEAMS_PATH = "/client_api/teams";
|
||||||
export const CHANGE_TEAM_PATH = "/client_api/teams/change_team";
|
export const CHANGE_TEAM_PATH = "/client_api/teams/change_team";
|
||||||
|
@ -16,9 +16,6 @@ export const TEAM_DETAILS_PATH = "/client_api/teams/:team_id/details";
|
||||||
export const TEAM_UPDATE_PATH = "/client_api/teams/update";
|
export const TEAM_UPDATE_PATH = "/client_api/teams/update";
|
||||||
export const CURRENT_USER_PATH = "/client_api/current_user_info"
|
export const CURRENT_USER_PATH = "/client_api/current_user_info"
|
||||||
|
|
||||||
// search
|
|
||||||
export const SEARCH_PATH = "/search";
|
|
||||||
|
|
||||||
// users
|
// users
|
||||||
export const USER_PROFILE_INFO = "/client_api/users/profile_info";
|
export const USER_PROFILE_INFO = "/client_api/users/profile_info";
|
||||||
export const UPDATE_USER_PATH = "/client_api/users/update";
|
export const UPDATE_USER_PATH = "/client_api/users/update";
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
import type { Teams$NewTeam, Team$Update } from "flow-typed";
|
import type { Teams$NewTeam, Team$Update } from "flow-typed";
|
||||||
|
import _ from "lodash";
|
||||||
import { axiosInstance } from "./config";
|
import { axiosInstance } from "./config";
|
||||||
import { TEAM_DETAILS_PATH, TEAMS_PATH, TEAM_UPDATE_PATH } from "./endpoints";
|
import {
|
||||||
|
TEAM_DETAILS_PATH,
|
||||||
|
TEAM_UPDATE_PATH,
|
||||||
|
TEAMS_PATH,
|
||||||
|
CHANGE_TEAM_PATH,
|
||||||
|
LEAVE_TEAM_PATH
|
||||||
|
} from "./endpoints";
|
||||||
|
|
||||||
export const getTeamDetails = (teamID: number): Promise<*> => {
|
export const getTeamDetails = (teamID: number): Promise<*> => {
|
||||||
const path = TEAM_DETAILS_PATH.replace(":team_id", teamID);
|
const path = TEAM_DETAILS_PATH.replace(":team_id", teamID);
|
||||||
|
@ -15,3 +22,26 @@ export const updateTeam = (teamID: number, teamData: Team$Update): Promise<*> =>
|
||||||
axiosInstance
|
axiosInstance
|
||||||
.post(TEAM_UPDATE_PATH, { team_id: teamID, team: teamData })
|
.post(TEAM_UPDATE_PATH, { team_id: teamID, team: teamData })
|
||||||
.then(({ data }) => data.team);
|
.then(({ data }) => data.team);
|
||||||
|
|
||||||
|
export const getTeams = (): Promise<*> =>
|
||||||
|
axiosInstance.get(TEAMS_PATH).then(({ data }) => {
|
||||||
|
const teams = data.teams.collection;
|
||||||
|
const currentTeam = _.find(teams, team => team.current_team);
|
||||||
|
return { teams, currentTeam };
|
||||||
|
});
|
||||||
|
|
||||||
|
export const changeCurrentTeam = (teamID: number): Promise<*> =>
|
||||||
|
axiosInstance.post(CHANGE_TEAM_PATH, { team_id: teamID }).then(({ data }) => {
|
||||||
|
const teams = data.teams.collection;
|
||||||
|
const currentTeam = _.find(teams, team => team.current_team);
|
||||||
|
return { teams, currentTeam };
|
||||||
|
});
|
||||||
|
|
||||||
|
export const leaveTeam = (teamID: number, userTeamID: number): Promise<*> => {
|
||||||
|
const teamUrl = `${LEAVE_TEAM_PATH}?team=${teamID}&user_team=${userTeamID}`;
|
||||||
|
return axiosInstance.delete(teamUrl).then(({ data }) => {
|
||||||
|
const teams = data.teams.collection;
|
||||||
|
const currentTeam = _.find(teams, team => team.current_team);
|
||||||
|
return { teams, currentTeam };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
12
flow-typed/action_types.js
vendored
Normal file
12
flow-typed/action_types.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// @flow
|
||||||
|
import type { Teams$Team } from "flow-typed";
|
||||||
|
|
||||||
|
export type Action$AddTeamData = {
|
||||||
|
payload: Array<Teams$Team>,
|
||||||
|
type: "GET_LIST_OF_TEAMS"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Actopm$SetCurrentTeam = {
|
||||||
|
team: Teams$Team,
|
||||||
|
action: "SET_CURRENT_TEAM"
|
||||||
|
}
|
1
flow-typed/teams_types.js
vendored
1
flow-typed/teams_types.js
vendored
|
@ -21,7 +21,6 @@ export type Teams$NewTeam = {
|
||||||
description: string
|
description: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export type Teams$Team = {
|
export type Teams$Team = {
|
||||||
id: number,
|
id: number,
|
||||||
name: string,
|
name: string,
|
||||||
|
|
Loading…
Add table
Reference in a new issue