Skip to content

Commit 2303968

Browse files
committed
chore: update modal store functions to use resolve/reject directly, enhance type definitions in modal and views for better type safety
1 parent 95c600b commit 2303968

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

adminforth/spa/src/adminforth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class FrontendAPI implements FrontendAPIInterface {
8181
acceptText: params.yes || 'Yes',
8282
cancelText: params.no || 'Cancel'
8383
})
84-
this.modalStore.onAcceptFunction = () => resolve(true)
85-
this.modalStore.onCancelFunction = () => resolve(false)
84+
this.modalStore.onAcceptFunction = resolve
85+
this.modalStore.onCancelFunction = reject
8686
this.modalStore.togleModal()
8787
})
8888
}

adminforth/spa/src/stores/modal.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { ref } from 'vue'
22
import { defineStore } from 'pinia'
33

44
type ModalContentType = {
5-
title: string;
6-
content: string;
7-
acceptText: string;
8-
cancelText: string;
5+
title?: string;
6+
content?: string;
7+
acceptText?: string;
8+
cancelText?: string;
99
}
1010

1111

@@ -29,7 +29,12 @@ export const useModalStore = defineStore('modal', () => {
2929
onCancelFunction.value = func;
3030
}
3131
function setModalContent(content: ModalContentType) {
32-
modalContent.value = content;
32+
modalContent.value = {
33+
title: content.title || 'title',
34+
content: content.content || 'content',
35+
acceptText: content.acceptText || 'acceptText',
36+
cancelText: content.cancelText || 'cancelText',
37+
};
3338
}
3439
function resetmodalState() {
3540
isOpened.value = false;

adminforth/spa/src/views/ListView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<button
3939
v-if="!action.showInThreeDotsDropdown"
4040
:key="action.id"
41-
@click="startBulkAction(action.id)"
41+
@click="startBulkAction(action.id!)"
4242
class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText focus:outline-none bg-lightListViewButtonBackground rounded-default border border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
4343
:class="action.buttonCustomCssClass || ''"
4444
>
@@ -326,7 +326,7 @@ async function refreshExistingList(pk?: any) {
326326
}
327327
328328
329-
async function startBulkAction(actionId: any) {
329+
async function startBulkAction(actionId: string) {
330330
const action = coreStore.resource?.options?.bulkActions?.find(a => a.id === actionId);
331331
if (action?.confirm) {
332332
const confirmed = await adminforth.confirm({

adminforth/spa/src/views/ShowView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ import ShowTable from '@/components/ShowTable.vue';
139139
import adminforth from "@/adminforth";
140140
import { useI18n } from 'vue-i18n';
141141
import { getIcon } from '@/utils';
142-
import { type AdminForthComponentDeclarationFull, type FieldGroup, type AdminForthResourceColumnCommon } from '@/types/Common.js';
142+
import { type AdminForthComponentDeclarationFull, type AdminForthResourceColumnCommon } from '@/types/Common.js';
143143
144144
const route = useRoute();
145145
const router = useRouter();
@@ -150,13 +150,13 @@ const coreStore = useCoreStore();
150150
const actionLoadingStates = ref<Record<string, boolean>>({});
151151
152152
const customActions = computed(() => {
153-
return coreStore.resource?.options?.actions?.filter(a => a.showIn?.showThreeDotsMenu) || [];
153+
return coreStore.resource?.options?.actions?.filter((a: any) => a.showIn?.showThreeDotsMenu) || [];
154154
});
155155
156156
onMounted(async () => {
157157
loading.value = true;
158158
await coreStore.fetchResourceFull({
159-
resourceId: route.params.resourceId as string, //route.params.resourceId has type string | string[], but chance, that resourceId can be array is very low
159+
resourceId: route.params.resourceId as string,
160160
});
161161
initThreeDotsDropdown();
162162
await coreStore.fetchRecord({
@@ -234,7 +234,7 @@ async function deleteRecord() {
234234
235235
}
236236
237-
async function startCustomAction(actionId: any) {
237+
async function startCustomAction(actionId: string) {
238238
actionLoadingStates.value[actionId] = true;
239239
240240
const data = await callAdminForthApi({

0 commit comments

Comments
 (0)