// @flow import Avatar from '@atlaskit/avatar'; import FieldText from '@atlaskit/field-text'; import ArrowLeft from '@atlaskit/icon/glyph/arrow-left'; import { AkCustomDrawer } from '@atlaskit/navigation'; import { SpotlightTarget } from '@atlaskit/onboarding'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import type { Dispatch } from 'redux'; import { closeDrawer, DrawerContainer, Logo } from '../../navbar'; import { Onboarding, startOnboarding } from '../../onboarding'; import { AvatarContainer, SettingsContainer } from '../styled'; import { setEmail, setName } from '../actions'; import ServerURLField from './ServerURLField'; import StartMutedToggles from './StartMutedToggles'; type Props = { /** * Redux dispatch. */ dispatch: Dispatch<*>; /** * Is the drawer open or not. */ isOpen: boolean; /** * Avatar URL. */ _avatarURL: string; /** * Email of the user. */ _email: string; /** * Name of the user. */ _name: string; }; /** * Drawer that open when SettingsAction is clicked. */ class SettingsDrawer extends Component { /** * Initializes a new {@code SettingsDrawer} instance. * * @inheritdoc */ constructor(props) { super(props); this._onBackButton = this._onBackButton.bind(this); this._onEmailBlur = this._onEmailBlur.bind(this); this._onEmailFormSubmit = this._onEmailFormSubmit.bind(this); this._onNameBlur = this._onNameBlur.bind(this); this._onNameFormSubmit = this._onNameFormSubmit.bind(this); } /** * Start Onboarding once component is mounted. * * NOTE: It automatically checks if the onboarding is shown or not. * * @param {Props} prevProps - Props before component updated. * @returns {void} */ componentDidUpdate(prevProps: Props) { if (!prevProps.isOpen && this.props.isOpen) { // TODO - Find a better way for this. // Delay for 300ms to let drawer open. setTimeout(() => { this.props.dispatch(startOnboarding('settings-drawer')); }, 300); } } /** * Render function of component. * * @returns {ReactElement} */ render() { return ( } isOpen = { this.props.isOpen } onBackButton = { this._onBackButton } primaryIcon = { } >
); } _onBackButton: (*) => void; /** * Closes the drawer when back button is clicked. * * @returns {void} */ _onBackButton() { this.props.dispatch(closeDrawer()); } _onEmailBlur: (*) => void; /** * Updates Avatar URL in (redux) state when email is updated. * * @param {SyntheticInputEvent} event - Event by which * this function is called. * @returns {void} */ _onEmailBlur(event: SyntheticInputEvent) { this.props.dispatch(setEmail(event.currentTarget.value)); } _onEmailFormSubmit: (*) => void; /** * Prevents submission of the form and updates email. * * @param {SyntheticEvent} event - Event by which * this function is called. * @returns {void} */ _onEmailFormSubmit(event: SyntheticEvent) { event.preventDefault(); // $FlowFixMe this.props.dispatch(setEmail(event.currentTarget.elements[0].value)); } _onNameBlur: (*) => void; /** * Updates Avatar URL in (redux) state when name is updated. * * @param {SyntheticInputEvent} event - Event by which * this function is called. * @returns {void} */ _onNameBlur(event: SyntheticInputEvent) { this.props.dispatch(setName(event.currentTarget.value)); } _onNameFormSubmit: (*) => void; /** * Prevents submission of the form and updates name. * * @param {SyntheticEvent} event - Event by which * this function is called. * @returns {void} */ _onNameFormSubmit(event: SyntheticEvent) { event.preventDefault(); // $FlowFixMe this.props.dispatch(setName(event.currentTarget.elements[0].value)); } } /** * Maps (parts of) the redux state to the React props. * * @param {Object} state - The redux state. * @returns {{ * _avatarURL: string, * _email: string, * _name: string * }} */ function _mapStateToProps(state: Object) { return { _avatarURL: state.settings.avatarURL, _email: state.settings.email, _name: state.settings.name }; } export default connect(_mapStateToProps)(SettingsDrawer);