add loading for leaving opengroup dialog
parent
e4dae7f408
commit
15aa6b5ef9
@ -1,84 +1,63 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { updateConfirmModal } from '../../state/ducks/modalDialog';
|
import { updateConfirmModal } from '../../state/ducks/modalDialog';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
interface Props {
|
type Props = {
|
||||||
active: boolean;
|
active: boolean;
|
||||||
onClick: any;
|
onClick: () => void;
|
||||||
confirmationDialogParams?: any | undefined;
|
confirmationDialogParams?: any | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
updateConfirmModal?: any;
|
export const SessionToggle = (props: Props) => {
|
||||||
}
|
const [active, setActive] = useState(false);
|
||||||
|
|
||||||
interface State {
|
const dispatch = useDispatch();
|
||||||
active: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SessionToggle extends React.PureComponent<Props, State> {
|
|
||||||
public static defaultProps = {
|
|
||||||
onClick: () => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props: any) {
|
|
||||||
super(props);
|
|
||||||
this.clickHandler = this.clickHandler.bind(this);
|
|
||||||
|
|
||||||
const { active } = this.props;
|
|
||||||
|
|
||||||
this.state = {
|
useEffect(() => {
|
||||||
active: active,
|
setActive(props.active);
|
||||||
};
|
}, []);
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={classNames('session-toggle', this.state.active ? 'active' : '')}
|
|
||||||
role="button"
|
|
||||||
onClick={this.clickHandler}
|
|
||||||
>
|
|
||||||
<div className="knob" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private clickHandler(event: any) {
|
const clickHandler = (event: any) => {
|
||||||
const stateManager = (e: any) => {
|
const stateManager = (e: any) => {
|
||||||
this.setState({
|
setActive(!active);
|
||||||
active: !this.state.active,
|
e.stopPropagation();
|
||||||
});
|
props.onClick();
|
||||||
|
|
||||||
if (this.props.onClick) {
|
|
||||||
e.stopPropagation();
|
|
||||||
this.props.onClick();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (props.confirmationDialogParams && props.confirmationDialogParams.shouldShowConfirm()) {
|
||||||
this.props.confirmationDialogParams &&
|
|
||||||
this.props.updateConfirmModal &&
|
|
||||||
this.props.confirmationDialogParams.shouldShowConfirm()
|
|
||||||
) {
|
|
||||||
// If item needs a confirmation dialog to turn ON, render it
|
// If item needs a confirmation dialog to turn ON, render it
|
||||||
const closeConfirmModal = () => {
|
const closeConfirmModal = () => {
|
||||||
this.props.updateConfirmModal(null);
|
dispatch(updateConfirmModal(null));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.props.updateConfirmModal({
|
dispatch(
|
||||||
onClickOk: () => {
|
updateConfirmModal({
|
||||||
stateManager(event);
|
onClickOk: () => {
|
||||||
closeConfirmModal();
|
stateManager(event);
|
||||||
},
|
closeConfirmModal();
|
||||||
onClickClose: () => {
|
},
|
||||||
this.props.updateConfirmModal(null);
|
onClickClose: () => {
|
||||||
},
|
updateConfirmModal(null);
|
||||||
...this.props.confirmationDialogParams,
|
},
|
||||||
updateConfirmModal,
|
...props.confirmationDialogParams,
|
||||||
});
|
updateConfirmModal,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateManager(event);
|
stateManager(event);
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={classNames('session-toggle', active ? 'active' : '')}
|
||||||
|
role="button"
|
||||||
|
onClick={clickHandler}
|
||||||
|
>
|
||||||
|
<div className="knob" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue