Confirm on deletion

This commit is contained in:
Adria Navarro 2025-03-19 09:42:18 +01:00
parent 83d6d5aeab
commit 211b0144f8
2 changed files with 17 additions and 7 deletions

View File

@ -11,6 +11,7 @@ export async function confirm(props: {
onConfirm?: () => void onConfirm?: () => void
onCancel?: () => void onCancel?: () => void
onClose?: () => void onClose?: () => void
warning?: boolean
}) { }) {
return await new Promise(resolve => { return await new Promise(resolve => {
const dialog = new ConfirmDialog({ const dialog = new ConfirmDialog({
@ -21,7 +22,7 @@ export async function confirm(props: {
okText: props.okText, okText: props.okText,
cancelText: props.cancelText, cancelText: props.cancelText,
size: props.size, size: props.size,
warning: false, warning: props.warning,
onOk: () => { onOk: () => {
dialog.$destroy() dialog.$destroy()
resolve(props.onConfirm?.() || true) resolve(props.onConfirm?.() || true)

View File

@ -9,6 +9,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import type { OAuth2Config } from "@budibase/types" import type { OAuth2Config } from "@budibase/types"
import OAuth2ConfigModalContent from "./OAuth2ConfigModalContent.svelte" import OAuth2ConfigModalContent from "./OAuth2ConfigModalContent.svelte"
import { confirm } from "@/helpers"
export let row: OAuth2Config export let row: OAuth2Config
@ -18,12 +19,20 @@
modal.show() modal.show()
} }
async function onDelete() { async function onDelete() {
try { await confirm({
await oauth2.delete(row.id) title: "Confirm Deletion",
notifications.success(`Config '${row.name}' deleted successfully`) body: `Deleting "${row.name}" cannot be undone. Are you sure?`,
} catch (e: any) { okText: "Delete Configuration",
notifications.error("Error deleting config") warning: true,
} onConfirm: async () => {
try {
await oauth2.delete(row.id)
notifications.success(`Config '${row.name}' deleted successfully`)
} catch (e: any) {
notifications.error("Error deleting config")
}
},
})
} }
</script> </script>