Skip to content

Commit 75a195b

Browse files
committed
refactor: update usage of useAdminforth to access API methods in CreateView and EditView
1 parent 455cd80 commit 75a195b

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

adminforth/spa/src/views/CreateView.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const router = useRouter();
103103
const record = ref({});
104104
105105
const coreStore = useCoreStore();
106-
const { runSaveInterceptors } = useAdminforth();
106+
const { api } = useAdminforth();
107107
108108
const { t } = useI18n();
109109
@@ -119,8 +119,7 @@ async function onUpdateRecord(newRecord: any) {
119119
}
120120
121121
onBeforeMount(() => {
122-
const { clearSaveInterceptors } = useAdminforth();
123-
clearSaveInterceptors(route.params.resourceId as string);
122+
api.clearSaveInterceptors(route.params.resourceId as string);
124123
});
125124
126125
onMounted(async () => {
@@ -175,7 +174,7 @@ async function saveRecord() {
175174
const requiredColumns = coreStore.resource?.columns.filter(c => c.required?.create === true) || [];
176175
const requiredColumnsToSkip = requiredColumns.filter(c => checkShowIf(c, record.value, coreStore.resource?.columns || []) === false);
177176
saving.value = true;
178-
const interceptorsResult = await runSaveInterceptors({
177+
const interceptorsResult = await api.runSaveInterceptors({
179178
action: 'create',
180179
values: record.value,
181180
resource: coreStore.resource,
@@ -186,7 +185,7 @@ async function saveRecord() {
186185
if (interceptorsResult.error) showErrorTost(interceptorsResult.error);
187186
return;
188187
}
189-
const interceptorConfirmationResult = interceptorsResult.extra?.confirmationResult;
188+
const interceptorConfirmationResult = (interceptorsResult.extra as Record<string, any>)?.confirmationResult;
190189
const response = await callAdminForthApi({
191190
method: 'POST',
192191
path: `/create_record`,

adminforth/spa/src/views/EditView.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import type { AdminForthResourceColumn } from '@/types/Back';
8787
8888
const { t } = useI18n();
8989
const coreStore = useCoreStore();
90-
const { runSaveInterceptors } = useAdminforth();
90+
const { api } = useAdminforth();
9191
9292
const isValid = ref(false);
9393
const validating = ref(false);
@@ -129,8 +129,7 @@ const editableRecord = computed(() => {
129129
})
130130
131131
onBeforeMount(() => {
132-
const { clearSaveInterceptors } = useAdminforth();
133-
clearSaveInterceptors(route.params.resourceId as string);
132+
api.clearSaveInterceptors(route.params.resourceId as string);
134133
});
135134
136135
onMounted(async () => {
@@ -165,7 +164,7 @@ async function saveRecord() {
165164
}
166165
167166
saving.value = true;
168-
const interceptorsResult = await runSaveInterceptors({
167+
const interceptorsResult = await api.runSaveInterceptors({
169168
action: 'edit',
170169
values: record.value,
171170
resource: coreStore.resource,

0 commit comments

Comments
 (0)