diff --git a/packages/nc-gui/components/dlg/AirtableImport.vue b/packages/nc-gui/components/dlg/AirtableImport.vue index 5631753..9ce65b5 100644 --- a/packages/nc-gui/components/dlg/AirtableImport.vue +++ b/packages/nc-gui/components/dlg/AirtableImport.vue @@ -58,9 +58,11 @@ const syncSource = ref({ syncDirection: 'Airtable to NocoDB', syncRetryCount: 1, apiKey: '', + personalAccessToken: '', appId: '', shareId: '', syncSourceUrlOrId: '', + apiVersion: 'v1', options: { syncViews: true, syncData: true, @@ -104,10 +106,20 @@ const onStatus = async (status: JobStatus, data?: any) => { } } -const validators = computed(() => ({ - 'details.apiKey': [fieldRequiredValidator()], - 'details.syncSourceUrlOrId': [fieldRequiredValidator()], -})) +const validators = computed(() => { + const rules: any = { + 'details.syncSourceUrlOrId': [fieldRequiredValidator()], + } + + // Validate credentials based on API version + if (syncSource.value.details.apiVersion === 'v2') { + rules['details.personalAccessToken'] = [fieldRequiredValidator()] + } else { + rules['details.apiKey'] = [fieldRequiredValidator()] + } + + return rules +}) const dialogShow = computed({ get: () => modelValue, @@ -118,12 +130,14 @@ const useForm = Form.useForm const { validateInfos } = useForm(syncSource, validators) -const disableImportButton = computed( - () => - !syncSource.value.details.apiKey || - !syncSource.value.details.syncSourceUrlOrId || - sourceSelectorRef.value?.selectedSource?.ncItemDisabled, -) +const disableImportButton = computed(() => { + const hasCredentials = + syncSource.value.details.apiVersion === 'v2' + ? !!syncSource.value.details.personalAccessToken + : !!syncSource.value.details.apiKey + + return !hasCredentials || !syncSource.value.details.syncSourceUrlOrId || sourceSelectorRef.value?.selectedSource?.ncItemDisabled +}) const isLoading = ref(false) @@ -230,9 +244,11 @@ async function loadSyncSrc() { syncDirection: 'Airtable to NocoDB', syncRetryCount: 1, apiKey: '', + personalAccessToken: '', appId: '', shareId: '', syncSourceUrlOrId: '', + apiVersion: 'v1', options: { syncViews: true, syncData: true, @@ -303,6 +319,18 @@ const isInProgress = computed(() => { const detailsIsShown = ref(false) const collapseKey = ref('') + +// Auto-detect API version based on credentials +watch( + () => [syncSource.value.details.personalAccessToken, syncSource.value.details.apiKey], + ([pat, apiKey]) => { + if (pat && !apiKey) { + syncSource.value.details.apiVersion = 'v2' + } else if (apiKey && !pat) { + syncSource.value.details.apiVersion = 'v1' + } + }, +)