import { useMutation, useQuery } from '@tanstack/react-query'; import { create_tasks, get_orders, get_tasks, SITE_BASE_URL } from '../../service.ts'; import { ConfigurationWarning } from '../shared/ConfigurationWarning.tsx'; import { ErrorMessage } from '../shared/ErrorMessage.tsx'; export function BulkActionModal({ order_ids, on_close }: { order_ids: number[]; on_close: () => void }) { const get_tasks_query = useQuery({ queryKey: ['bulk-tasks', ...order_ids], queryFn: async () => { // First fetch orders to get their order keys const orders = await get_orders(order_ids); const order_keys = orders.map(order => order.order_key); // Then check for existing tasks using order keys return get_tasks(order_keys); }, }); const create_tasks_mutation = useMutation({ mutationFn: async () => create_tasks(order_ids), onSuccess: () => { // Close modal on success on_close(); }, }); // Check if plugin is configured before attempting API calls const is_configured = window.JAAK_IS_CONFIGURED === true; if (!is_configured) { return (
Do you want to send {order_ids.length} selected order(s) to Jaak?
Note that it may take a moment until all orders are available on your Jaak dashboard.
{/* Error States */} {get_tasks_query.isError && (Some selected orders already exist in Jaak: