Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.4 KB
Raw Blame
import { useVerifyReportBundle } from '@/features/Acceptance/hooks';
import { useAcceptanceOrigin } from '@/features/Acceptance/origin';
import { buildAcceptanceRoundPath } from '@/features/Acceptance/roundLink';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';

/**
 * Web URL of the acceptance round the portal's report belongs to — the report's
 * only page outside the app. `undefined` until the run is loaded, and for good
 * once it turns out to be `standalone` (no acceptance, so nothing to open).
 */
export const useVerifyReportUrl = () => {
  const appOrigin = useAcceptanceOrigin();
  const runId = useChatStore(chatPortalSelectors.verifyReportRunId);
  // Same replica entry as the portal's title and body, so this shares their request.
  const { data } = useVerifyReportBundle(runId ?? null);
  const roundPath = buildAcceptanceRoundPath(data?.run);
  // Copied and opened outside the app, so it stays on the public route: the
  // workspace-prefixed one only mounts for members of that workspace.
  const reportUrl = roundPath ? `${appOrigin}${roundPath}` : undefined;
  // Without an origin the URL is relative — the system browser has nothing to resolve it against.
  const externalUrl = appOrigin && reportUrl ? reportUrl : undefined;

  return { externalUrl, reportUrl, runId, standalone: Boolean(data) && !roundPath };
};