Files
supabase/packages/ui-patterns/Dialogs/ConfirmDialog.tsx
Terry SuttonandJoshen Lim 7d5c62c518 Chore/update without where warning (#28458)
* Add warning when running update without where

* Account for quotes

* Split warnings to allow them to show independently

* Update

* Combine two modals into one

* Padding bump

* Fix padding

* Return if a query has issues

* Allow queries to run

* Small UI tweaks

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-09-20 17:33:47 +08:00

101 lines
2.4 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { Button, Form, Modal } from 'ui'
// [Joshen] As of 280222, let's just use ConfirmationModal as the one and only confirmation modal (Deprecate this)
interface ConfirmModalProps {
visible: boolean
danger?: boolean
title: string
description: string
size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'
buttonLabel: string
buttonLoadingLabel?: string
onSelectCancel: () => void
onSelectConfirm: () => void
}
// @deprecated use ConfirmationModal instead
const ConfirmModal = ({
visible = false,
danger = false,
title = '',
description = '',
size = 'small',
buttonLabel = '',
buttonLoadingLabel = '',
onSelectCancel = () => {},
onSelectConfirm = () => {},
}: ConfirmModalProps) => {
useEffect(() => {
if (visible) {
setLoading(false)
}
}, [visible])
const [loading, setLoading] = useState(false)
const onConfirm = () => {
setLoading(true)
onSelectConfirm()
}
return (
<Modal
header={title}
visible={visible}
title={title}
description={description}
size={size}
hideFooter
onCancel={onSelectCancel}
>
<Form
initialValues={{}}
validateOnBlur
onSubmit={() => onConfirm()}
validate={() => {
return []
}}
>
{() => {
return (
<>
<Modal.Content>
<div className="flex items-center gap-2">
<Button
block
htmlType="button"
type="default"
onClick={onSelectCancel}
disabled={loading}
>
Cancel
</Button>
<Button
htmlType="submit"
block
type={danger ? 'danger' : 'primary'}
disabled={loading}
loading={loading}
>
{buttonLoadingLabel && loading
? buttonLoadingLabel
: buttonLabel
? buttonLabel
: 'Confirm'}
</Button>
</div>
</Modal.Content>
</>
)
}}
</Form>
</Modal>
)
}
export default ConfirmModal