Skip to content

Commit 6b93fcc

Browse files
committed
Remove create group service
1 parent 07a4bd4 commit 6b93fcc

File tree

3 files changed

+26
-78
lines changed

3 files changed

+26
-78
lines changed

site/src/api/queries/groups.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
import { QueryClient } from "@tanstack/react-query";
12
import * as API from "api/api";
3+
import { CreateGroupRequest } from "api/typesGenerated";
24

35
export const groups = (organizationId: string) => {
46
return {
57
queryKey: ["groups"],
68
queryFn: () => API.getGroups(organizationId),
79
};
810
};
11+
12+
export const createGroup = (queryClient: QueryClient) => {
13+
return {
14+
mutationFn: ({
15+
organizationId,
16+
...request
17+
}: CreateGroupRequest & { organizationId: string }) =>
18+
API.createGroup(organizationId, request),
19+
onSuccess: async () => {
20+
await queryClient.invalidateQueries(["groups"]);
21+
},
22+
};
23+
};

site/src/pages/GroupsPage/CreateGroupPage.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
import { useMachine } from "@xstate/react";
21
import { useOrganizationId } from "hooks/useOrganizationId";
32
import { FC } from "react";
43
import { Helmet } from "react-helmet-async";
54
import { useNavigate } from "react-router-dom";
65
import { pageTitle } from "utils/page";
7-
import { createGroupMachine } from "xServices/groups/createGroupXService";
86
import CreateGroupPageView from "./CreateGroupPageView";
7+
import { useMutation, useQueryClient } from "@tanstack/react-query";
8+
import { createGroup } from "api/queries/groups";
99

1010
export const CreateGroupPage: FC = () => {
11+
const queryClient = useQueryClient();
1112
const navigate = useNavigate();
1213
const organizationId = useOrganizationId();
13-
const [createState, sendCreateEvent] = useMachine(createGroupMachine, {
14-
context: {
15-
organizationId,
16-
},
17-
actions: {
18-
onCreate: (_, { data }) => {
19-
navigate(`/groups/${data.id}`);
20-
},
21-
},
22-
});
23-
const { error } = createState.context;
14+
const createGroupMutation = useMutation(createGroup(queryClient));
2415

2516
return (
2617
<>
2718
<Helmet>
2819
<title>{pageTitle("Create Group")}</title>
2920
</Helmet>
3021
<CreateGroupPageView
31-
onSubmit={(data) => {
32-
sendCreateEvent({
33-
type: "CREATE",
34-
data,
22+
onSubmit={async (data) => {
23+
const newGroup = await createGroupMutation.mutateAsync({
24+
organizationId,
25+
...data,
3526
});
27+
navigate(`/groups/${newGroup.id}`);
3628
}}
37-
formErrors={error}
38-
isLoading={createState.matches("creatingGroup")}
29+
formErrors={createGroupMutation.error}
30+
isLoading={createGroupMutation.isLoading}
3931
/>
4032
</>
4133
);

site/src/xServices/groups/createGroupXService.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)