import { useEffect, useState } from 'react'; import { authorizedGet } from '../../api'; import { useAuthToken } from './use-auth-token'; type Prompt = { id: string; user_id: string; prompt_title: string; workflow_manager_plan: string; result: string; created_at: string; user_prompt: string; }; export const useUserPrompts = () => { const [prompts, setPrompts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { getToken } = useAuthToken(); const fetchPrompts = async () => { setLoading(true); setError(null); try { const response = await authorizedGet("/api/user/prompts", getToken); setPrompts(response.data); } catch (err) { setError("Failed to fetch prompts"); console.error("Error fetching prompts:", err); } finally { setLoading(false); } }; useEffect(() => { fetchPrompts(); }, []); return { prompts, loading, error, refetch: fetchPrompts }; };