Show signup button if not signed up

This commit is contained in:
Sinclair Chen 2022-08-17 16:05:21 -07:00
parent 38a59245ff
commit b1c047430f
3 changed files with 40 additions and 27 deletions

View File

@ -9,6 +9,8 @@ import { BuyAmountInput } from './amount-input'
import { Button } from './button' import { Button } from './button'
import { Row } from './layout/row' import { Row } from './layout/row'
import { YesNoSelector } from './yes-no-selector' import { YesNoSelector } from './yes-no-selector'
import { useUser } from 'web/hooks/use-user'
import { SignUpPrompt } from './sign-up-prompt'
export function BetInline(props: { export function BetInline(props: {
contract: CPMMBinaryContract | PseudoNumericContract contract: CPMMBinaryContract | PseudoNumericContract
@ -16,8 +18,9 @@ export function BetInline(props: {
}) { }) {
const { contract, className } = props const { contract, className } = props
const [outcome, setOutcome] = useState<'YES' | 'NO'>('YES') const user = useUser()
const [outcome, setOutcome] = useState<'YES' | 'NO'>('YES')
const [amount, setAmount] = useState<number>() const [amount, setAmount] = useState<number>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
@ -64,18 +67,21 @@ export function BetInline(props: {
error="" // handle error ourselves error="" // handle error ourselves
setError={setError} setError={setError}
/> />
<Button {user && (
color={({ YES: 'green', NO: 'red' } as const)[outcome]} <Button
size="xs" color={({ YES: 'green', NO: 'red' } as const)[outcome]}
disabled={betDisabled} size="xs"
onClick={() => submitBet.mutate()} disabled={betDisabled}
> onClick={() => submitBet.mutate()}
{submitBet.isLoading >
? 'Submitting' {submitBet.isLoading
: submitBet.isSuccess ? 'Submitting'
? 'Success!' : submitBet.isSuccess
: 'Submit'} ? 'Success!'
</Button> : 'Submit'}
</Button>
)}
<SignUpPrompt size="xs" />
</Row> </Row>
) )
} }

View File

@ -1,20 +1,23 @@
import { ReactNode } from 'react' import { ReactNode } from 'react'
import clsx from 'clsx' import clsx from 'clsx'
export type SizeType = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
export type ColorType =
| 'green'
| 'red'
| 'blue'
| 'indigo'
| 'yellow'
| 'gray'
| 'gradient'
| 'gray-white'
export function Button(props: { export function Button(props: {
className?: string className?: string
onClick?: () => void onClick?: () => void
children?: ReactNode children?: ReactNode
size?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' size?: SizeType
color?: color?: ColorType
| 'green'
| 'red'
| 'blue'
| 'indigo'
| 'yellow'
| 'gray'
| 'gradient'
| 'gray-white'
type?: 'button' | 'reset' | 'submit' type?: 'button' | 'reset' | 'submit'
disabled?: boolean disabled?: boolean
}) { }) {

View File

@ -2,17 +2,21 @@ import React from 'react'
import { useUser } from 'web/hooks/use-user' import { useUser } from 'web/hooks/use-user'
import { firebaseLogin } from 'web/lib/firebase/users' import { firebaseLogin } from 'web/lib/firebase/users'
import { withTracking } from 'web/lib/service/analytics' import { withTracking } from 'web/lib/service/analytics'
import { Button } from './button' import { Button, SizeType } from './button'
export function SignUpPrompt(props: { label?: string; className?: string }) { export function SignUpPrompt(props: {
const { label, className } = props label?: string
className?: string
size?: SizeType
}) {
const { label, className, size = 'lg' } = props
const user = useUser() const user = useUser()
return user === null ? ( return user === null ? (
<Button <Button
onClick={withTracking(firebaseLogin, 'sign up to bet')} onClick={withTracking(firebaseLogin, 'sign up to bet')}
className={className} className={className}
size="lg" size={size}
color="gradient" color="gradient"
> >
{label ?? 'Sign up to bet!'} {label ?? 'Sign up to bet!'}