[portal][feat] allow changing email on settings page

pull/528/head
Yangshun Tay 2 years ago
parent 5b2f06fadc
commit c1d926c6fa

@ -34,6 +34,7 @@ function SettingsForm({
); );
const [name, setName] = useState(session?.user?.name); const [name, setName] = useState(session?.user?.name);
const [email, setEmail] = useState(session?.user?.email);
return ( return (
<div className="lg:py-18 bg-white py-12"> <div className="lg:py-18 bg-white py-12">
@ -50,6 +51,7 @@ function SettingsForm({
onSubmit={(event) => { onSubmit={(event) => {
event.preventDefault(); event.preventDefault();
updateProfileMutation.mutate({ updateProfileMutation.mutate({
email: email ? email : undefined,
name: name ? name : undefined, name: name ? name : undefined,
}); });
}}> }}>
@ -58,10 +60,20 @@ function SettingsForm({
<TextInput <TextInput
description="This name will be used across the entire platform" description="This name will be used across the entire platform"
label="Name" label="Name"
placeholder="John Doe"
value={name ?? undefined} value={name ?? undefined}
onChange={(val) => setName(val)} onChange={(val) => setName(val)}
/> />
</div> </div>
<div className="sm:col-span-3">
<TextInput
label="Email"
placeholder="john.doe@example.com"
type="email"
value={email ?? undefined}
onChange={(val) => setEmail(val)}
/>
</div>
{/* <div className="sm:col-span-6"> {/* <div className="sm:col-span-6">
<label <label
className="block text-sm font-medium text-gray-700" className="block text-sm font-medium text-gray-700"

@ -6,12 +6,14 @@ export const userRouter = createProtectedRouter().mutation(
'settings.profile.update', 'settings.profile.update',
{ {
input: z.object({ input: z.object({
email: z.string().optional(),
name: z.string().optional(), name: z.string().optional(),
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id; const userId = ctx.session?.user?.id;
return await ctx.prisma.user.update({ return await ctx.prisma.user.update({
data: { data: {
email: input.email,
name: input.name, name: input.name,
}, },
where: { where: {

Loading…
Cancel
Save