1
0
Fork 0
mirror of synced 2024-10-03 02:27:06 +13:00

Use action name as confirmation modal title

This commit is contained in:
Andrew Kingston 2021-06-21 10:46:55 +01:00
parent 0d99c69fe6
commit 785f724dda
3 changed files with 16 additions and 10 deletions

View file

@ -6,7 +6,7 @@
{#if $confirmationStore.showConfirmation} {#if $confirmationStore.showConfirmation}
<Modal fixed on:cancel={confirmationStore.actions.cancel}> <Modal fixed on:cancel={confirmationStore.actions.cancel}>
<ModalContent <ModalContent
title="Confirm Action" title={$confirmationStore.title}
onConfirm={confirmationStore.actions.confirm} onConfirm={confirmationStore.actions.confirm}
> >
{$confirmationStore.text} {$confirmationStore.text}

View file

@ -2,6 +2,7 @@ import { writable, get } from "svelte/store"
const initialState = { const initialState = {
showConfirmation: false, showConfirmation: false,
title: null,
text: null, text: null,
callback: null, callback: null,
} }
@ -9,9 +10,10 @@ const initialState = {
const createConfirmationStore = () => { const createConfirmationStore = () => {
const store = writable(initialState) const store = writable(initialState)
const showConfirmation = (text, callback) => { const showConfirmation = (title, text, callback) => {
store.set({ store.set({
showConfirmation: true, showConfirmation: true,
title,
text, text,
callback, callback,
}) })

View file

@ -107,15 +107,19 @@ export const enrichButtonActions = (actions, context) => {
if (action.parameters?.confirm) { if (action.parameters?.confirm) {
const defaultText = confirmTextMap[action["##eventHandlerType"]] const defaultText = confirmTextMap[action["##eventHandlerType"]]
const confirmText = action.parameters?.confirmText || defaultText const confirmText = action.parameters?.confirmText || defaultText
confirmationStore.actions.showConfirmation(confirmText, async () => { confirmationStore.actions.showConfirmation(
// When confirmed, execute this action immediately, action["##eventHandlerType"],
// then execute the rest of the actions in the chain confirmText,
const result = await callback() async () => {
if (result !== false) { // When confirmed, execute this action immediately,
const next = enrichButtonActions(actions.slice(i + 1), context) // then execute the rest of the actions in the chain
await next() const result = await callback()
if (result !== false) {
const next = enrichButtonActions(actions.slice(i + 1), context)
await next()
}
} }
}) )
// Stop enriching actions when encountering a confirmable action, // Stop enriching actions when encountering a confirmable action,
// as the callback continues the action chain // as the callback continues the action chain