Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix issues with email change flow #1495

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/public/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,5 @@
"emailChangeRequestSentDescription": "To complete the change, please check your email for a verification link.",
"profileEmailAddress": "Email Address",
"profileEmailAddressDescription": "Your email address is used to log in to your account",
"emailAlreadyInUse": "Email already in use. Please try a different one or delete the existing account."
"emailAlreadyInUse": "This email address is already associated with another account. Please use a different email address."
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { usePostHog } from "@rallly/posthog/client";

Check failure on line 1 in apps/web/src/app/[locale]/(admin)/settings/profile/profile-email-address.tsx

View workflow job for this annotation

GitHub Actions / Linting

Run autofix to sort these imports!
import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
import { Button } from "@rallly/ui/button";
import {
Expand All @@ -20,19 +20,23 @@
import { Trans } from "@/components/trans";
import { useUser } from "@/components/user-provider";
import { trpc } from "@/trpc/client";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";

const emailChangeFormData = z.object({
email: z.string().email(),
});

type EmailChangeFormData = z.infer<typeof emailChangeFormData>;
export const ProfileEmailAddress = () => {
const { user, refresh } = useUser();
const requestEmailChange = trpc.user.requestEmailChange.useMutation();
const posthog = usePostHog();
const form = useForm<{
name: string;
email: string;
}>({
const form = useForm<EmailChangeFormData>({
defaultValues: {
name: user.isGuest ? "" : user.name,
email: user.email ?? "",
},
resolver: zodResolver(emailChangeFormData),
});
const { t } = useTranslation("app");
const { toast } = useToast();
Expand Down Expand Up @@ -82,7 +86,6 @@
<Form {...form}>
<form
onSubmit={handleSubmit(async (data) => {
reset(data);
if (data.email !== user.email) {
posthog.capture("email change requested");
const res = await requestEmailChange.mutateAsync({
Expand All @@ -99,9 +102,9 @@
}
} else {
setDidRequestEmailChange(true);
reset(data);
}
}
await refresh();
})}
>
<div className="flex flex-col gap-y-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Button } from "@rallly/ui/button";

Check failure on line 1 in apps/web/src/app/[locale]/(admin)/settings/profile/profile-settings.tsx

View workflow job for this annotation

GitHub Actions / Linting

Run autofix to sort these imports!
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@rallly/ui/form";
import { Input } from "@rallly/ui/input";
import { useForm } from "react-hook-form";
Expand All @@ -13,19 +14,24 @@
import { Trans } from "@/components/trans";
import { useUser } from "@/components/user-provider";
import { trpc } from "@/trpc/client";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";

const profileSettingsFormData = z.object({
name: z.string().min(1).max(100),
});

type ProfileSettingsFormData = z.infer<typeof profileSettingsFormData>;

export const ProfileSettings = () => {
const { user, refresh } = useUser();
const changeName = trpc.user.changeName.useMutation();

const form = useForm<{
name: string;
email: string;
}>({
const form = useForm<ProfileSettingsFormData>({
defaultValues: {
name: user.isGuest ? "" : user.name,
email: user.email ?? "",
},
resolver: zodResolver(profileSettingsFormData),
});

const { control, handleSubmit, formState, reset } = form;
Expand Down Expand Up @@ -54,6 +60,7 @@
<FormControl>
<Input id="name" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/emails/locales/en/emails.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"changeEmailRequest_text2": "To complete this change, please click the button below:",
"changeEmailRequest_button": "Verify Email Address",
"changeEmailRequest_subject": "Verify your new email address",
"changeEmailRequest_text3": "This link will expire in 10 minutes. If you did not request this change, please contact support.",
"changeEmailRequest_text3": "This link will expire in 10 minutes. If you did not request this change, please ignore this email.",
"changeEmailRequest_text1": "We've received a request to change the email address for your account from <b>{{fromEmail}}</b> to <b>{{toEmail}}</b>."
}
Loading