Oliver-ai-bot_2.0/frontend/lib/hooks/useSlashCommands.ts
Vadym Samoilenko 96ecc59f0f feat: add open_as_popup mode for slash commands requiring MS auth
Microsoft MSAL redirect flow is blocked in iframes by browsers.
When open_as_popup is enabled, the command opens a real browser
popup window (window.open) instead of an iframe modal — MSAL auth
works correctly there.

- Migration 018_slash_popup: add open_as_popup boolean column
- Admin UI: new checkbox with explanation, purple Popup badge in list
- chat-input: if open_as_popup, calls window.open() centered on screen
  instead of showing IframeModal

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 19:05:11 +00:00

45 lines
1.1 KiB
TypeScript

'use client';
import { useState, useEffect } from 'react';
import apiClient from '@/lib/api-client';
export interface SlashCommandOut {
id: string;
name: string;
url: string;
description: string;
is_enabled: boolean;
sort_order: number;
pass_token: boolean;
open_as_popup: boolean;
}
let cachedCommands: SlashCommandOut[] | null = null;
export function useSlashCommands() {
const [commands, setCommands] = useState<SlashCommandOut[]>(cachedCommands ?? []);
const [isLoading, setIsLoading] = useState(cachedCommands === null);
useEffect(() => {
if (cachedCommands !== null) return;
let cancelled = false;
apiClient.get<SlashCommandOut[]>('/admin/slash-commands')
.then((data) => {
if (!cancelled) {
cachedCommands = data;
setCommands(data);
}
})
.catch((err) => {
console.error('Failed to load slash commands:', err);
})
.finally(() => {
if (!cancelled) setIsLoading(false);
});
return () => { cancelled = true; };
}, []);
return { commands, isLoading };
}