Skip to content

Commit 77ed295

Browse files
committed
feat: enhance modal confirmation by adding customizable title and updating related components
1 parent 402b27a commit 77ed295

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

adminforth/spa/src/adminforth.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ class FrontendAPI implements FrontendAPIInterface {
118118

119119
confirm(params: Parameters<FrontendAPIInterface['confirm']>[0]): ReturnType<FrontendAPIInterface['confirm']> {
120120
return new Promise((resolve, reject) => {
121-
this.modalStore.setModalContent({
122-
content: params.message,
121+
this.modalStore.setModalContent({
122+
title: params.title,
123+
content: params.message,
123124
contentHTML: params.messageHtml,
124125
acceptText: params.yes || 'Yes',
125-
cancelText: params.no || 'Cancel'
126+
cancelText: params.no || 'Cancel'
126127
})
127128
this.modalStore.onAcceptFunction = resolve
128129
this.modalStore.onCancelFunction = reject

adminforth/spa/src/components/AcceptModal.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
</div>
2323
</div>
2424

25-
<h3 class="mb-4 text-2xl font-bold text-gray-900 dark:text-white">
26-
There are unsaved changes.
25+
<h3 v-if="modalStore?.modalContent?.title" class="mb-4 text-2xl font-bold text-gray-900 dark:text-white">
26+
{{ modalStore.modalContent.title }}
2727
</h3>
2828

2929
<div class="mb-2 text-[15px] text-gray-600 dark:text-gray-300">
@@ -35,7 +35,7 @@
3535

3636
<div class="flex justify-center gap-4 w-full">
3737
<button @click="()=>{modalStore.onAcceptFunction(false);modalStore.togleModal()}" type="button" class="flex-1 py-2.5 px-4 text-sm font-medium text-gray-700 bg-white rounded-lg border border-gray-200 hover:bg-gray-50 focus:ring-4 focus:ring-gray-100 transition-all dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700">
38-
Stay and continue
38+
{{ modalStore?.modalContent?.cancelText }}
3939
</button>
4040

4141
<button
@@ -47,7 +47,7 @@
4747
border border-red-700 dark:border-red-600
4848
rounded-lg shadow-sm focus:z-10 focus:ring-4
4949
focus:ring-red-100 dark:focus:ring-red-900 gap-1">
50-
Leave without saving
50+
{{ modalStore?.modalContent?.acceptText }}
5151
</button>
5252
</div>
5353

adminforth/spa/src/stores/modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const useModalStore = defineStore('modal', () => {
3232
}
3333
function setModalContent(content: ModalContentType) {
3434
modalContent.value = {
35-
title: content.title || 'title',
35+
title: content.title || '',
3636
content: content.content || '',
3737
contentHTML: content.contentHTML || '',
3838
acceptText: content.acceptText || 'acceptText',

adminforth/spa/src/utils/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,10 @@ export async function onBeforeRouteLeaveCreateEditViewGuard(initialValues: any,
781781
generateMessageHtmlForRecordChange(changedFields, t);
782782

783783
const answer = await confirm({
784+
title: t('There are unsaved changes'),
784785
messageHtml,
785-
yes: t('Yes'),
786-
no: t('No'),
786+
yes: t('Leave without saving'),
787+
no: t('Stay and continue'),
787788
});
788789

789790
return answer;

adminforth/types/FrontendAPI.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ export interface FrontendAPIInterface {
160160
}
161161

162162
export type ConfirmParams = {
163+
/**
164+
* The title to display in the dialog
165+
*/
166+
title?: string;
163167
/**
164168
* The message to display in the dialog
165169
*/

0 commit comments

Comments
 (0)