2022-09-09 06:02:22 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
import { Row } from './layout/row'
|
|
|
|
import { ConfirmationButton } from './confirmation-button'
|
|
|
|
import { ExclamationIcon } from '@heroicons/react/solid'
|
2022-09-27 00:28:54 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-09-30 05:41:22 +00:00
|
|
|
import { Button, ColorType, SizeType } from './button'
|
2022-10-04 20:52:53 +00:00
|
|
|
import { capitalize } from 'lodash'
|
2022-09-09 06:02:22 +00:00
|
|
|
|
|
|
|
export function WarningConfirmationButton(props: {
|
2022-09-27 00:28:54 +00:00
|
|
|
amount: number | undefined
|
2022-09-27 04:40:56 +00:00
|
|
|
marketType: 'freeResponse' | 'binary'
|
2022-09-09 06:02:22 +00:00
|
|
|
warning?: string
|
2022-10-04 20:52:53 +00:00
|
|
|
onSubmit?: () => void
|
2022-09-30 05:41:22 +00:00
|
|
|
disabled: boolean
|
2022-09-09 06:02:22 +00:00
|
|
|
isSubmitting: boolean
|
|
|
|
openModalButtonClass?: string
|
2022-09-30 05:41:22 +00:00
|
|
|
color: ColorType
|
|
|
|
size: SizeType
|
2022-10-04 20:52:53 +00:00
|
|
|
actionLabel?: string
|
2022-09-09 06:02:22 +00:00
|
|
|
}) {
|
|
|
|
const {
|
2022-09-27 00:28:54 +00:00
|
|
|
amount,
|
2022-09-09 06:02:22 +00:00
|
|
|
onSubmit,
|
|
|
|
warning,
|
|
|
|
disabled,
|
|
|
|
isSubmitting,
|
|
|
|
openModalButtonClass,
|
2022-09-30 05:41:22 +00:00
|
|
|
size,
|
|
|
|
color,
|
2022-10-04 20:52:53 +00:00
|
|
|
actionLabel,
|
2022-09-09 06:02:22 +00:00
|
|
|
} = props
|
2022-09-30 05:41:22 +00:00
|
|
|
|
2022-10-04 20:52:53 +00:00
|
|
|
const label = capitalize(actionLabel) ?? 'Wager'
|
|
|
|
const buttonText = isSubmitting
|
|
|
|
? 'Submitting...'
|
|
|
|
: amount
|
|
|
|
? `${label} ${formatMoney(amount)}`
|
|
|
|
: label
|
|
|
|
|
2022-09-09 06:02:22 +00:00
|
|
|
if (!warning) {
|
|
|
|
return (
|
2022-09-30 05:41:22 +00:00
|
|
|
<Button
|
|
|
|
size={size}
|
|
|
|
disabled={isSubmitting || disabled}
|
|
|
|
className={clsx(openModalButtonClass)}
|
2022-09-09 06:02:22 +00:00
|
|
|
onClick={onSubmit}
|
2022-09-30 05:41:22 +00:00
|
|
|
color={color}
|
2022-09-09 06:02:22 +00:00
|
|
|
>
|
2022-10-04 20:52:53 +00:00
|
|
|
{buttonText}
|
2022-09-30 05:41:22 +00:00
|
|
|
</Button>
|
2022-09-09 06:02:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmationButton
|
|
|
|
openModalBtn={{
|
2022-10-04 20:52:53 +00:00
|
|
|
label: buttonText,
|
2022-09-30 05:41:22 +00:00
|
|
|
size: size,
|
|
|
|
color: 'yellow',
|
2022-10-04 20:52:53 +00:00
|
|
|
disabled: isSubmitting || disabled,
|
2022-09-09 06:02:22 +00:00
|
|
|
}}
|
|
|
|
cancelBtn={{
|
|
|
|
label: 'Cancel',
|
2022-10-04 14:02:20 +00:00
|
|
|
color: 'yellow',
|
2022-09-09 06:02:22 +00:00
|
|
|
}}
|
|
|
|
submitBtn={{
|
|
|
|
label: 'Submit',
|
2022-10-04 14:02:20 +00:00
|
|
|
color: 'gray',
|
2022-09-09 06:02:22 +00:00
|
|
|
}}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
>
|
|
|
|
<Row className="items-center text-xl">
|
|
|
|
<ExclamationIcon
|
|
|
|
className="h-16 w-16 text-yellow-400"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
Whoa, there!
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
<p>{warning}</p>
|
|
|
|
</ConfirmationButton>
|
|
|
|
)
|
|
|
|
}
|