Added a loading state and some copy-changes
This commit is contained in:
parent
b762a414a1
commit
a8e02029f0
|
@ -22,6 +22,7 @@ export function ConfirmationButton(props: {
|
||||||
onSubmit?: () => void
|
onSubmit?: () => void
|
||||||
onOpenChanged?: (isOpen: boolean) => void
|
onOpenChanged?: (isOpen: boolean) => void
|
||||||
onSubmitWithSuccess?: () => Promise<boolean>
|
onSubmitWithSuccess?: () => Promise<boolean>
|
||||||
|
disabled?: boolean
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
openModalBtn,
|
openModalBtn,
|
||||||
|
@ -31,6 +32,7 @@ export function ConfirmationButton(props: {
|
||||||
children,
|
children,
|
||||||
onOpenChanged,
|
onOpenChanged,
|
||||||
onSubmitWithSuccess,
|
onSubmitWithSuccess,
|
||||||
|
disabled,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
@ -68,7 +70,15 @@ export function ConfirmationButton(props: {
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
</Modal>
|
</Modal>
|
||||||
<div className={openModalBtn.className} onClick={() => updateOpen(true)}>
|
<div
|
||||||
|
className={openModalBtn.className}
|
||||||
|
onClick={() => {
|
||||||
|
if (disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updateOpen(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
{openModalBtn.icon}
|
{openModalBtn.icon}
|
||||||
{openModalBtn.label}
|
{openModalBtn.label}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -35,7 +35,6 @@ import { getMappedValue } from 'common/pseudo-numeric'
|
||||||
import { Tooltip } from '../tooltip'
|
import { Tooltip } from '../tooltip'
|
||||||
import { SiteLink } from '../site-link'
|
import { SiteLink } from '../site-link'
|
||||||
import { ProbChange } from './prob-change-table'
|
import { ProbChange } from './prob-change-table'
|
||||||
import { ContractReportResolution } from './contract-report-resolution'
|
|
||||||
|
|
||||||
export function ContractCard(props: {
|
export function ContractCard(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
|
|
@ -7,23 +7,27 @@ import { ConfirmationButton } from '../confirmation-button'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { FlagIcon } from '@heroicons/react/solid'
|
import { FlagIcon } from '@heroicons/react/solid'
|
||||||
import { buildArray } from 'common/lib/util/array'
|
import { buildArray } from 'common/lib/util/array'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
export function ContractReportResolution(props: { contract: Contract }) {
|
export function ContractReportResolution(props: { contract: Contract }) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
const [reporting, setReporting] = useState(false)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
const userReported = contract.flaggedByUsernames?.includes(user.id)
|
const userReported = contract.flaggedByUsernames?.includes(user.id)
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
if (!user) {
|
if (!user || userReported) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
setReporting(true)
|
||||||
|
|
||||||
await updateContract(contract.id, {
|
await updateContract(contract.id, {
|
||||||
flaggedByUsernames: buildArray(contract.flaggedByUsernames, user.id),
|
flaggedByUsernames: buildArray(contract.flaggedByUsernames, user.id),
|
||||||
})
|
})
|
||||||
|
setReporting(false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +37,18 @@ export function ContractReportResolution(props: { contract: Contract }) {
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip text="Flag this market as incorrectly resolved">
|
<Tooltip
|
||||||
|
text={
|
||||||
|
userReported
|
||||||
|
? "You've reported this market as incorrectly resolved"
|
||||||
|
: 'Flag this market as incorrectly resolved '
|
||||||
|
}
|
||||||
|
>
|
||||||
<ConfirmationButton
|
<ConfirmationButton
|
||||||
openModalBtn={{
|
openModalBtn={{
|
||||||
label: '',
|
label: '',
|
||||||
icon: <FlagIcon className="h-5 w-5" />,
|
icon: <FlagIcon className="h-5 w-5" />,
|
||||||
className: flagClass,
|
className: clsx(flagClass, reporting && 'btn-disabled loading'),
|
||||||
}}
|
}}
|
||||||
cancelBtn={{
|
cancelBtn={{
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
|
@ -49,10 +59,18 @@ export function ContractReportResolution(props: { contract: Contract }) {
|
||||||
className: 'btn-secondary',
|
className: 'btn-secondary',
|
||||||
}}
|
}}
|
||||||
onSubmitWithSuccess={onSubmit}
|
onSubmitWithSuccess={onSubmit}
|
||||||
|
disabled={userReported}
|
||||||
>
|
>
|
||||||
|
<div>
|
||||||
<Row className="items-center text-xl">
|
<Row className="items-center text-xl">
|
||||||
Flag this market as incorrectly resolved
|
Flag this market as incorrectly resolved
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row className="text-sm text-gray-500">
|
||||||
|
Report that the market was not resolved according to its resolution
|
||||||
|
criteria. If a creator's markets get flagged too often, they'll be
|
||||||
|
marked as unreliable.
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
</ConfirmationButton>
|
</ConfirmationButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user