03f36cf954
* add id, userId to comment * change user info cloud function and script; move cleanUsername to common * change user info script * fix rules * add fund button: useLocation hook * profile page * merge * profile stuff * avatar uploading to storage bucket * changeUserInfo: use transaction * Styles for profile page * Edit mode for profile, and more styles Co-authored-by: James Grugett <jahooma@gmail.com>
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import clsx from 'clsx'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
|
import { checkoutURL } from '../lib/service/stripe'
|
|
import { FundsSelector } from './yes-no-selector'
|
|
|
|
export function AddFundsButton(props: { className?: string }) {
|
|
const { className } = props
|
|
const user = useUser()
|
|
|
|
const [amountSelected, setAmountSelected] = useState<
|
|
500 | 1000 | 2500 | 10000
|
|
>(500)
|
|
|
|
const location = useLocation()
|
|
|
|
return (
|
|
<>
|
|
<label
|
|
htmlFor="add-funds"
|
|
className={clsx(
|
|
'btn btn-xs btn-outline normal-case modal-button font-normal',
|
|
className
|
|
)}
|
|
>
|
|
Add funds
|
|
</label>
|
|
<input type="checkbox" id="add-funds" className="modal-toggle" />
|
|
|
|
<div className="modal">
|
|
<div className="modal-box">
|
|
<div className="text-xl mb-6">Get Manifold Dollars</div>
|
|
|
|
<div className="text-gray-500 mb-6">
|
|
Use Manifold Dollars to trade in your favorite markets. <br /> (Not
|
|
redeemable for cash.)
|
|
</div>
|
|
|
|
<div className="text-gray-500 text-sm mb-2">Amount</div>
|
|
<FundsSelector
|
|
selected={amountSelected}
|
|
onSelect={setAmountSelected}
|
|
/>
|
|
|
|
<div className="mt-6">
|
|
<div className="text-gray-500 text-sm mb-1">Price USD</div>
|
|
<div className="text-xl">
|
|
${Math.round(amountSelected / 100)}.00
|
|
</div>
|
|
</div>
|
|
|
|
<div className="modal-action">
|
|
<label htmlFor="add-funds" className={clsx('btn btn-ghost')}>
|
|
Back
|
|
</label>
|
|
|
|
<form
|
|
action={checkoutURL(user?.id || '', amountSelected, location)}
|
|
method="POST"
|
|
>
|
|
<button
|
|
type="submit"
|
|
className="btn btn-primary px-10 font-medium bg-gradient-to-r from-teal-500 to-green-500 hover:from-teal-600 hover:to-green-600"
|
|
>
|
|
Checkout
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
// needed in next js
|
|
// window not loaded at runtime
|
|
const useLocation = () => {
|
|
const [href, setHref] = useState('')
|
|
useEffect(() => {
|
|
setHref(window.location.href)
|
|
}, [])
|
|
return href
|
|
}
|