Commit fad2f1d2 authored by Alessandro Abluton's avatar Alessandro Abluton

still to finish Manage Modal

parent 7e86e8b3
......@@ -5,9 +5,8 @@ import { withCurrentUser} from '../withCurrentUser'
import { translate, Trans } from 'react-i18next'
import { Container, Menu, Segment, Grid } from 'semantic-ui-react'
import {apolloFetch, apolloFetchNoAuth} from '../store/apolloFetchUtils'
import {connect} from 'react-redux'
import {saveAdminData} from '../store/actions/AdministrationActions'
import {saveTeams,saveRoles,saveUserTeams} from '../store/actions/AdministrationActions'
import AdminMenu from './components/Menu'
import RootModal from './containers/RootModal'
......@@ -24,36 +23,9 @@ class Admin extends Component{
)
}
componentDidUpdate(){
let query=`
query getAdminData {
roles{
data {
id
role_desc
}
}
user_teams{
data{
userteam_id
user_id
team_id
}
}
team{
data {
id
name
email
}
}
}
`
apolloFetch({query})
.then((data)=>{
//salvo i dati sullo store
this.props.saveDataToStore(data.data.roles.data, data.data.team.data, data.data.user_teams.data)
})
this.props.saveTeamsToStore
this.props.saveRolesToStore
this.props.saveUserTeamsToStore
}
render(){
return (
......@@ -81,7 +53,9 @@ const mapStateToProps = (state)=>{
}
const mapDispatchToProps = (dispatch) => {
return {
saveDataToStore: (roles, teams, user_teams) => dispatch(saveAdminData(roles, teams, user_teams))
saveTeamsToStore: dispatch(saveTeams()),
saveRolesToStore: dispatch(saveRoles()),
saveUserTeamsToStore: dispatch(saveUserTeams())
}
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(translate('translations')(Admin)))
......@@ -6,9 +6,8 @@ class ErrorMessage extends Component{
super(props)
}
render(){
console.log(this.props);
return(
<Message negative>
<Message negative hidden={this.props.hidden}>
<Message.Header>{this.props.header}</Message.Header>
<p>{this.props.message}</p>
</Message>
......
import React, { Component } from 'react'
class CreateUserForm extends Component {
constructor(props) {
super(props)
}
render(){
return null
}
}
export default CreateUserForm
......@@ -6,9 +6,8 @@ class PositiveMessage extends Component{
super(props)
}
render(){
console.log(this.props);
return(
<Message positive>
<Message positive hidden={this.props.hidden}>
<Message.Header>{this.props.header}</Message.Header>
<p>{this.props.message}</p>
</Message>
......
......@@ -23,7 +23,6 @@ class UsersTable extends React.Component {
}
render() {
const { t, i18n } = this.props
console.log(t);
let rows = this.props.users.map((item)=>{
return(
<Table.Row key={item.id} onClick={()=>{this.props.selectable ? this.clicked(item.id) : null }}>
......
......@@ -64,6 +64,7 @@ class AddUserModal extends Component {
//user yet to Search
return(
<div>
<p>Seleziona l'utente da inserire nel team, ti basta cliccare sulla sua riga</p>
<UsersPagination
selectUser={this.selectUser}
userSelected = {this.userSelected.bind(this)}
......@@ -81,12 +82,12 @@ class AddUserModal extends Component {
}else if(this.state.done){
//user added to team
return(
<PositiveMessage header="Tutto ok!" message="L'utente è stato aggiunto correttamente al team :)" />
<PositiveMessage header="Tutto ok!" message="L'utente è stato aggiunto correttamente al team :)" hidden={false}/>
)
}else if(this.state.error) {
//errors in the operation
return(
<NegativeMessage header="Errore!" message="L'utente non è stato aggiunto al team, riprova più tardi :(" />
<NegativeMessage header="Errore!" message="L'utente non è stato aggiunto al team, riprova più tardi :(" hidden={false}/>
)
}
}
......
......@@ -138,13 +138,13 @@ class CreateUserModal extends Component {
)
}else if(this.state.error && !this.state.userCreated && !this.state.addedToTeam){
//error, user not created nor added to team
return(<ErrorMessage header="Errore" message="Utente non creato per un errore, riprova più tardi o contatta il supporto"/>)
return(<ErrorMessage header="Errore" message="Utente non creato per un errore, riprova più tardi o contatta il supporto" hidden={false}/>)
}else if(this.state.error && this.state.userCreated && !this.state.addedToTeam){
//error, user created but non added to team
return(<ErrorMessage header="Errore" message="Utente creato ma non aggiunto al team per un errore interno, puoi farlo manualmente con la scheda Aggiungi Utente"/>)
return(<ErrorMessage header="Errore" message="Utente creato ma non aggiunto al team per un errore interno, puoi farlo manualmente con la scheda Aggiungi Utente" hidden={false}/>)
}else if(!this.state.error && this.state.userCreated && this.state.addedToTeam){
//positive, user created and added to team
return(<PositiveMessage header="Perfetto!" message="Utente creato e aggiunto al team, tutto ok :)"/>)
return(<PositiveMessage header="Perfetto!" message="Utente creato e aggiunto al team, tutto ok :)" hidden={false}/>)
}else return(<div></div>)
}
......
......@@ -6,6 +6,9 @@ import NegativeMessage from '../components/ErrorMessage'
import UsersPagination from './UsersPagination'
import {apolloFetch, apolloFetchNoAuth} from '../../store/apolloFetchUtils'
import {connect} from 'react-redux'
import {saveTeams,saveRoles,saveUserTeams} from '../../store/actions/AdministrationActions'
import { translate, Trans } from 'react-i18next'
class ManageTeamModal extends Component {
constructor(props){
......@@ -49,7 +52,7 @@ class ManageTeamModal extends Component {
removeUser(id){
let query = `
mutation delUser {
deleteCaaUser(id: ${this.state.idToDelete}){
deleteCaaUser(id: ${id}){
id
}
}
......@@ -61,6 +64,7 @@ class ManageTeamModal extends Component {
this.setState({removed: false, loading: false, error: true});
}else{
this.setState({removed: true, loading: false, error: false});
this.props.saveUserTeams
}
})
.catch((error) => {
......@@ -82,6 +86,8 @@ class ManageTeamModal extends Component {
manageUsers={true}
modUser={this.modUser.bind(this)}
removeUser={this.removeUser.bind(this)}/>
<PositiveMessage header="Tutto ok!" message="Utente eliminato correttamente dal team :)" hidden={!this.state.removed}/>
<NegativeMessage header="Errore!" message="Non è stato possibile rimuovere l'utente da questo team, riprova più tardi" hidden={!this.state.error}/>
</Modal.Content>
<Modal.Actions>
{buttonsLayout}
......@@ -90,4 +96,14 @@ class ManageTeamModal extends Component {
)
}
}
export default ManageTeamModal
const mapStateToProps = (state)=>{
return{}
}
const mapDispatchToProps = (dispatch) => {
return {
saveTeamsToStore: dispatch(saveTeams()),
saveRolesToStore: dispatch(saveRoles()),
saveUserTeamsToStore: dispatch(saveUserTeams())
}
}
export default connect(mapStateToProps,mapDispatchToProps)(translate('translations')(ManageTeamModal))
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import UsersTable from '../components/UsersTable'
import ErrorMessage from '../components/ErrorMessage'
import {Loader, Dimmer} from 'semantic-ui-react'
import {apolloFetch, apolloFetchNoAuth} from '../../store/apolloFetchUtils'
class ManageTeamTable extends Component {
constructor(props) {
super(props)
}
remove(id){
this.props.removeUser(id)
}
mod(id){
this.props.modUser(id)
}
render(){
return (
<div>
<UsersTable
users={this.state.users}
selectable={false}
manageUsers={true}
modUser={this.props.modUser.bind(this)}
removeUser={this.remove.bind(this)}
/>
<ErrorMessage header="Errore!" message="Errore nel caricare gli utenti, prova a caricare un'altra pagina."/>
</div>
)
}
}
export default ManageTeamTable
......@@ -28,26 +28,7 @@ class UsersPagination extends Component {
if(this.state.activePage == 1) this.queryNewPage()
}
queryNewPage(){
let query = ``
if(this.props.manageUsers){
query=`
query getUsersPaginated{
users_teams(limit: 4, page: ${this.state.activePage}) {
total
data{
id
name
user
email
organization
link_web
role_id
}
}
}
`
}else{
query=`
let query=`
query getUsersPaginated{
caa_users(limit: 4, page: ${this.state.activePage}) {
total
......@@ -63,7 +44,6 @@ class UsersPagination extends Component {
}
}
`
}
//query users for the selected page
this.setState({loading:true})
apolloFetch({query})
......@@ -108,7 +88,7 @@ class UsersPagination extends Component {
userSelected={this.clicked.bind(this)}
manageUsers={this.props.manageUsers}
modUser={this.props.modUser.bind(this)}
removeUser={this.props.removeUser.bind(this)}
removeUser={this.remove.bind(this)}
/>
<Pagination totalPages={this.state.nPages} activePage={this.state.activePage}
onPageChange={this.handlePaginationChange}/>
......
import {apolloFetch, apolloFetchNoAuth} from '../apolloFetchUtils'
export function closeModal() {
return (dispatch) => {
dispatch({
......@@ -35,13 +37,68 @@ export function openModalManageTeam(team_id=-1) {
}
}
}
export function saveAdminData(roles, teams, user_teams) {
return (dispatch) => {
dispatch({
type: "SAVE_ADMIN_DATA",
roles,
teams,
user_teams
})
export function saveRoles(){
return(dispatch)=>{
let query = `
query getRoles{
roles{
data {
id
role_desc
}
}
}
`
apolloFetch({query})
.then((data)=>{
dispatch({
type: "SAVE_ADMIN_ROLES",
roles: data.data.roles.data
})
})
}
}
export function saveTeams(){
return(dispatch)=>{
let query = `
query getTeams{
team{
data {
id
name
email
}
}
}
`
apolloFetch({query})
.then((data)=>{
dispatch({
type: "SAVE_ADMIN_TEAMS",
teams: data.data.team.data
})
})
}
}
export function saveUserTeams(){
return(dispatch)=>{
let query = `
query getUserTeams{
user_teams{
data{
userteam_id
user_id
team_id
}
}
}
`
apolloFetch({query})
.then((data)=>{
dispatch({
type: "SAVE_ADMIN_USER_TEAMS",
user_teams: data.data.user_teams.data
})
})
}
}
......@@ -39,10 +39,24 @@ export function modalReducer(state = {openModal: false, modalContent: "none", to
export function adminReducer(state = {roles: [], teams: [], user_teams: []}, action){
let newState=null
switch (action.type){
case "SAVE_ADMIN_DATA":
case "SAVE_ADMIN_ROLES":
newState = Object.assign({}, state,{
roles: action.roles,
teams: state.teams,
user_teams: state.user_teams
});
return newState
case "SAVE_ADMIN_TEAMS":
newState = Object.assign({}, state,{
roles: state.roles,
teams: action.teams,
user_teams: state.user_teams
});
return newState
case "SAVE_ADMIN_USER_TEAMS":
newState = Object.assign({}, state,{
roles: state.roles,
teams: state.teams,
user_teams: action.user_teams
});
return newState
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment