2021-12-14 00:47:43 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-26 22:22:44 +00:00
|
|
|
import { ReactNode, useState } from 'react'
|
2022-09-30 05:41:22 +00:00
|
|
|
import { Button, ColorType, SizeType } from './button'
|
2022-03-31 09:09:08 +00:00
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Modal } from './layout/modal'
|
|
|
|
import { Row } from './layout/row'
|
2021-12-14 00:47:43 +00:00
|
|
|
|
2021-12-15 18:44:34 +00:00
|
|
|
export function ConfirmationButton(props: {
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalBtn: {
|
2021-12-14 00:47:43 +00:00
|
|
|
label: string
|
2022-06-03 00:40:41 +00:00
|
|
|
icon?: JSX.Element
|
2021-12-14 00:47:43 +00:00
|
|
|
className?: string
|
2022-09-30 05:41:22 +00:00
|
|
|
color?: ColorType
|
|
|
|
size?: SizeType
|
|
|
|
disabled?: boolean
|
2021-12-14 00:47:43 +00:00
|
|
|
}
|
|
|
|
cancelBtn?: {
|
|
|
|
label?: string
|
|
|
|
className?: string
|
|
|
|
}
|
|
|
|
submitBtn?: {
|
|
|
|
label?: string
|
|
|
|
className?: string
|
2022-10-03 20:33:00 +00:00
|
|
|
isSubmitting?: boolean
|
2021-12-14 00:47:43 +00:00
|
|
|
}
|
2022-05-26 22:22:44 +00:00
|
|
|
children: ReactNode
|
2022-06-22 16:35:50 +00:00
|
|
|
onSubmit?: () => void
|
|
|
|
onOpenChanged?: (isOpen: boolean) => void
|
|
|
|
onSubmitWithSuccess?: () => Promise<boolean>
|
2022-10-03 09:49:19 +00:00
|
|
|
disabled?: boolean
|
2021-12-14 00:47:43 +00:00
|
|
|
}) {
|
2022-06-22 16:35:50 +00:00
|
|
|
const {
|
|
|
|
openModalBtn,
|
|
|
|
cancelBtn,
|
|
|
|
submitBtn,
|
|
|
|
onSubmit,
|
|
|
|
children,
|
|
|
|
onOpenChanged,
|
|
|
|
onSubmitWithSuccess,
|
2022-10-03 09:49:19 +00:00
|
|
|
disabled,
|
2022-06-22 16:35:50 +00:00
|
|
|
} = props
|
2021-12-14 00:47:43 +00:00
|
|
|
|
2022-03-31 09:09:08 +00:00
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
function updateOpen(newOpen: boolean) {
|
|
|
|
onOpenChanged?.(newOpen)
|
|
|
|
setOpen(newOpen)
|
|
|
|
}
|
|
|
|
|
2021-12-14 00:47:43 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-06-22 16:35:50 +00:00
|
|
|
<Modal open={open} setOpen={updateOpen}>
|
2022-03-31 09:09:08 +00:00
|
|
|
<Col className="gap-4 rounded-md bg-white px-8 py-6">
|
2021-12-14 00:47:43 +00:00
|
|
|
{children}
|
2022-03-31 09:09:08 +00:00
|
|
|
<Row className="gap-4">
|
2022-06-22 16:35:50 +00:00
|
|
|
<div
|
2022-09-09 06:02:22 +00:00
|
|
|
className={clsx('btn', cancelBtn?.className)}
|
2022-06-22 16:35:50 +00:00
|
|
|
onClick={() => updateOpen(false)}
|
2022-03-31 09:09:08 +00:00
|
|
|
>
|
2021-12-14 00:47:43 +00:00
|
|
|
{cancelBtn?.label ?? 'Cancel'}
|
2022-06-22 16:35:50 +00:00
|
|
|
</div>
|
2022-10-03 20:33:00 +00:00
|
|
|
<Button
|
2022-09-09 06:02:22 +00:00
|
|
|
className={clsx('btn', submitBtn?.className)}
|
2022-06-22 16:35:50 +00:00
|
|
|
onClick={
|
|
|
|
onSubmitWithSuccess
|
|
|
|
? () =>
|
|
|
|
onSubmitWithSuccess().then((success) =>
|
|
|
|
updateOpen(!success)
|
|
|
|
)
|
|
|
|
: onSubmit
|
|
|
|
}
|
2022-10-03 20:33:00 +00:00
|
|
|
loading={submitBtn?.isSubmitting}
|
2021-12-14 00:47:43 +00:00
|
|
|
>
|
|
|
|
{submitBtn?.label ?? 'Submit'}
|
2022-10-03 20:33:00 +00:00
|
|
|
</Button>
|
2022-03-31 09:09:08 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Modal>
|
2022-10-03 09:49:19 +00:00
|
|
|
|
2022-09-30 05:41:22 +00:00
|
|
|
<Button
|
2022-10-03 09:49:19 +00:00
|
|
|
className={openModalBtn.className}
|
|
|
|
onClick={() => {
|
|
|
|
if (disabled) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
updateOpen(true)
|
|
|
|
}}
|
2022-09-30 05:41:22 +00:00
|
|
|
disabled={openModalBtn.disabled}
|
|
|
|
color={openModalBtn.color}
|
|
|
|
size={openModalBtn.size}
|
2022-03-31 09:09:08 +00:00
|
|
|
>
|
2022-06-22 16:35:50 +00:00
|
|
|
{openModalBtn.icon}
|
2022-03-31 09:09:08 +00:00
|
|
|
{openModalBtn.label}
|
2022-09-30 05:41:22 +00:00
|
|
|
</Button>
|
2021-12-14 00:47:43 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-02-17 23:00:19 +00:00
|
|
|
|
|
|
|
export function ResolveConfirmationButton(props: {
|
|
|
|
onResolve: () => void
|
|
|
|
isSubmitting: boolean
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalButtonClass?: string
|
2022-02-17 23:00:19 +00:00
|
|
|
submitButtonClass?: string
|
2022-09-30 05:41:22 +00:00
|
|
|
color?: ColorType
|
|
|
|
disabled?: boolean
|
2022-02-17 23:00:19 +00:00
|
|
|
}) {
|
2022-09-30 05:41:22 +00:00
|
|
|
const {
|
|
|
|
onResolve,
|
|
|
|
isSubmitting,
|
|
|
|
openModalButtonClass,
|
|
|
|
submitButtonClass,
|
|
|
|
color,
|
|
|
|
disabled,
|
|
|
|
} = props
|
2022-02-17 23:00:19 +00:00
|
|
|
return (
|
|
|
|
<ConfirmationButton
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalBtn={{
|
2022-09-30 05:41:22 +00:00
|
|
|
className: clsx('border-none self-start', openModalButtonClass),
|
2022-02-17 23:00:19 +00:00
|
|
|
label: 'Resolve',
|
2022-09-30 05:41:22 +00:00
|
|
|
color: color,
|
|
|
|
disabled: isSubmitting || disabled,
|
|
|
|
size: 'xl',
|
2022-02-17 23:00:19 +00:00
|
|
|
}}
|
|
|
|
cancelBtn={{
|
|
|
|
label: 'Back',
|
|
|
|
}}
|
|
|
|
submitBtn={{
|
|
|
|
label: 'Resolve',
|
|
|
|
className: clsx('border-none', submitButtonClass),
|
2022-10-03 20:33:00 +00:00
|
|
|
isSubmitting,
|
2022-02-17 23:00:19 +00:00
|
|
|
}}
|
|
|
|
onSubmit={onResolve}
|
|
|
|
>
|
|
|
|
<p>Are you sure you want to resolve this market?</p>
|
|
|
|
</ConfirmationButton>
|
|
|
|
)
|
|
|
|
}
|