Skip to content

Instantly share code, notes, and snippets.

@grantglidewell
Last active June 27, 2018 17:50
Show Gist options
  • Save grantglidewell/d1f6376d8831703482320c9356086398 to your computer and use it in GitHub Desktop.
Save grantglidewell/d1f6376d8831703482320c9356086398 to your computer and use it in GitHub Desktop.
// 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)
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
})
}
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