diff --git a/app/components/UserDialogs.tsx b/app/components/UserDialogs.tsx index 6022c2d105..776368abf4 100644 --- a/app/components/UserDialogs.tsx +++ b/app/components/UserDialogs.tsx @@ -5,6 +5,7 @@ import { UserRole } from "@shared/types"; import User from "~/models/User"; import ConfirmationDialog from "~/components/ConfirmationDialog"; import Input from "~/components/Input"; +import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; import { client } from "~/utils/ApiClient"; import Text from "./Text"; @@ -135,6 +136,7 @@ export function UserChangeNameDialog({ user, onSubmit }: Props) { export function UserChangeEmailDialog({ user, onSubmit }: Props) { const { t } = useTranslation(); + const actor = useCurrentUser(); const [email, setEmail] = React.useState(user.email); const [error, setError] = React.useState(); @@ -142,7 +144,11 @@ export function UserChangeEmailDialog({ user, onSubmit }: Props) { try { await client.post(`/users.updateEmail`, { id: user.id, email }); onSubmit(); - toast.info(t("Check your email to verify the new address.")); + toast.info( + actor.id === user.id + ? t("Check your email to verify the new address.") + : t("The email will be changed once verified.") + ); return true; } catch (err) { setError(err.message); @@ -162,10 +168,17 @@ export function UserChangeEmailDialog({ user, onSubmit }: Props) { disabled={!email || email === user.email} > - - You will receive an email to verify your new address. It must be - unique in the workspace. - + {actor.id === user.id ? ( + + You will receive an email to verify your new address. It must be + unique in the workspace. + + ) : ( + + A confirmation email will be sent to the new address before it is + changed. + + )} { + ev.preventDefault(); + dialogs.openModal({ + title: t("Change email"), + content: ( + + ), + }); + }, + [dialogs, t, user] + ); + const handleSuspend = React.useCallback( (ev: React.SyntheticEvent) => { ev.preventDefault(); @@ -117,7 +134,13 @@ function UserMenu({ user }: Props) { type: "button", title: `${t("Change name")}…`, onClick: handleChangeName, - visible: can.update && user.role !== "admin", + visible: can.update, + }, + { + type: "button", + title: `${t("Change email")}…`, + onClick: handleChangeEmail, + visible: can.update, }, { type: "button", diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 78302a759a..cde3ab797b 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -403,7 +403,9 @@ "New name": "New name", "Name can't be empty": "Name can't be empty", "Check your email to verify the new address.": "Check your email to verify the new address.", + "The email will be changed once verified.": "The email will be changed once verified.", "You will receive an email to verify your new address. It must be unique in the workspace.": "You will receive an email to verify your new address. It must be unique in the workspace.", + "A confirmation email will be sent to the new address before it is changed.": "A confirmation email will be sent to the new address before it is changed.", "New email": "New email", "Email can't be empty": "Email can't be empty", "Your import completed": "Your import completed", @@ -547,6 +549,7 @@ "Headings you add to the document will appear here": "Headings you add to the document will appear here", "Table of contents": "Table of contents", "Change name": "Change name", + "Change email": "Change email", "Suspend user": "Suspend user", "An error occurred while sending the invite": "An error occurred while sending the invite", "User options": "User options", @@ -982,7 +985,6 @@ "Auto-format text by replacing shortcuts with symbols, dashes, smart quotes, and other typographical elements.": "Auto-format text by replacing shortcuts with symbols, dashes, smart quotes, and other typographical elements.", "You may delete your account at any time, note that this is unrecoverable": "You may delete your account at any time, note that this is unrecoverable", "Profile saved": "Profile saved", - "Change email": "Change email", "Profile picture updated": "Profile picture updated", "Unable to upload new profile picture": "Unable to upload new profile picture", "Manage how you appear to other members of the workspace.": "Manage how you appear to other members of the workspace.",