File tree Expand file tree Collapse file tree 5 files changed +30
-8
lines changed
Expand file tree Collapse file tree 5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,14 @@ export function useAdminforth() {
228228 const api = frontendAPI as FrontendAPI ;
229229 return {
230230 registerSaveInterceptor : ( handler : ( ctx : { action : 'create' | 'edit' ; values : any ; resource : any ; } ) => Promise < { ok : boolean ; error ?: string | null ; extra ?: object ; } > ) => api . registerSaveInterceptor ( handler ) ,
231- api,
231+ alert : ( params : AlertParams ) => api . alert ( params ) ,
232+ confirm : ( params : ConfirmParams ) => api . confirm ( params ) ,
233+ list : api . list ,
234+ show : api . show ,
235+ menu : api . menu ,
236+ closeUserMenuDropdown : ( ) => api . closeUserMenuDropdown ( ) ,
237+ runSaveInterceptors : ( params : { action : 'create' | 'edit' ; values : any ; resource : any ; resourceId : string ; } ) => api . runSaveInterceptors ( params ) ,
238+ clearSaveInterceptors : ( resourceId ?: string ) => api . clearSaveInterceptors ( resourceId ) ,
232239 } ;
233240}
234241
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ const router = useRouter();
103103const record = ref ({});
104104
105105const coreStore = useCoreStore ();
106- const { api } = useAdminforth ();
106+ const { clearSaveInterceptors, runSaveInterceptors } = useAdminforth ();
107107
108108const { t } = useI18n ();
109109
@@ -119,7 +119,7 @@ async function onUpdateRecord(newRecord: any) {
119119}
120120
121121onBeforeMount (() => {
122- api . clearSaveInterceptors (route .params .resourceId as string );
122+ clearSaveInterceptors (route .params .resourceId as string );
123123});
124124
125125onMounted (async () => {
@@ -174,7 +174,7 @@ async function saveRecord() {
174174 const requiredColumns = coreStore .resource ?.columns .filter (c => c .required ?.create === true ) || [];
175175 const requiredColumnsToSkip = requiredColumns .filter (c => checkShowIf (c , record .value , coreStore .resource ?.columns || []) === false );
176176 saving .value = true ;
177- const interceptorsResult = await api . runSaveInterceptors ({
177+ const interceptorsResult = await runSaveInterceptors ({
178178 action: ' create' ,
179179 values: record .value ,
180180 resource: coreStore .resource ,
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ import type { AdminForthResourceColumn } from '@/types/Back';
8787
8888const { t } = useI18n ();
8989const coreStore = useCoreStore ();
90- const { api } = useAdminforth ();
90+ const { clearSaveInterceptors, runSaveInterceptors } = useAdminforth ();
9191
9292const isValid = ref (false );
9393const validating = ref (false );
@@ -129,7 +129,7 @@ const editableRecord = computed(() => {
129129})
130130
131131onBeforeMount (() => {
132- api . clearSaveInterceptors (route .params .resourceId as string );
132+ clearSaveInterceptors (route .params .resourceId as string );
133133});
134134
135135onMounted (async () => {
@@ -164,7 +164,7 @@ async function saveRecord() {
164164 }
165165
166166 saving .value = true ;
167- const interceptorsResult = await api . runSaveInterceptors ({
167+ const interceptorsResult = await runSaveInterceptors ({
168168 action: ' edit' ,
169169 values: record .value ,
170170 resource: coreStore .resource ,
Original file line number Diff line number Diff line change @@ -136,6 +136,18 @@ export interface FrontendAPIInterface {
136136 * Close the user menu dropdown
137137 */
138138 closeUserMenuDropdown ( ) : void ;
139+
140+ /**
141+ * Run save interceptors for a specific resource or all resources if no resourceId is provided
142+ */
143+ runSaveInterceptors ( params : { action : 'create' | 'edit' ; values : any ; resource : any ; resourceId : string ; } ) : Promise < { ok : boolean ; error ?: string | null ; extra ?: object ; } > ;
144+
145+ /**
146+ * Clear save interceptors for a specific resource or all resources if no resourceId is provided
147+ *
148+ * @param resourceId - The resource ID to clear interceptors for
149+ */
150+ clearSaveInterceptors ( resourceId ?: string ) : void ;
139151}
140152
141153export type ConfirmParams = {
Original file line number Diff line number Diff line change @@ -317,6 +317,9 @@ import { IconSearchOutline } from '@iconify-prerendered/vue-flowbite'
317317import { DatePicker } from ' @/afcl' ;
318318import CustomRangePicker from " @/components/CustomRangePicker.vue" ;
319319import Toast from ' @/components/Toast.vue' ;
320+ import { useAdminforth } from ' @/adminforth' ;
321+
322+ const { alert } = useAdminforth ();
320323
321324const files: Ref <File []> = ref ([])
322325
@@ -338,7 +341,7 @@ watch(valueStart, (newVal) => {
338341});
339342
340343function doSmth(){
341-
344+ alert ({message: ' Hello world ' , variant: ' success ' })
342345}
343346
344347 </script >
You can’t perform that action at this time.
0 commit comments