resolution panel: show errors, disable when submitting, rename confirm button

This commit is contained in:
mantikoros 2021-12-15 12:44:34 -06:00
parent 3ee03ffcba
commit f0e0796b99
3 changed files with 38 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import clsx from 'clsx' import clsx from 'clsx'
export function ConfirmationModal(props: { export function ConfirmationButton(props: {
id: string id: string
openModelBtn: { openModelBtn: {
label: string label: string

View File

@ -8,7 +8,7 @@ import { Title } from './title'
import { User } from '../lib/firebase/users' import { User } from '../lib/firebase/users'
import { YesNoCancelSelector } from './yes-no-selector' import { YesNoCancelSelector } from './yes-no-selector'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
import { ConfirmationModal } from './confirmation-modal' import { ConfirmationButton as ConfirmationButton } from './confirmation-button'
const functions = getFunctions() const functions = getFunctions()
export const resolveMarket = httpsCallable(functions, 'resolveMarket') export const resolveMarket = httpsCallable(functions, 'resolveMarket')
@ -18,13 +18,25 @@ export function ResolutionPanel(props: {
contract: Contract contract: Contract
className?: string className?: string
}) { }) {
const { creator, contract, className } = props const { contract, className } = props
const [outcome, setOutcome] = useState<'YES' | 'NO' | 'CANCEL' | undefined>() const [outcome, setOutcome] = useState<'YES' | 'NO' | 'CANCEL' | undefined>()
const [isSubmitting, setIsSubmitting] = useState(false)
const [error, setError] = useState<string | undefined>(undefined)
const resolve = async () => { const resolve = async () => {
setIsSubmitting(true)
const result = await resolveMarket({ outcome, contractId: contract.id }) const result = await resolveMarket({ outcome, contractId: contract.id })
console.log('resolved', outcome, 'result:', result.data) .then(r => r.data as any)
console.log('resolved', outcome, 'result:', result)
if (result?.status !== 'success') {
setError(result?.error || 'Error resolving market')
}
setIsSubmitting(false)
} }
const submitButtonClass = const submitButtonClass =
@ -46,14 +58,17 @@ export function ResolutionPanel(props: {
<Title className="mt-0" text="Your market" /> <Title className="mt-0" text="Your market" />
<div className="pt-2 pb-1 text-sm text-gray-400">Resolve outcome</div> <div className="pt-2 pb-1 text-sm text-gray-400">Resolve outcome</div>
<YesNoCancelSelector <YesNoCancelSelector
className="mx-auto my-2" className="mx-auto my-2"
selected={outcome} selected={outcome}
onSelect={setOutcome} onSelect={setOutcome}
btnClassName={isSubmitting ? 'btn-disabled' : ''}
/> />
<Spacer h={3} /> <Spacer h={3} />
<div> <div>
{outcome === 'YES' ? ( {outcome === 'YES' ? (
<> <>
@ -72,14 +87,20 @@ export function ResolutionPanel(props: {
)} )}
</div> </div>
<Spacer h={3} /> <Spacer h={3} />
<ConfirmationModal {!!error &&
<div className='text-red-500'>{error}</div>
}
<ConfirmationButton
id="resolution-modal" id="resolution-modal"
openModelBtn={{ openModelBtn={{
className: clsx( className: clsx(
'border-none self-start mt-2 w-full', 'border-none self-start mt-2 w-full',
submitButtonClass submitButtonClass,
isSubmitting && 'btn-disabled loading'
), ),
label: 'Resolve', label: 'Resolve',
}} }}
@ -93,7 +114,7 @@ export function ResolutionPanel(props: {
onSubmit={resolve} onSubmit={resolve}
> >
<p>Are you sure you want to resolve this market?</p> <p>Are you sure you want to resolve this market?</p>
</ConfirmationModal> </ConfirmationButton>
</Col> </Col>
) )
} }

View File

@ -32,15 +32,18 @@ export function YesNoCancelSelector(props: {
selected: 'YES' | 'NO' | 'CANCEL' | undefined selected: 'YES' | 'NO' | 'CANCEL' | undefined
onSelect: (selected: 'YES' | 'NO' | 'CANCEL') => void onSelect: (selected: 'YES' | 'NO' | 'CANCEL') => void
className?: string className?: string
btnClassName?: string
}) { }) {
const { selected, onSelect, className } = props const { selected, onSelect, className } = props
const btnClassName = clsx('px-6', props.btnClassName)
return ( return (
<Row className={clsx('space-x-3', className)}> <Row className={clsx('space-x-3', className)}>
<Button <Button
color={selected === 'YES' ? 'green' : 'gray'} color={selected === 'YES' ? 'green' : 'gray'}
onClick={() => onSelect('YES')} onClick={() => onSelect('YES')}
className="px-6" className={btnClassName}
> >
YES YES
</Button> </Button>
@ -48,7 +51,7 @@ export function YesNoCancelSelector(props: {
<Button <Button
color={selected === 'NO' ? 'red' : 'gray'} color={selected === 'NO' ? 'red' : 'gray'}
onClick={() => onSelect('NO')} onClick={() => onSelect('NO')}
className="px-6" className={btnClassName}
> >
NO NO
</Button> </Button>
@ -56,7 +59,7 @@ export function YesNoCancelSelector(props: {
<Button <Button
color={selected === 'CANCEL' ? 'yellow' : 'gray'} color={selected === 'CANCEL' ? 'yellow' : 'gray'}
onClick={() => onSelect('CANCEL')} onClick={() => onSelect('CANCEL')}
className="px-6" className={btnClassName}
> >
CANCEL CANCEL
</Button> </Button>