Files
supabase/studio/components/ui/Dialogs/ConfirmDialog.js
T
Sara Tavaresandgithub-actions[bot] 80d0624262 fix(typos): add github action to prevent typos + fix typos (#9598)
* feat(ci): fix typos

* [create-pull-request] automated change

* Update index.tsx

* Update README.fr.md

* Create .misspell-fixer.ignore

* Update constant.dart

* [create-pull-request] automated change

* Update database.tsx

* [create-pull-request] automated change

* [create-pull-request] automated change

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-10-27 23:32:02 -03:00

85 lines
2.1 KiB
JavaScript

import { Modal, Button, Form } from 'ui'
import { useState, useEffect } from 'react'
// [Joshen] As of 280222, let's just use THIS component as the one and only confirmation modal
// deprecate all others, since it uses the Form component from the UI library as well
const ConfirmModal = ({
visible = false,
danger = false,
title = '',
description = '',
size = 'small',
buttonLabel = '',
buttonLoadingLabel = '',
onSelectCancel = () => {},
onSelectConfirm = () => {},
}) => {
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={() => {
let errors = []
return errors
}}
>
{() => {
return (
<div className="space-y-4 py-4">
<Modal.Content>
<p className="text-sm text-scale-1100">{description}</p>
</Modal.Content>
<Modal.Separator />
<Modal.Content>
<div className="flex items-center gap-2">
<Button htmlType="button" type="default" onClick={onSelectCancel} block>
Cancel
</Button>
<Button
htmlType="submit"
block
type={danger ? 'danger' : 'primary'}
loading={loading}
>
{buttonLoadingLabel && loading
? buttonLoadingLabel
: buttonLabel
? buttonLabel
: 'Confirm'}
</Button>
</div>
</Modal.Content>
</div>
)
}}
</Form>
</Modal>
)
}
export default ConfirmModal