diff --git a/src/components/layouts/CheckConnection.tsx b/src/components/layouts/CheckConnection.tsx index bb892bb..bad9456 100644 --- a/src/components/layouts/CheckConnection.tsx +++ b/src/components/layouts/CheckConnection.tsx @@ -1,15 +1,18 @@ 'use client' import { useAuthContext } from '@/features/auth/hooks/useAuth' -import { postMessageParentDashboard } from '@/lib/copilot/hooks/app-bridge/postParentMessage' +import { Overlay } from '@/features/sync/components/Overlay' export const CheckConnection = ({ children }: { children: React.ReactNode }) => { const { connectionStatus } = useAuthContext() if (!connectionStatus) { - postMessageParentDashboard({ type: 'header.actionsMenu', items: [] }) - postMessageParentDashboard({ type: 'header.primaryCta' }) - return - } //remove app bridge functionality when app is disconnected. + return ( +
+ + {children} +
+ ) + } return <>{children} } diff --git a/src/features/app-bridge/components/AppBridge.tsx b/src/features/app-bridge/components/AppBridge.tsx index 393ec3e..8c9172a 100644 --- a/src/features/app-bridge/components/AppBridge.tsx +++ b/src/features/app-bridge/components/AppBridge.tsx @@ -1,12 +1,14 @@ 'use client' import { useEffect, useState } from 'react' +import { useAuthContext } from '@/features/auth/hooks/useAuth' import { useSubHeader } from '@/features/sync/hooks/useSubHeader' import { useActionsMenu, usePrimaryCta } from '@/lib/copilot/hooks/app-bridge' import { type AppBridgeProps, Icons } from '@/lib/copilot/hooks/app-bridge/types' export const AppBridge = ({ portalUrl, handleDropboxDisconnection }: AppBridgeProps) => { const [_awake, setAwake] = useState(false) + const { connectionStatus } = useAuthContext() useEffect(() => { setTimeout(() => { @@ -16,25 +18,26 @@ export const AppBridge = ({ portalUrl, handleDropboxDisconnection }: AppBridgePr const { handleAddRule } = useSubHeader() - usePrimaryCta( - { - label: 'Add', - icon: Icons.PLUS, - onClick: handleAddRule, - }, - { portalUrl }, - ) - - useActionsMenu( - [ - { - label: 'Disconnect account', - icon: Icons.DISCONNECT, - onClick: handleDropboxDisconnection, - }, - ], - { portalUrl }, - ) + const primaryCta = connectionStatus + ? { + label: 'Add', + icon: Icons.PLUS, + onClick: handleAddRule, + } + : null + + const actionsMenu = connectionStatus + ? [ + { + label: 'Disconnect account', + icon: Icons.DISCONNECT, + onClick: handleDropboxDisconnection, + }, + ] + : [] + + usePrimaryCta(primaryCta, { portalUrl }) + useActionsMenu(actionsMenu, { portalUrl }) return null } diff --git a/src/features/auth/components/Callout.tsx b/src/features/auth/components/Callout.tsx index 0f560fc..78bcd3a 100644 --- a/src/features/auth/components/Callout.tsx +++ b/src/features/auth/components/Callout.tsx @@ -1,6 +1,6 @@ 'use client' -import { Button } from 'copilot-design-system' +import { Callout as CalloutComponent } from 'copilot-design-system' import { useAuthContext } from '@/features/auth/hooks/useAuth' export const authInitUrl = `/auth/initiate?token=` @@ -9,14 +9,21 @@ export const Callout = () => { const { user, connectionStatus } = useAuthContext() return ( -
+
{!connectionStatus ? ( -
-
+ { + window.open(`${authInitUrl}${user.token}`, '_blank', 'noopener,noreferrer') + }, + }} + /> ) : null}
) diff --git a/src/features/sync/components/Overlay.tsx b/src/features/sync/components/Overlay.tsx new file mode 100644 index 0000000..754adef --- /dev/null +++ b/src/features/sync/components/Overlay.tsx @@ -0,0 +1,5 @@ +'use client' + +export const Overlay = () => { + return
+} diff --git a/src/features/sync/hooks/useFolder.ts b/src/features/sync/hooks/useFolder.ts index 8402441..efe64ba 100644 --- a/src/features/sync/hooks/useFolder.ts +++ b/src/features/sync/hooks/useFolder.ts @@ -3,11 +3,15 @@ import { useAuthContext } from '@/features/auth/hooks/useAuth' import type { Folder } from '@/features/sync/types' export const useFolder = () => { - const { user } = useAuthContext() + const { user, connectionStatus } = useAuthContext() const [folderTree, setFolderTree] = useState([]) const [isFolderTreeLoading, setIsFolderTreeLoading] = useState(true) const getPathOptions = useCallback(async () => { + if (!connectionStatus) { + setIsFolderTreeLoading(false) + return + } setIsFolderTreeLoading(true) // api call to get all the folders const response = await fetch(`/api/dropbox/folder-tree?token=${user.token}`, { @@ -19,7 +23,7 @@ export const useFolder = () => { const resp = await response.json() setFolderTree(resp.folders) setIsFolderTreeLoading(false) - }, [user.token]) + }, [user.token, connectionStatus]) useEffect(() => { // biome-ignore lint/nursery/noFloatingPromises: floating promises are fine here