-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathcreate-project-frame.tsx
More file actions
86 lines (80 loc) · 2.16 KB
/
Copy pathcreate-project-frame.tsx
File metadata and controls
86 lines (80 loc) · 2.16 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import type { Rivet } from "@rivet-gg/cloud";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import * as CreateProjectForm from "@/app/forms/create-project-form";
import { Flex, Frame } from "@/components";
import { useCloudDataProvider } from "@/components/actors";
import { authClient } from "@/lib/auth";
import { features } from "@/lib/features";
const useDefaultOrg = () => {
if (features.platform) {
// biome-ignore lint/correctness/useHookAtTopLevel: guarded by build constant
const org = authClient.useActiveOrganization();
return org.data?.id;
}
return undefined;
};
export default function CreateProjectFrameContent({
organization,
onSuccess,
name,
}: {
name?: string;
organization?: string;
// FIXME
onSuccess?: (
data: Rivet.ProjectsCreateResponse,
vars: { displayName: string; organization: string },
) => void;
}) {
const queryClient = useQueryClient();
const navigate = useNavigate();
const provider = useCloudDataProvider();
const defaultOrg = useDefaultOrg();
const { mutateAsync } = useMutation({
...provider.createProjectMutationOptions(),
onSuccess: async (data, vars) => {
await queryClient.refetchQueries(
provider.currentOrgProjectsQueryOptions(),
);
return onSuccess
? onSuccess(data, vars)
: navigate({
to: "/orgs/$organization/projects/$project",
params: {
organization: vars.organization,
project: data.project.name,
},
});
},
});
return (
<CreateProjectForm.Form
onSubmit={async (values) => {
await mutateAsync({
displayName: values.name,
organization: values.organization,
});
}}
defaultValues={{
name: name,
organization: organization ?? defaultOrg ?? "",
}}
>
<Frame.Header>
<Frame.Title>Create Project</Frame.Title>
</Frame.Header>
<Frame.Content>
<Flex gap="4" direction="col">
<CreateProjectForm.Organization />
<CreateProjectForm.Name />
</Flex>
</Frame.Content>
<Frame.Footer>
<CreateProjectForm.Submit type="submit">
Create
</CreateProjectForm.Submit>
</Frame.Footer>
</CreateProjectForm.Form>
);
}