mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-24 14:26:23 +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 { m } from "framer-motion";
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
import posthog from "posthog-js";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
|
import { usePostHog } from "@/utils/posthog";
|
||||||
|
|
||||||
import { requiredString, validEmail } from "../../utils/form-validation";
|
import { requiredString, validEmail } from "../../utils/form-validation";
|
||||||
import { trpc } from "../../utils/trpc";
|
import { trpc } from "../../utils/trpc";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
|
@ -31,12 +32,12 @@ export const UserDetails: React.FunctionComponent<UserDetailsProps> = ({
|
||||||
defaultValues: { name, email },
|
defaultValues: { name, email },
|
||||||
});
|
});
|
||||||
|
|
||||||
const { refresh } = useUser();
|
const posthog = usePostHog();
|
||||||
|
|
||||||
const changeName = trpc.user.changeName.useMutation({
|
const changeName = trpc.user.changeName.useMutation({
|
||||||
onSuccess: (_, { name }) => {
|
onSuccess: (_, { name }) => {
|
||||||
posthog.people.set({ name });
|
reset({ name, email });
|
||||||
refresh();
|
posthog?.people.set({ name });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,7 +48,6 @@ export const UserDetails: React.FunctionComponent<UserDetailsProps> = ({
|
||||||
if (dirtyFields.name) {
|
if (dirtyFields.name) {
|
||||||
await changeName.mutateAsync({ userId, name: data.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">
|
<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";
|
import { usePostHog as usePostHogHook } from "posthog-js/react";
|
||||||
|
|
||||||
// Seems silly but annoyingly typescript tries to import usePostHog from
|
export const usePostHog = () => {
|
||||||
// posthog-js/react/dist/types which doesn't even work.
|
const posthog = usePostHogHook();
|
||||||
export const usePostHog = usePostHogHook;
|
return process.env.NEXT_PUBLIC_POSTHOG_API_KEY ? posthog : null;
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue