From fd2d5f39c021124b70aab2ec546d28cd3354a5a4 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sat, 1 Aug 2026 00:20:59 +0700 Subject: [PATCH] feat(settings): add CFDM API URL handling and improve integration form Introduced a new test to verify the persistence of the CFDM API URL via the settings endpoint. Updated the integration form to reflect saved credentials more clearly, enhancing user feedback for the API URL and integration token. Improved sync button behavior to prevent actions without saved credentials. Updated settings schema to include CFDM API URL validation. --- apps/api/src/routes/settings.test.ts | 13 +++++++ .../integrations/cfdm-integration-card.tsx | 38 ++++++++++++------- .../routes/_auth/settings/integrations.tsx | 4 +- packages/shared/src/contracts/settings.ts | 1 + 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/apps/api/src/routes/settings.test.ts b/apps/api/src/routes/settings.test.ts index 36e4865..932304b 100644 --- a/apps/api/src/routes/settings.test.ts +++ b/apps/api/src/routes/settings.test.ts @@ -101,6 +101,19 @@ describe('settings cfdm sync', () => { closeDb() }) + it('persists cfdmApiUrl via PUT settings', async () => { + const res = await app.inject({ + method: 'PUT', + url: '/api/settings/settings-main', + payload: { cfdmApiUrl: 'http://192.168.100.67:6363' }, + }) + expect(res.statusCode).toBe(200) + expect(res.json()).toMatchObject({ cfdmApiUrl: 'http://192.168.100.67:6363' }) + + const dto = settingsRepository.get('settings-main') + expect(dto?.cfdmApiUrl).toBe('http://192.168.100.67:6363') + }) + it('requests full sync from CFDM', async () => { const fetchMock = vi.fn(async () => Response.json({ ok: true, count: 3 })) vi.stubGlobal('fetch', fetchMock) diff --git a/apps/web/src/components/integrations/cfdm-integration-card.tsx b/apps/web/src/components/integrations/cfdm-integration-card.tsx index 07bed8b..93b9067 100644 --- a/apps/web/src/components/integrations/cfdm-integration-card.tsx +++ b/apps/web/src/components/integrations/cfdm-integration-card.tsx @@ -79,9 +79,11 @@ export function CfdmIntegrationForm({ }) } - // Только сохранённые credentials — без ввода токена и без «сначала сохранить форму». + // Sync по сохранённому токену (URL — cfdmApiUrl или App Switcher на API). + const hasSavedToken = Boolean(settings?.integrationTokenSet) + const hasSavedUrl = Boolean(settings?.cfdmApiUrl?.trim()) const canSync = - Boolean(settings?.cfdmApiUrl?.trim()) && Boolean(settings?.integrationTokenSet) + hasSavedToken || Boolean(settings?.integrationLastSyncAt?.trim()) return (
syncMut.mutate()} + onClick={() => { + if (!canSync) { + toast.error('Сначала сохраните integration token') + return + } + syncMut.mutate() + }} >