import GoogleSheetsIntegrationSettings from '@/integrations/google-sheets/views/form-builder/GoogleSheetsIntegrationSettings.vue' import { IVYFORMS_SETTINGS } from '@/constants/pages' export const GOOGLE_SHEETS_MANAGE_ROUTE = 'google-sheets-manage' export const GOOGLE_SHEETS_EDIT_ROUTE = 'google-sheets-edit' interface RouterInstance { addRoute: (parentName: string, route: Record) => void push: (path: string) => void hasRoute: (name: string) => boolean } export function registerGoogleSheetsRoutes(): void { const api = window.IvyForms?.api if (api?.hooks?.addFilter) { api.hooks.addFilter('ivyforms/builder/filter/routes', (routes: unknown) => { const list = Array.isArray(routes) ? routes : [] return [...list, GOOGLE_SHEETS_MANAGE_ROUTE, GOOGLE_SHEETS_EDIT_ROUTE] }) } const register = () => { const router = window.IvyForms?._router as RouterInstance | undefined if (!router?.hasRoute(IVYFORMS_SETTINGS)) { return } // Use integration-specific paths under settings (not shared form-integrations/manage) // so webhook manage routes are not overridden. router.addRoute(IVYFORMS_SETTINGS, { path: 'integrations/google_sheets/manage', name: GOOGLE_SHEETS_MANAGE_ROUTE, component: GoogleSheetsIntegrationSettings, meta: { breadcrumb: 'Add Google Sheet', requiresForm: true, }, }) router.addRoute(IVYFORMS_SETTINGS, { path: 'integrations/google_sheets/manage/:integrationId(\\d+)', name: GOOGLE_SHEETS_EDIT_ROUTE, component: GoogleSheetsIntegrationSettings, meta: { breadcrumb: 'Edit Google Sheet', requiresForm: true, }, }) const currentPath = window.location.hash.replace('#', '') if (currentPath.includes('/integrations/google_sheets/manage')) { router.push(currentPath) } } if (window.IvyForms?._router) { register() } else { window.addEventListener('ivyforms:ready', register, { once: true }) } } registerGoogleSheetsRoutes()