import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { create_tasks, get_tasks } from '../../service.ts'; import { Button } from '../shared/Button.tsx'; import { ConfigurationWarning } from '../shared/ConfigurationWarning.tsx'; import { ErrorMessage } from '../shared/ErrorMessage.tsx'; import { Spinner } from '../shared/Spinner.tsx'; import { TaskInfo } from './TaskInfo.tsx'; interface OrderMetaBoxProps { order_id: number; order_key: string; } export function OrderMetaBox({ order_id, order_key }: OrderMetaBoxProps) { const query_client = useQueryClient(); const get_task_query = useQuery({ queryKey: ['tasks', order_key], queryFn: async () => get_tasks([order_key]), refetchOnWindowFocus: true, }); const create_task_mutation = useMutation({ mutationFn: async () => create_tasks([order_id]), onSuccess: async () => { await query_client.invalidateQueries({ queryKey: ['tasks', order_key] }); }, }); // Check if plugin is configured before attempting API calls const is_configured = window.JAAK_IS_CONFIGURED === true; if (!is_configured) { return (
); } const tasks = get_task_query.data; if (get_task_query.isPending) { return (
Loading
); } return (
{/* Error banners */} {get_task_query.isError && ( )} {create_task_mutation.isError && ( )} {/* Task info display */} {tasks?.map(task => (
))} {/* Primary action button (centered, only if no task) */} {(!tasks || tasks.length < 1) && (
)} {/* Updated timestamp button (right-aligned, always shown) */}
{/* Send again button (right-aligned, only if task exists) */} {(tasks && tasks.length >= 1) && (
)}
); }