Advertisement
famiev

OrganizationPage

Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. // libs
  3. import page from 'lib/page'
  4. import styled from 'styled-components'
  5. import { object } from 'prop-types'
  6. import { compose, graphql } from 'react-apollo'
  7. import { connect } from 'react-redux'
  8. // components
  9. import MainLayout from 'layouts/MainLayout'
  10. import SectionHeader from 'components/SectionHeader'
  11. import Wrapper from 'components/Wrapper'
  12. import WizardOpenButton from 'components/UI-elements/Buttons/WizardOpenButton'
  13. import NewUserWizard from 'components/Organization/Wizards/NewUserWizard'
  14. import NewTeamWizard from 'components/Organization/Wizards/NewTeamWizard'
  15. import EditTeamWizard from 'components/Organization/Wizards/EditTeamWizard'
  16. import EditUserWizard from 'components/Organization/Wizards/EditUserWizard'
  17. import TableUsers from 'components/Organization/Tables/TableUsers'
  18. import TableTeams from 'components/Organization/Tables/TableTeams'
  19. // context
  20. import { modalTypes } from 'context/constants/modals'
  21. // graphql
  22. import { usersQuery } from 'graphql/queries/users'
  23. import { teamsQuery } from 'graphql/queries/teams'
  24. // utils
  25. import get from 'lodash/get'
  26.  
  27. const Container = styled.div`
  28. display: flex;
  29.  
  30. @media (max-width: 768px) {
  31. flex-direction: column;
  32. }
  33. `
  34.  
  35. class OrganizationPage extends Component {
  36. static propTypes = {
  37. usersData: object,
  38. teamsData: object
  39. }
  40.  
  41. refetchTeamsData = () => {
  42. this.props.teamsData.refetch()
  43. }
  44.  
  45. refetchUsersData = () => {
  46. this.props.usersData.refetch()
  47. }
  48.  
  49. render () {
  50. const { usersData } = this.props
  51. const { teamsData } = this.props
  52.  
  53. const users = get(usersData, 'users', [])
  54. const teams = get(teamsData, 'teams', [])
  55.  
  56. return (
  57. <MainLayout>
  58. <SectionHeader
  59. title='Organization'
  60. >
  61. <Container>
  62. <WizardOpenButton modalType={modalTypes.ORGANIZATION_NEW_USER_WIZARD}>
  63. Create new user
  64. </WizardOpenButton>
  65. <WizardOpenButton modalType={modalTypes.ORGANIZATION_NEW_TEAM_WIZARD} marginLeft='10px'>
  66. Create new team
  67. </WizardOpenButton>
  68. </Container>
  69. </SectionHeader>
  70. <Wrapper>
  71. <TableUsers normal data={users} tableName='Users' />
  72. <TableTeams data={teams} tableName='Teams' marginTop='50px' />
  73. </Wrapper>
  74. <NewUserWizard usersData={usersData} teams={teams} />
  75. <NewTeamWizard teamsData={teamsData} />
  76. <EditTeamWizard
  77. teamsData={teamsData}
  78. refetchTeamsData={this.refetchTeamsData}
  79. refetchUsersData={this.refetchUsersData}
  80. />
  81. <EditUserWizard teams={teams} refetchUsersData={this.refetchUsersData} />
  82. </MainLayout>
  83. )
  84. }
  85. }
  86.  
  87. const mapStateToProps = ({ currentUser }) => ({
  88. currentUser: currentUser.data.me
  89. })
  90.  
  91. export default compose(
  92. page({}),
  93. connect(mapStateToProps),
  94. graphql(usersQuery, {
  95. name: 'usersData',
  96. options: ({ currentUser }) => ({
  97. variables: {
  98. company_id: currentUser.company_id
  99. }
  100. })
  101. }),
  102. graphql(teamsQuery, {
  103. name: 'teamsData',
  104. options: ({ currentUser }) => ({
  105. variables: {
  106. company_id: currentUser.company_id
  107. }
  108. })
  109. })
  110. )(OrganizationPage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement