diff options
Diffstat (limited to 'components/Popup.js')
-rw-r--r-- | components/Popup.js | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/components/Popup.js b/components/Popup.js index 911d2fa..3df11c5 100644 --- a/components/Popup.js +++ b/components/Popup.js @@ -1,32 +1,24 @@ -import React, {useState, useEffect} from 'react' +import React from 'react' +import usePopup from 'hooks/usePopup' -const Popup = ({popup}) => { - const [visible, setVisible] = useState(false) - const { - content = null, - time = null, - error = null, - yes = null, - no = null, - } = popup +const Popup = () => { + const {popupData: p} = usePopup() - useEffect(() => { - setVisible(true) - time && setTimeout(() => setVisible(false), time) - }, [popup]) + if (!p || !p.content) return null - if (!content) return null - - return visible ? ( - <div className={`window window--popup${error ? ' window--error' : ''}`}> - <div className="window__content--popup">{ content }</div> + return ( + <div className={`window window--popup${p.error ? ' window--error' : ''}`}> + <div className="window__content--popup">{p.content}</div> { - (yes || no) && (<div className="window__buttons--popup"> - {[yes, no].map(a => a && <input key={a.label} className='window__button' type="button" onClick={() => { setVisible(false); a.action() }} value={a.label} />)} - </div>) + (p.yes || p.no) && ( + <div className="window__buttons--popup"> + {[p.no, p.yes].map(a => a && <input key={a.label} className='window__button' type="button" onClick={async () => a.action()} value={a.label} />)} + </div> + ) } </div> - ) : null + ) } export default Popup + |