-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract and refactor clear queue dialog
- Loading branch information
Showing
6 changed files
with
82 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,46 @@ | ||
/* eslint-disable react/jsx-handler-names */ | ||
import React from 'react'; | ||
import { Modal, Button } from 'react-bootstrap'; | ||
|
||
export default class ConfirmActionDialog extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.onOkClick = this.onOkClick.bind(this); | ||
this.onCancelClick = this.onCancelClick.bind(this); | ||
} | ||
function ConfirmActionDialog(props) { | ||
const { | ||
title, | ||
okBtnLabel = 'OK', | ||
cancelBtnLabel = 'Cancel', | ||
show = false, | ||
children, | ||
onHide, | ||
onOk, | ||
onCancel, | ||
} = props; | ||
|
||
onOkClick() { | ||
if (this.props.onOk) { | ||
this.props.onOk(); | ||
} | ||
|
||
this.props.hide(); | ||
} | ||
|
||
onCancelClick() { | ||
if (this.props.onCancel) { | ||
this.props.onCancel(); | ||
} | ||
|
||
this.props.hide(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Modal show={this.props.show}> | ||
<Modal.Header> | ||
<Modal.Title>{this.props.title}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{this.props.message}</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="outline-secondary" onClick={this.onCancelClick}> | ||
{this.props.cancelButtonText} | ||
</Button> | ||
<Button variant="outline-secondary" onClick={this.onOkClick}> | ||
{this.props.okButtonText} | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} | ||
return ( | ||
<Modal show={show} data-default-styles onHide={onHide}> | ||
<Modal.Header> | ||
<Modal.Title>{title}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{children}</Modal.Body> | ||
<Modal.Footer> | ||
<Button | ||
variant="warning" | ||
onClick={() => { | ||
onOk?.(); | ||
onHide(); | ||
}} | ||
> | ||
{okBtnLabel} | ||
</Button> | ||
<Button | ||
variant="outline-secondary" | ||
onClick={() => { | ||
onCancel?.(); | ||
onHide(); | ||
}} | ||
> | ||
{cancelBtnLabel} | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} | ||
|
||
ConfirmActionDialog.defaultProps = { | ||
show: false, | ||
title: '', | ||
message: '', | ||
okButtonText: 'Ok', | ||
cancelButtonText: 'Cancel', | ||
onOk: false, | ||
onCancel: false, | ||
}; | ||
export default ConfirmActionDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import ConfirmActionDialog from '../GenericDialog/ConfirmActionDialog'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { clearQueue } from '../../actions/queue'; | ||
import { showConfirmClearQueueDialog } from '../../actions/general'; | ||
|
||
function ClearQueueDialog() { | ||
const dispatch = useDispatch(); | ||
const show = useSelector( | ||
(state) => state.general.showConfirmClearQueueDialog, | ||
); | ||
|
||
return ( | ||
<ConfirmActionDialog | ||
title="Clear sample list?" | ||
okBtnLabel="Clear" | ||
show={show} | ||
onOk={() => dispatch(clearQueue())} | ||
onHide={() => dispatch(showConfirmClearQueueDialog(false))} | ||
> | ||
This will also <strong>clear the queue</strong>. | ||
</ConfirmActionDialog> | ||
); | ||
} | ||
|
||
export default ClearQueueDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters