From 32c11ff7c4045459c4b1957b66386c6c74865edd Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 25 Jul 2022 18:00:07 +0800 Subject: [PATCH] feat(gui-v2): replace $axios implementation --- .../components/dlg/AirtableImport.vue | 100 ++++++++++-------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/AirtableImport.vue b/packages/nc-gui-v2/components/dlg/AirtableImport.vue index d47438371b..5b3e16b7ed 100644 --- a/packages/nc-gui-v2/components/dlg/AirtableImport.vue +++ b/packages/nc-gui-v2/components/dlg/AirtableImport.vue @@ -24,6 +24,7 @@ const progress = ref([]) const socket = ref() const syncSourceUrlOrId = ref('') const syncSource = ref({ + id: '', type: 'Airtable', details: { syncInterval: '15mins', @@ -67,57 +68,66 @@ async function saveAndSync() { } async function createOrUpdate() { - // TODO: check $axios implementation - // try { - // const { id, ...payload } = syncSource.value; - // if (id) { - // await $axios.patch(`/api/v1/db/meta/syncs/${id}`, payload); - // } else { - // syncSource.value = (await $axios.post(`/api/v1/db/meta/projects/${project.value.id}/syncs`, payload)).data; - // } - // } catch (e: any) { - // toast.error(await extractSdkResponseErrorMsg(e)) - // } + try { + const { id, ...payload } = syncSource.value + if (id !== '') { + await $fetch(`/api/v1/db/meta/syncs/${id}`, { + method: 'PATCH', + body: payload, + }) + } else { + const { data }: any = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, { + method: 'POST', + body: payload, + }) + syncSource.value = data + } + } catch (e: any) { + toast.error(await extractSdkResponseErrorMsg(e)) + } } async function loadSyncSrc() { - // const { - // data: { list: srcs }, - // } = await $axios.get(`/api/v1/db/meta/projects/${project.id}/syncs`) - // if (srcs && srcs[0]) { - // srcs[0].details = srcs[0].details || {} - // syncSource.value = this.migrateSync(srcs[0]) - // syncSourceUrlOrId.value = srcs[0].details.shareId - // } else { - // syncSource.value = { - // type: 'Airtable', - // details: { - // syncInterval: '15mins', - // syncDirection: 'Airtable to NocoDB', - // syncRetryCount: 1, - // apiKey: '', - // shareId: '', - // options: { - // syncViews: true, - // syncData: true, - // syncRollup: false, - // syncLookup: true, - // syncFormula: false, - // syncAttachment: true, - // }, - // }, - // } - // } + const { + data: { list: srcs }, + }: any = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, { + method: 'GET', + }) + if (srcs && srcs[0]) { + srcs[0].details = srcs[0].details || {} + syncSource.value = migrateSync(srcs[0]) + syncSourceUrlOrId.value = srcs[0].details.shareId + } else { + syncSource.value = { + id: '', + type: 'Airtable', + details: { + syncInterval: '15mins', + syncDirection: 'Airtable to NocoDB', + syncRetryCount: 1, + apiKey: '', + shareId: '', + options: { + syncViews: true, + syncData: true, + syncRollup: false, + syncLookup: true, + syncFormula: false, + syncAttachment: true, + }, + }, + } + } } -function sync() { +async function sync() { step.value = 2 - // TODO: check $axios implementation - // $axios.post(`/api/v1/db/meta/syncs/${syncSource.value.id}/trigger`, payload, { - // params: { - // id: this.socket.id, - // }, - // }); + const { data }: any = await $fetch(`/api/v1/db/meta/syncs/${syncSource.value.id}/trigger`, { + method: 'POST', + body: { + id: socket.value.id, + }, + }) } function migrateSync(src: any) {