import { Col } from 'web/components/layout/col' import { SEO } from 'web/components/SEO' import { Title } from 'web/components/title' import { usePrivateUser, useUser } from 'web/hooks/use-user' import { Page } from 'web/components/page' import { useTracking } from 'web/hooks/use-tracking' import { redirectIfLoggedOut } from 'web/lib/firebase/server-auth' import { Button } from 'web/components/button' import { convertmana } from 'web/lib/firebase/api' import { formatMoney } from 'common/util/format' import { useEffect, useState } from 'react' import { Modal } from 'web/components/layout/modal' import { Row } from 'web/components/layout/row' import { LoadingIndicator } from 'web/components/loading-indicator' export const getServerSideProps = redirectIfLoggedOut('/') export default function RedeemManaPage() { const [open, setOpen] = useState(false) const [loading, setLoading] = useState(false) const [success, setSuccess] = useState(false) const [error, setError] = useState('') const user = useUser() const privateUser = usePrivateUser(user?.id) useTracking('view redeem mana page') const cost = 7500 useEffect(() => { if (open) setSuccess(false) setError('') }, [open]) if (!user || !privateUser) return const onClick = async () => { if (user.balance < cost) { setError('You do not have enough mana to redeem.') return } setLoading(true) try { await convertmana({}) setSuccess(true) } catch (e) { setError((e as any).message) setSuccess(false) } setLoading(false) } return ( For {formatMoney(cost)} you can get a $50 gift card from: • Amazon • Starbucks • Best Buy • And more! You'll get an email with more details upon redemption. { setOpen(!open) }} > {' '} Redeem {formatMoney(cost)} {success ? ( 🎉 Thanks! You'll see your gift card in your inbox within the next few minutes! ) : ( <> You will be charged:{' '} {formatMoney(cost)} A $50 gift card of your choice will be sent to: {privateUser.email} Do you want to continue? {error} {loading ? 'Loading...' : 'Confirm'} setOpen(false)}> Cancel > )} ) }