MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / AddClient

Function AddClient

apps/start/src/modals/add-client.tsx:29–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27type IForm = z.infer<typeof validation>;
28
29export default function AddClient() {
30 const { organizationId, projectId } = useAppParams();
31 const form = useForm<IForm>({
32 resolver: zodResolver(validation),
33 defaultValues: {
34 name: '',
35 type: 'write',
36 },
37 });
38 const queryClient = useQueryClient();
39 const trpc = useTRPC();
40 const mutation = useMutation(
41 trpc.client.create.mutationOptions({
42 onSuccess() {
43 toast.success('Client created successfully');
44 queryClient.invalidateQueries(
45 trpc.project.getProjectWithClients.pathFilter(),
46 );
47 queryClient.invalidateQueries(
48 trpc.client.list.queryFilter({ projectId }),
49 );
50 },
51 onError: handleError,
52 }),
53 );
54
55 const onSubmit: SubmitHandler<IForm> = (values) => {
56 mutation.mutate({
57 name: values.name,
58 type: values.type,
59 projectId,
60 organizationId,
61 });
62 };
63
64 return (
65 <ModalContent>
66 {mutation.isSuccess ? (
67 <>
68 <ModalHeader title="Success" text={'Your client is created'} />
69 <CreateClientSuccess {...mutation.data} />
70 <div className="mt-4 flex gap-4">
71 <a
72 className={cn(buttonVariants({ variant: 'secondary' }), 'flex-1')}
73 href="https://openpanel.dev/docs"
74 target="_blank"
75 rel="noreferrer"
76 >
77 Read docs
78 </a>
79 <Button className="flex-1" onClick={() => popModal()}>
80 Close
81 </Button>
82 </div>
83 </>
84 ) : (
85 <>
86 <ModalHeader title="Create a client" />

Callers

nothing calls this directly

Calls 2

useAppParamsFunction · 0.90
cnFunction · 0.90

Tested by

no test coverage detected