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-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
|
|
|
|
}
|
|
|
|
cancelBtn?: {
|
|
|
|
label?: string
|
|
|
|
className?: string
|
|
|
|
}
|
|
|
|
submitBtn?: {
|
|
|
|
label?: string
|
|
|
|
className?: string
|
|
|
|
}
|
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>
|
2021-12-14 00:47:43 +00:00
|
|
|
}) {
|
2022-06-22 16:35:50 +00:00
|
|
|
const {
|
|
|
|
openModalBtn,
|
|
|
|
cancelBtn,
|
|
|
|
submitBtn,
|
|
|
|
onSubmit,
|
|
|
|
children,
|
|
|
|
onOpenChanged,
|
|
|
|
onSubmitWithSuccess,
|
|
|
|
} = 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
|
|
|
|
className={clsx('btn normal-case', cancelBtn?.className)}
|
|
|
|
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>
|
|
|
|
<div
|
|
|
|
className={clsx('btn normal-case', submitBtn?.className)}
|
|
|
|
onClick={
|
|
|
|
onSubmitWithSuccess
|
|
|
|
? () =>
|
|
|
|
onSubmitWithSuccess().then((success) =>
|
|
|
|
updateOpen(!success)
|
|
|
|
)
|
|
|
|
: onSubmit
|
|
|
|
}
|
2021-12-14 00:47:43 +00:00
|
|
|
>
|
|
|
|
{submitBtn?.label ?? 'Submit'}
|
2022-06-22 16:35:50 +00:00
|
|
|
</div>
|
2022-03-31 09:09:08 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Modal>
|
2022-06-22 16:35:50 +00:00
|
|
|
<div
|
|
|
|
className={clsx('btn normal-case', openModalBtn.className)}
|
|
|
|
onClick={() => updateOpen(true)}
|
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-06-22 16:35:50 +00:00
|
|
|
</div>
|
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-03-31 08:38:57 +00:00
|
|
|
const { onResolve, isSubmitting, openModalButtonClass, submitButtonClass } =
|
2022-02-17 23:00:19 +00:00
|
|
|
props
|
|
|
|
return (
|
|
|
|
<ConfirmationButton
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalBtn={{
|
2022-02-17 23:00:19 +00:00
|
|
|
className: clsx(
|
|
|
|
'border-none self-start',
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalButtonClass,
|
2022-02-17 23:00:19 +00:00
|
|
|
isSubmitting && 'btn-disabled loading'
|
|
|
|
),
|
|
|
|
label: 'Resolve',
|
|
|
|
}}
|
|
|
|
cancelBtn={{
|
|
|
|
label: 'Back',
|
|
|
|
}}
|
|
|
|
submitBtn={{
|
|
|
|
label: 'Resolve',
|
|
|
|
className: clsx('border-none', submitButtonClass),
|
|
|
|
}}
|
|
|
|
onSubmit={onResolve}
|
|
|
|
>
|
|
|
|
<p>Are you sure you want to resolve this market?</p>
|
|
|
|
</ConfirmationButton>
|
|
|
|
)
|
|
|
|
}
|