All files / src/containers/QuestionnarieDetails/components/SplitterPaneLayout ConfirmationPopUp.js

0% Statements 0/26
0% Branches 0/14
0% Functions 0/3
0% Lines 0/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
import React, { Component } from 'react';
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, withMobileDialog } from '@material-ui/core';
 
class ConfirmationPopUp extends Component {
    constructor(props) {
        super(props);
  
        const { open, msg, leftLabel, leftAction, rightLabel, rightAction, onCloseAction } = this.props;
        this.state = { open, msg, leftLabel, leftAction, rightLabel, rightAction, onCloseAction };
    }
 
    componentWillReceiveProps(nextProps) {
        let { open, msg, leftLabel, leftAction, rightLabel, rightAction, onCloseAction } = this.state;
        if (open !== nextProps.open) {
            open = nextProps.open;
        }
        if (msg !== nextProps.msg) {
            msg = nextProps.msg;
        }
        if (leftLabel !== nextProps.leftLabel) {
            leftLabel = nextProps.leftLabel;
        }
        if (leftAction !== nextProps.leftAction) {
            leftAction = nextProps.leftAction;
        }
        if (rightLabel !== nextProps.rightLabel) {
            rightLabel = nextProps.rightLabel;
        }
        if (rightAction !== nextProps.rightAction) {
            rightAction = nextProps.rightAction;
        }
        if (onCloseAction !== nextProps.onCloseAction) {
            onCloseAction = nextProps.onCloseAction;
        }
 
        this.setState({ open, msg, leftLabel, leftAction, rightLabel, rightAction, onCloseAction });
    }
 
    render() {
        const { open, msg, leftLabel, leftAction, rightLabel, rightAction, onCloseAction } = this.state;
        return (
            <Dialog
                open={open}
                onClose={onCloseAction}
                aria-labelledby="responsive-dialog-title"
            >
                <DialogTitle id="responsive-dialog-title">Confirmation</DialogTitle>
                <DialogContent>
                    <DialogContentText>
                        {msg}
                    </DialogContentText>
                </DialogContent>
                <DialogActions>
                    <Button
                        variant="outlined"
                        onClick={leftAction}
                        className="greenOutlinedButton"
                    >
                        {leftLabel}
                    </Button>
                    <Button
                        onClick={rightAction}
                        variant="contained"
                        className="greenButton"
                    >
                        {rightLabel}
                    </Button>
                </DialogActions>
            </Dialog>
        );
    }
}
 
export default withMobileDialog()(ConfirmationPopUp);