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

Function EditClient

apps/start/src/modals/edit-client.tsx:27–69  ·  view source on GitHub ↗
({ id, name }: EditClientProps)

Source from the content-addressed store, hash-verified

25type IForm = z.infer<typeof validator>;
26
27export default function EditClient({ id, name }: EditClientProps) {
28 const queryClient = useQueryClient();
29 const { register, handleSubmit, reset, formState, control, setError } =
30 useForm<IForm>({
31 resolver: zodResolver(validator),
32 defaultValues: {
33 id,
34 name,
35 },
36 });
37
38 const trpc = useTRPC();
39 const mutation = useMutation(
40 trpc.client.update.mutationOptions({
41 onError: handleError,
42 onSuccess() {
43 reset();
44 toast('Success', {
45 description: 'Client updated.',
46 });
47 popModal();
48 queryClient.invalidateQueries(trpc.client.list.pathFilter());
49 },
50 }),
51 );
52
53 return (
54 <ModalContent>
55 <ModalHeader title="Edit client" />
56 <form onSubmit={handleSubmit((values) => mutation.mutate(values))}>
57 <InputWithLabel label="Name" placeholder="Name" {...register('name')} />
58 <ButtonContainer>
59 <Button type="button" variant="outline" onClick={() => popModal()}>
60 Cancel
61 </Button>
62 <Button type="submit" disabled={!formState.isDirty}>
63 Save
64 </Button>
65 </ButtonContainer>
66 </form>
67 </ModalContent>
68 );
69}

Callers

nothing calls this directly

Calls 1

handleSubmitFunction · 0.50

Tested by

no test coverage detected