Use action name as confirmation modal title
This commit is contained in:
parent
4352611fc7
commit
b7991ea894
|
@ -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}
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
|
@ -107,7 +107,10 @@ 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(
|
||||||
|
action["##eventHandlerType"],
|
||||||
|
confirmText,
|
||||||
|
async () => {
|
||||||
// When confirmed, execute this action immediately,
|
// When confirmed, execute this action immediately,
|
||||||
// then execute the rest of the actions in the chain
|
// then execute the rest of the actions in the chain
|
||||||
const result = await callback()
|
const result = await callback()
|
||||||
|
@ -115,7 +118,8 @@ export const enrichButtonActions = (actions, context) => {
|
||||||
const next = enrichButtonActions(actions.slice(i + 1), context)
|
const next = enrichButtonActions(actions.slice(i + 1), context)
|
||||||
await next()
|
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
|
||||||
|
|
Loading…
Reference in New Issue