mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-23 13:56:18 +02:00
🐛 Fix error thrown in handler when changing name (#598)
This commit is contained in:
parent
a3aae4804c
commit
d049e91665
2 changed files with 9 additions and 8 deletions
|
@ -1,9 +1,10 @@
|
|||
import { m } from "framer-motion";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import posthog from "posthog-js";
|
||||
import * as React from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { usePostHog } from "@/utils/posthog";
|
||||
|
||||
import { requiredString, validEmail } from "../../utils/form-validation";
|
||||
import { trpc } from "../../utils/trpc";
|
||||
import { Button } from "../button";
|
||||
|
@ -31,12 +32,12 @@ export const UserDetails: React.FunctionComponent<UserDetailsProps> = ({
|
|||
defaultValues: { name, email },
|
||||
});
|
||||
|
||||
const { refresh } = useUser();
|
||||
const posthog = usePostHog();
|
||||
|
||||
const changeName = trpc.user.changeName.useMutation({
|
||||
onSuccess: (_, { name }) => {
|
||||
posthog.people.set({ name });
|
||||
refresh();
|
||||
reset({ name, email });
|
||||
posthog?.people.set({ name });
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -47,7 +48,6 @@ export const UserDetails: React.FunctionComponent<UserDetailsProps> = ({
|
|||
if (dirtyFields.name) {
|
||||
await changeName.mutateAsync({ userId, name: data.name });
|
||||
}
|
||||
reset(data);
|
||||
})}
|
||||
>
|
||||
<div className="flex items-center justify-between border-b px-3 py-2 shadow-sm">
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { usePostHog as usePostHogHook } from "posthog-js/react";
|
||||
|
||||
// Seems silly but annoyingly typescript tries to import usePostHog from
|
||||
// posthog-js/react/dist/types which doesn't even work.
|
||||
export const usePostHog = usePostHogHook;
|
||||
export const usePostHog = () => {
|
||||
const posthog = usePostHogHook();
|
||||
return process.env.NEXT_PUBLIC_POSTHOG_API_KEY ? posthog : null;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue