From ed8487e0a94baf5e17a989c950d36101e0120c05 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Mon, 2 Sep 2024 17:23:56 +0000 Subject: [PATCH] tooltip --- src/components/elements/inputField.tsx | 64 +++++++++++++++++++++-- src/pages/user-settings/account/index.tsx | 10 ++-- src/server/callbacks/jwt.ts | 13 +++-- 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/src/components/elements/inputField.tsx b/src/components/elements/inputField.tsx index d61e5fc2..8fa21993 100644 --- a/src/components/elements/inputField.tsx +++ b/src/components/elements/inputField.tsx @@ -51,6 +51,12 @@ interface FormProps { color: string; onClick?: () => void; }; + toolTip?: { + text: string; + className?: string; + isVerified?: boolean; + onClick?: () => void; + }; } const InputField = ({ @@ -63,6 +69,7 @@ const InputField = ({ submitHandler, badge, headerBadge, + toolTip, isLoading, size = "md", buttonClassName, @@ -163,11 +170,11 @@ const InputField = ({ return ( { - e.stopPropagation(); // Prevent event from bubbling up + e.stopPropagation(); if (badgeProps.onClick) { badgeProps.onClick(); } @@ -177,6 +184,56 @@ const InputField = ({ ); }; + + const renderToolTip = (toolTip: FormProps["toolTip"]) => { + if (!toolTip) return null; + + return ( +
+ +
+ ); + }; return ( <> {!showInputs ? ( @@ -191,9 +248,10 @@ const InputField = ({

{description}

) : null} -
+
{placeholder ?? fields[0].placeholder} {renderBadge(badge)} + {renderToolTip(toolTip)}
diff --git a/src/pages/user-settings/account/index.tsx b/src/pages/user-settings/account/index.tsx index 4c08237c..8e9ed524 100644 --- a/src/pages/user-settings/account/index.tsx +++ b/src/pages/user-settings/account/index.tsx @@ -104,27 +104,27 @@ const Account = () => { isLoading={!session?.user} rootFormClassName="space-y-3 w-6/6 sm:w-3/6" size="sm" - badge={ + toolTip={ meLoading || sendMailLoading ? { text: "loading", - color: "ghost", } : me?.emailVerified ? { text: t("userSettings.account.accountSettings.verifiedBadge"), - color: "success", + className: "tooltip-success", + isVerified: true, } : { text: "Not verified, click to resend", - color: "warning", + className: "tooltip-primary", onClick: sendVerificationEmail, } } fields={[ { name: "email", - type: "text", + type: "email", placeholder: session?.user?.email, value: session?.user?.email, }, diff --git a/src/server/callbacks/jwt.ts b/src/server/callbacks/jwt.ts index 91dd589d..5d990508 100644 --- a/src/server/callbacks/jwt.ts +++ b/src/server/callbacks/jwt.ts @@ -25,7 +25,7 @@ export function jwtCallback(res) { // session update => https://github.com/nextauthjs/next-auth/discussions/3941 // verify that name has at least one character if (typeof session.update.name === "string") { - // TODO throwing error will logout user. + // !TODO throwing error will logout user. // if (session.update.name.length < 1) { // throw new Error("Name must be at least one character long."); // } @@ -35,14 +35,21 @@ export function jwtCallback(res) { // verify that email is valid if (typeof session.update.email === "string") { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call + const existingUser = await prisma.user.findUnique({ + where: { email: session.update.email }, + }); + + // if the email is already in use by another user, return the token. + // !TODO need to find a way to show error message to user. + if (existingUser && existingUser.id !== token.id) { + return token; + } token.email = session.update.email; updateObject.email = session.update.email; updateObject.emailVerified = user?.email === session.update.email ? user.emailVerified : null; } - // update user with new values await prisma.user.update({ where: {