All files / src/apps/user/pages/swarms NewSwarm.tsx

55.55% Statements 5/9
100% Branches 0/0
25% Functions 1/4
55.55% Lines 5/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                      1x 3x 3x 3x 3x                                        
import SubPage from "@/components/page/SubPage/SubPage";
import { APP_ROUTES } from "@/routes/const";
import { swarmHref } from "@/routes/resourceHref";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useQueryClient } from "@tanstack/react-query";
import React from "react";
import { useNavigate } from "react-router-dom";
import SwarmForm from "./SwarmForm";
 
/** A new swarm, in the workspace the page is open in. */
const NewSwarm: React.FC = () => {
  const { getApiHandler } = useApiHandler();
  const queryClient = useQueryClient();
  const navigate = useNavigate();
  return (
    <SubPage
      title="New Swarm"
      description="A team of your agents in a shape, to send on a long task under a budget and a time cap."
      back={APP_ROUTES.USER.INFERENCE.swarms}
    >
      <SwarmForm
        submitLabel="Create Swarm"
        onSubmit={(body) => getApiHandler().swarm_router.create(body)}
        onDone={(swarm) => {
          void queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET.SWARMS] });
          navigate(swarmHref(swarm.id));
        }}
        onCancel={() => navigate(APP_ROUTES.USER.INFERENCE.swarms)}
      />
    </SubPage>
  );
};
 
export default NewSwarm;