add fund button: useLocation hook

This commit is contained in:
mantikoros 2022-01-26 17:40:25 -06:00
parent 48bbbc46c8
commit 363a7ba7ae

View File

@ -1,5 +1,5 @@
import clsx from 'clsx' import clsx from 'clsx'
import { useState } from 'react' import { useEffect, useState } from 'react'
import { useUser } from '../hooks/use-user' import { useUser } from '../hooks/use-user'
import { checkoutURL } from '../lib/service/stripe' import { checkoutURL } from '../lib/service/stripe'
@ -13,6 +13,8 @@ export function AddFundsButton(props: { className?: string }) {
500 | 1000 | 2500 | 10000 500 | 1000 | 2500 | 10000
>(500) >(500)
const location = useLocation()
return ( return (
<> <>
<label <label
@ -54,11 +56,7 @@ export function AddFundsButton(props: { className?: string }) {
</label> </label>
<form <form
action={checkoutURL( action={checkoutURL(user?.id || '', amountSelected, location)}
user?.id || '',
amountSelected,
window.location.href
)}
method="POST" method="POST"
> >
<button <button
@ -74,3 +72,13 @@ export function AddFundsButton(props: { className?: string }) {
</> </>
) )
} }
// needed in next js
// window not loaded at runtime
const useLocation = () => {
const [href, setHref] = useState('')
useEffect(() => {
setHref(window.location.href)
}, [])
return href
}