Last active
June 27, 2018 17:50
-
-
Save grantglidewell/d1f6376d8831703482320c9356086398 to your computer and use it in GitHub Desktop.
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 is example data and will be replaced with the actual components when they are made public | |
import React, { Component } from 'react' | |
import { connect } from 'react-redux' | |
import styles from './Confirm.less' | |
const Confirm = props => { | |
return ( | |
(props.isOpen && ( | |
<section className={styles.confirmWrapper}> | |
<section className={styles.Confirm}> | |
<h1>{props.prompt}</h1> | |
<footer> | |
<ButtonGroup className={styles.buttons}> | |
<Button | |
onClick={() => { | |
props.callback(true) | |
props.dispatch({ type: 'REMOVE_CONFIRM'}) | |
}} | |
text="Continue" | |
/> | |
<Button | |
onClick={() => { | |
props.callback(false) | |
props.dispatch({ type: 'REMOVE_CONFIRM'}) | |
}} | |
text="Cancel" | |
/> | |
</ButtonGroup> | |
</footer> | |
</section> | |
</section> | |
)) || | |
null | |
) | |
} | |
export default connect(state => state.confirm)(Confirm) |
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
const initialState = { isOpen: false } | |
export function confirm(state = initialState, action) { | |
switch (action.type) { | |
case 'NEW_CONFIRM': | |
return { isOpen: true, ...action.data } | |
case 'REMOVE_CONFIRM': | |
return { isOpen: false } | |
default: | |
return state | |
} | |
} | |
export function zConfirm(data) { | |
if (!data.prompt) { | |
console.error('cannot confirm without a prompt') | |
} | |
if (!data.callback) { | |
console.error('cannot confirm without a callback') | |
} | |
return({ | |
type: 'NEW_CONFIRM', | |
data | |
}) | |
} |
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
zConfirm({ | |
prompt: 'string', | |
callback: result => { | |
if(result){ | |
// execute if confirmed | |
} | |
else{} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment