|
| 1 | +import { memo, useCallback, useState } from 'react'; |
| 2 | +import classnames from 'classnames'; |
| 3 | +import { Info } from 'react-feather'; |
| 4 | +import { useHistory } from 'react-router-dom'; |
| 5 | + |
| 6 | +import CloseButton from 'views/components/CloseButton'; |
| 7 | +import { useSelector } from 'react-redux'; |
| 8 | +import { State } from 'types/state'; |
| 9 | +import { BETA_BANNER } from 'storage/keys'; |
| 10 | +import storage from 'storage'; |
| 11 | +import styles from './BetaBanner.scss'; |
| 12 | + |
| 13 | +const key = BETA_BANNER; |
| 14 | + |
| 15 | +const BetaBanner = memo(() => { |
| 16 | + const history = useHistory(); |
| 17 | + const beta = useSelector(({ settings }: State) => settings.beta); |
| 18 | + const [isOpen, setIsOpen] = useState(() => { |
| 19 | + if (beta) return false; |
| 20 | + if (key) return !storage.getItem(key); |
| 21 | + return true; |
| 22 | + }); |
| 23 | + |
| 24 | + const dismiss = useCallback(() => { |
| 25 | + if (key) storage.setItem(key, true); |
| 26 | + setIsOpen(false); |
| 27 | + }, []); |
| 28 | + |
| 29 | + if (!isOpen) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className={classnames('alert alert-info no-export', styles.announcement)}> |
| 35 | + <Info className={styles.backgroundIcon} /> |
| 36 | + |
| 37 | + <div className={classnames(styles.body, styles.wrapButtons)}> |
| 38 | + <h3>Timetable Optimiser is now in BETA!</h3> |
| 39 | + <p className={styles.bodyElement}> |
| 40 | + Turn on NUSMods BETA to try out the new timetable optimiser to help you find your optimal |
| 41 | + timetable based on your preferences. |
| 42 | + </p> |
| 43 | + <p className={styles.bodyElement}>Share your feedback to help us make it even better!</p> |
| 44 | + <div className={styles.Betabutton}> |
| 45 | + <button |
| 46 | + className="btn btn-info" |
| 47 | + type="button" |
| 48 | + onClick={() => history.push('/settings#beta')} |
| 49 | + > |
| 50 | + Turn on BETA |
| 51 | + </button> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div className={styles.buttons}> |
| 56 | + <CloseButton onClick={dismiss} /> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ); |
| 60 | +}); |
| 61 | + |
| 62 | +export default BetaBanner; |
0 commit comments