diff --git a/src/features/settings/hooks/useAppMenu.ts b/src/features/settings/hooks/useAppMenu.ts index ba282ed..0003d96 100644 --- a/src/features/settings/hooks/useAppMenu.ts +++ b/src/features/settings/hooks/useAppMenu.ts @@ -3,7 +3,7 @@ import { useAuthContext } from '@auth/hooks/useAuth' import { disconnectApp } from '@settings/actions/disconnectApp' import { useSettingsContext } from '@settings/hooks/useSettings' -import { useState } from 'react' +import { useCallback } from 'react' import { useActionsMenu } from '@/lib/copilot/hooks/app-bridge' import { Icons } from '@/lib/copilot/hooks/app-bridge/types' @@ -11,16 +11,16 @@ export const useAppBridge = ({ token }: { token: string }) => { const { connectionStatus } = useAuthContext() const { isSyncEnabled, updateSettings, initialSettings } = useSettingsContext() - const disconnectAppAction = async () => { + const disconnectAppAction = useCallback(async () => { await disconnectApp(token) updateSettings({ isSyncEnabled: false, initialSettings: { ...initialSettings, isSyncEnabled: false }, }) - } + }, [token, updateSettings, initialSettings]) // biome-ignore lint/suspicious/useAwait: there is no async action being done here but the type signature requires it - const _downloadCsvAction = async () => { + const downloadCsvAction = useCallback(async () => { const url = `/api/sync-logs?token=${token}` const link = document.createElement('a') link.href = url @@ -28,14 +28,7 @@ export const useAppBridge = ({ token }: { token: string }) => { document.body.appendChild(link) link.click() link.remove() - } - - // Quickfix for now (it will probably stay like this for the end of time) - const [downloadCsvAction, setDownloadCsvAction] = useState(() => _downloadCsvAction) - - setTimeout(() => { - setDownloadCsvAction(() => _downloadCsvAction) - }, 1000) + }, [token]) let actions: { label: string; icon?: Icons; onClick: () => Promise }[] = [] if (connectionStatus) {