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>
45 lines
1.1 KiB
TypeScript
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 };
|
|
}
|