material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

Dialog not showing on tab onActive

Open kkotwal94 opened this issue 10 years ago • 1 comments

My app is hierarchical and it inherits from parents in this case the "App" Component is the parent:

Im struggling to use this idea, where I have a navigation bar where on tab click of the tab "Login/Signup" a dialog/modal should appear. However it does not, i tried to follow the docs and the examples source but couldnt get it running. I used the handleOpen, handleClose functions as well. Here is how I went about it and below are some errors:

Failed propType: Required prop `open` was not specified in `Dialog`. Check the render method of `t`.
Failed propType: Invalid prop `children` supplied to `DialogInline`, expected a ReactNode
Failed propType: Required prop `open` was not specified in `DialogInline`.
Failed propType: Required prop `show` was not specified in `Overlay`. Check the render method of `DialogInline`

App.js

  import React from 'react';
import AltContainer from 'alt-container';
import UserStore from 'stores/UserStore';
import Navigation from 'components/Navigation';
import 'scss/main';
import injectTapEventPlugin from 'react-tap-event-plugin';
const ThemeManager = require('material-ui/lib/styles/theme-manager');
const ThemeDecorator = require('material-ui/lib/styles/theme-decorator');
import { PropTypes } from 'react-router';
const { Styles } = require('material-ui');
const DarkRawTheme = Styles.DarkRawTheme;
const DefaultRawTheme = Styles.LightRawTheme;

injectTapEventPlugin();
@ThemeDecorator(ThemeManager.getMuiTheme(DefaultRawTheme))
export default class App extends React.Component {
  render() {
    return (
      <AltContainer stores={{
        UserStore: UserStore
      }}>
        <Navigation />
        {this.props.children}
      </AltContainer>
    );
  }
}

App.propTypes = { children: React.PropTypes.object };
App.contextTypes = { history: PropTypes.history };

Navigation.js

import React from 'react';
import { Link } from 'react-router';
import $ from 'jquery';
import UserActions from 'actions/UserActions';
import UserStore from 'stores/UserStore';
import Immutable from 'immutable';

const { AppBar,
      AppCanvas,
      Dialog,
      FontIcon,
      IconButton,
      EnhancedButton,
      Menu,
      Mixins,
      RaisedButton,
      Styles,
      Tab,
      Tabs,
      FlatButton,
      Paper} = require('material-ui');

const { StylePropable } = Mixins;
const { Colors, Spacing, Typography } = Styles;

import styles from 'scss/components/_navigation';
import {PropTypes} from 'react-router';

export default class Navigation extends React.Component {


  constructor(props) {
  super(props);
  this.state = UserStore.getState();
  this.state.open = false;
  }
  static contextTypes = {
        router: React.PropTypes.func
    }
  componentDidMount() {
    //console.log(window.location);
    //window.onresize = setTabsState;
    UserStore.listen(this._onChange);
    this.setState({ tabIndex: this._getSelectedIndex()});
    let setTabsState = function() {
      this.setState({renderTabs: !(document.body.clientWidth <= 871)});
    }.bind(this);
    setTabsState();
    //console.log(window.location);
    window.onresize = setTabsState;
  }

  componentWillUnmount() {
    UserStore.unlisten(this._onChange);
  }

  componentWillReceiveProps(nextProps, nextContext) {
    this.setState({
      tabIndex: this._getSelectedIndex()

    });
  }

  _onChange = () => {
    this.setState({
      user: UserStore.getState().user
    });
  }


  handleOpen = () => {
    this.setState({open: true});
  }

  handleClose = () => {
    this.setState({open: false});
  }

  _getSelectedIndex() {
    //console.log(this.context.history.isActive('/'));
    return this.context.history.isActive('/') ? '1' :
      this.context.history.isActive('/channels') ? '2' : 
      this.context.history.isActive('/profile') ? '3' :
      //this.context.history.isActive('/login') ? '4' :
      this.context.history.isActive('/about') ? '5' : '';
  }

  _handleTabChange = (value, e, tab) => {
    //console.log(this.context.history);
  if(tab.props.route != '/login') {
    this.context.history.pushState(null, tab.props.route);
    this.setState({tabIndex: this._getSelectedIndex()});
  }
  }

_onLogout = () => {
  UserActions.logout();
}

_getTabs() {
 let styles = {
      root: {
        backgroundColor: '#4527A0',
        position: 'fixed',
        height: 64,
        top: 0,
        right: 0,
        zIndex: 4,
        width: '100%',
      },
      container: {
        position: 'absolute',
        right: (Spacing.desktopGutter/2) + 48,
        bottom: 0,
      },
      span: {
        color: Colors.white,
        fontWeight: Typography.fontWeightLight,
        left: 65,
        top: 18,
        position: 'absolute',
        fontSize: 26,
      },
      svgLogoContainer: {
        position: 'fixed',
        width: 300,
        left: Spacing.desktopGutter,
      },
      svgLogo: {
        width: 65,
        height: 65,
        backgroundColor: '#4527A0',
        position: 'absolute',
        top: 0,
      },
      tabs: {
        width: 600,
        bottom:0
      },
      tab: {
        height: 64,
        backgroundColor: '#4527A0'
      },

    };


     const actions = [
      <FlatButton
        label="Cancel"
        secondary={true}
        onTouchTap={this.handleClose} />,
      <FlatButton
        label="Submit"
        primary={true}
        keyboardFocused={true}
        onTouchTap={this.handleClose} />,
    ];

    let renderedResult;

    if (this.state.user.get('authenticated')) {
    renderedResult = (

        <Paper zDepth={0}
             rounded={false}
             style={styles.root}
        >

      <EnhancedButton
        style={styles.svgLogoContainer}
        linkButton={true}
        href="/">

        <span style={styles.span}>Classrm.tv</span>
      </EnhancedButton>

          <div style={styles.container}>
            <Tabs
              style={styles.tabs}
              value={this.state.tabIndex}
              onChange={this._handleTabChange}>
              <Tab
                value="1"
                label="DASHBOARD"
                style={styles.tab}
                route="/" />
              <Tab
                value="2"
                label="CHANNELS"
                style={styles.tab}
                route="/channels" />
              <Tab
                value="3"
                label="PROFILE"
                style={styles.tab}
                route="/profile"/>
              <Tab
                value="6"
                label="LOGOUT"
                style={styles.tab}
                onClick ={this._onLogout}
                route="/"/>

                <Tab
                value="5"
                label="ABOUT"
                style={styles.tab}
                route="/about" />
            </Tabs>


          </div>

        </Paper>


    );
}

else {
  renderedResult = (

        <Paper zDepth={0}
             rounded={false}
             style={styles.root}
        >

      <EnhancedButton
        style={styles.svgLogoContainer}
        linkButton={true}
        href="/">

        <span style={styles.span}>Classrm.tv</span>
      </EnhancedButton>

          <div style={styles.container}>
            <Tabs
              style={styles.tabs}
              value={this.state.tabIndex}
              onChange={this._handleTabChange}>
              <Tab
                value="1"
                label="DASHBOARD"
                style={styles.tab}
                route="/" />
              <Tab
                value="2"
                label="CHANNELS"
                style={styles.tab}
                route="/channels" />
              <Tab
                value="4"
                label="LOGIN/SIGNUP"
                style={styles.tab}
                onActive={this.handleOpen}
                route="/login">

                <Dialog>
                title="Dialog With Actions"
                  actions={actions}
                  modal={false}
                  open={this.state.open}
                  onRequestClose={this.handleClose}>
                  Random text
                </Dialog>

                </Tab>

                <Tab
                value="5"
                label="ABOUT"
                style={styles.tab}
                route="/about" />
            </Tabs>


          </div>

        </Paper>

    );
}
return (
      <div>
        {renderedResult}
      </div>

    );
}

_getAppBar() {
    let title =
      this.context.history.isActive('/') ? 'Dashboard' :
      this.context.history.isActive('/channels') ? 'Channels' : 
      this.context.history.isActive('/profile') ? 'Profile' :
     // this.context.history.isActive('/login') ? 'Login' : '':
      this.context.history.isActive('/about') ? 'About' : '';

    let githubButton = (
      <IconButton
        iconClassName="muidocs-icon-custom-github"
        href="https://github.com/callemall/material-ui"
        linkButton={true}/>
    );

    return (
      <div>
        <AppBar
          onLeftIconButtonTouchTap={this._onLeftIconButtonTouchTap}
          title={title}
          zDepth={0}
          iconElementRight={githubButton}
          style={{position: 'fixed', top: 0, backgroundColor: '#4527A0'}}/>
      </div>);
  }


_onLeftIconButtonTouchTap() {
    //do something
  }

render() {
//console.log(this.state.user);
//console.log(this.state.open);
let renderedresult;

let title =
      this.context.history.isActive('/') ? 'Dashboard' :
      this.context.history.isActive('/channels') ? 'Channels' : 
      this.context.history.isActive('/profile') ? 'Profile' :
      //this.context.history.isActive('/login') ? 'Login' : 
      this.context.history.isActive('/about') ? 'About' : '';



    let githubButton = (
      <IconButton
        iconStyle={styles.iconButton}
        iconClassName="muidocs-icon-custom-github"
        href="https://github.com/callemall/material-ui"
        linkButton={true}
        style={styles.github} />
    );

    let githubButton2 = (
      <IconButton
        iconStyle={styles.iconButton}
        iconClassName="muidocs-icon-custom-github"
        href="https://github.com/callemall/material-ui"
        linkButton={true}/>
    );



    return (
      <AppCanvas>
        {githubButton}
        {this.state.renderTabs ? this._getTabs(): this._getAppBar()}



      </AppCanvas>
    );
  }


}

Navigation.contextTypes = { history: PropTypes.history };
Navigation.propTypes = { UserStore: React.PropTypes.object };

kkotwal94 avatar Dec 20 '15 21:12 kkotwal94

Was a derp moment forgot to include it, and put it in the wrong render

kkotwal94 avatar Dec 25 '15 00:12 kkotwal94