mango-ui-v3/components/AlphaModal.tsx

150 lines
5.1 KiB
TypeScript
Raw Normal View History

2021-11-04 05:25:11 -07:00
import React, { useState } from 'react'
2021-11-01 05:35:26 -07:00
import { CheckCircleIcon } from '@heroicons/react/outline'
2021-04-15 09:34:59 -07:00
import Modal from './Modal'
import Button from './Button'
import useLocalStorageState from '../hooks/useLocalStorageState'
import { useTranslation } from 'next-i18next'
2021-10-26 04:05:48 -07:00
import Checkbox from './Checkbox'
2021-10-29 05:05:55 -07:00
import { SHOW_TOUR_KEY } from './IntroTips'
2021-10-31 04:21:22 -07:00
import { useViewport } from '../hooks/useViewport'
import { breakpoints } from './TradePageGrid'
2021-11-01 05:35:26 -07:00
import { useRouter } from 'next/router'
import { LANGS } from './LanguageSwitch'
import { RadioGroup } from '@headlessui/react'
2021-04-15 09:34:59 -07:00
2021-08-31 11:42:33 -07:00
export const ALPHA_MODAL_KEY = 'mangoAlphaAccepted-3.06'
2021-08-30 11:50:37 -07:00
const AlphaModal = ({
2021-04-15 09:34:59 -07:00
isOpen,
onClose,
}: {
isOpen: boolean
onClose?: (x) => void
}) => {
const { t } = useTranslation('common')
2021-10-26 04:05:48 -07:00
const [acceptRisks, setAcceptRisks] = useState(false)
2021-08-30 11:50:37 -07:00
const [, setAlphaAccepted] = useLocalStorageState(ALPHA_MODAL_KEY, false)
2021-10-29 05:05:55 -07:00
const [, setShowTips] = useLocalStorageState(SHOW_TOUR_KEY, false)
2021-11-01 05:35:26 -07:00
const [savedLanguage, setSavedLanguage] = useLocalStorageState('language', '')
2021-11-04 05:25:11 -07:00
const [language, setLanguage] = useState('en')
2021-11-01 05:35:26 -07:00
const router = useRouter()
const { pathname, asPath, query } = router
2021-10-31 04:21:22 -07:00
const { width } = useViewport()
const hideTips = width ? width < breakpoints.md : false
2021-08-01 05:48:15 -07:00
2021-11-04 05:25:11 -07:00
const handleLanguageSelect = () => {
setSavedLanguage(language)
router.push({ pathname, query }, asPath, { locale: language })
}
2021-11-01 05:35:26 -07:00
2021-10-29 05:05:55 -07:00
const handleGetStarted = () => {
2021-08-01 05:48:15 -07:00
setAlphaAccepted(true)
}
2021-04-15 09:34:59 -07:00
2021-10-29 05:05:55 -07:00
const handleTakeTour = () => {
setAlphaAccepted(true)
setShowTips(true)
}
2021-04-15 09:34:59 -07:00
return (
<Modal isOpen={isOpen} onClose={onClose} hideClose>
2021-04-15 09:34:59 -07:00
<Modal.Header>
<div className="flex flex-col items-center">
2021-10-26 04:05:48 -07:00
<div className="flex space-x-8 items-center justify-center">
2021-06-08 07:59:39 -07:00
<img
2021-08-25 11:47:57 -07:00
className={`h-12 w-auto`}
2021-06-08 07:59:39 -07:00
src="/assets/icons/logo.svg"
alt="next"
/>
</div>
2021-04-15 09:34:59 -07:00
</div>
</Modal.Header>
2021-10-26 04:05:48 -07:00
<h1 className="m-auto mb-4 relative w-max">
{t('v3-welcome')}
2021-10-26 04:05:48 -07:00
<span className="absolute bg-th-primary font-bold px-1.5 py-0.5 -right-8 rounded-full text-black text-xs -top-1 w-max">
V3
</span>
</h1>
2021-11-01 05:35:26 -07:00
{savedLanguage ? (
<>
<div className="bg-th-bkg-3 p-4 space-y-3 rounded-md">
<div className="flex items-center text-th-fgd-1">
<CheckCircleIcon className="flex-shrink-0 h-5 mr-2 text-th-green w-5" />
2021-11-04 05:25:11 -07:00
{t('intro-feature-1')}
2021-11-01 05:35:26 -07:00
</div>
<div className="flex items-center text-th-fgd-1">
<CheckCircleIcon className="flex-shrink-0 h-5 mr-2 text-th-green w-5" />
2021-11-04 05:25:11 -07:00
{t('intro-feature-2')}
2021-11-01 05:35:26 -07:00
</div>
<div className="flex items-center text-th-fgd-1">
<CheckCircleIcon className="flex-shrink-0 h-5 mr-2 text-th-green w-5" />
2021-11-04 05:25:11 -07:00
{t('intro-feature-3')}
2021-11-01 05:35:26 -07:00
</div>
<div className="flex items-center text-th-fgd-1">
<CheckCircleIcon className="flex-shrink-0 h-5 mr-2 text-th-green w-5" />
2021-11-04 05:25:11 -07:00
{t('intro-feature-4')}
2021-11-01 05:35:26 -07:00
</div>
</div>
<div className="px-6 text-th-fgd-3 text-center mt-4">
{t('v3-unaudited')}
</div>
<div className="border border-th-fgd-4 mt-4 p-3 rounded-md">
<Checkbox
checked={acceptRisks}
onChange={(e) => setAcceptRisks(e.target.checked)}
>
2021-11-04 05:25:11 -07:00
{t('accept-terms')}
2021-11-01 05:35:26 -07:00
</Checkbox>
</div>
<div className={`mt-6 flex justify-center space-x-4`}>
<Button
className="w-40"
disabled={!acceptRisks}
onClick={handleGetStarted}
>
2021-11-04 05:25:11 -07:00
{t('get-started')}
2021-11-01 05:35:26 -07:00
</Button>
{!hideTips ? (
<Button
className="w-40"
disabled={!acceptRisks}
onClick={handleTakeTour}
>
2021-11-04 05:25:11 -07:00
{t('show-tips')}
2021-11-01 05:35:26 -07:00
</Button>
) : null}
</div>
</>
) : (
<div className="pt-2">
2021-11-04 05:25:11 -07:00
<RadioGroup value={language} onChange={setLanguage}>
2021-11-01 05:35:26 -07:00
{LANGS.map((l) => (
2021-11-04 05:25:11 -07:00
<RadioGroup.Option className="" key={l.locale} value={l.locale}>
2021-11-01 05:35:26 -07:00
{({ checked }) => (
2021-11-04 05:25:11 -07:00
<div
className={`border ${
checked ? 'border-th-primary' : 'border-th-fgd-4'
} cursor-pointer default-transition flex items-center mb-2 p-3 rounded-md text-th-fgd-1 hover:border-th-primary`}
>
2021-11-01 05:35:26 -07:00
<CheckCircleIcon
className={`h-5 mr-2 w-5 ${
2021-11-04 05:25:11 -07:00
checked ? 'text-th-primary' : 'text-th-fgd-4'
2021-11-01 05:35:26 -07:00
}`}
/>
<span>{t(l.name.toLowerCase())}</span>
</div>
)}
</RadioGroup.Option>
))}
</RadioGroup>
2021-11-04 05:25:11 -07:00
<div className="flex justify-center pt-4">
<Button onClick={() => handleLanguageSelect()}>Save</Button>
</div>
2021-10-26 04:05:48 -07:00
</div>
2021-11-01 05:35:26 -07:00
)}
2021-04-15 09:34:59 -07:00
</Modal>
)
}
export default React.memo(AlphaModal)