diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/_components/_disable-user-button.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/_components/_disable-user-button.tsx index c8b8b20df..21662f08d 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/_components/_disable-user-button.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/_components/_disable-user-button.tsx @@ -16,22 +16,29 @@ export const DisableUserButton = ({ user }: DisableUserButtonProps) => { const t = useI18n(); const [isPending, startTransition] = useTransition(); const changeDisabledMutation = clientApi.user.changeDisabled.useMutation(); + const isDisabled = user.disabled; + + const getSuccessMessage = () => { + if (isDisabled) { + return { + title: t("user.action.enable.success", { defaultValue: "User enabled" }), + message: t("user.action.enable.successDescription", { defaultValue: "User has been enabled" }), + }; + } + return { + title: t("user.action.disable.success", { defaultValue: "User disabled" }), + message: t("user.action.disable.successDescription", { defaultValue: "User has been disabled" }), + }; + }; const handleToggle = () => { startTransition(async () => { try { await changeDisabledMutation.mutateAsync({ userId: user.id, - disabled: !user.disabled, - }); - showSuccessNotification({ - title: user.disabled - ? t("user.action.enable.success", { defaultValue: "User enabled" }) - : t("user.action.disable.success", { defaultValue: "User disabled" }), - message: user.disabled - ? t("user.action.enable.successDescription", { defaultValue: "User has been enabled" }) - : t("user.action.disable.successDescription", { defaultValue: "User has been disabled" }), + disabled: !isDisabled, }); + showSuccessNotification(getSuccessMessage()); } catch { showErrorNotification({ title: t("common.notification.update.error"), @@ -41,21 +48,31 @@ export const DisableUserButton = ({ user }: DisableUserButtonProps) => { }); }; - const tooltipLabel = user.disabled - ? t("user.action.enable.description", { defaultValue: "Enable this user" }) - : t("user.action.disable.description", { defaultValue: "Disable this user" }); + const getTooltipLabel = () => { + if (isDisabled) { + return t("user.action.enable.description", { defaultValue: "Enable this user" }); + } + return t("user.action.disable.description", { defaultValue: "Disable this user" }); + }; + + const getButtonLabel = () => { + if (isDisabled) { + return t("user.action.enable.label", { defaultValue: "Enable user" }); + } + return t("user.action.disable.label", { defaultValue: "Disable user" }); + }; + + const getButtonColor = () => (isDisabled ? "green" : "yellow"); return ( - + ); diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/page.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/page.tsx index 26e0c990d..620b02a33 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/page.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/general/page.tsx @@ -62,6 +62,19 @@ export default async function EditUserPage(props: Props) { const searchEngines = await api.searchEngine.getSelectable(); const isSelf = session?.user.id === user.id; const isCredentialsUser = user.provider === "credentials"; + const isDisabled = user.disabled; + + const getDisableItemLabel = () => { + if (isDisabled) return t("user.action.enable.label"); + return t("user.action.disable.label"); + }; + + const getDisableItemDescription = () => { + if (isDisabled) { + return t("management.page.user.action.enable.description", { defaultValue: "Re-enable access for this user" }); + } + return t("management.page.user.action.disable.description", { defaultValue: "Prevent this user from logging in" }); + }; return ( @@ -98,14 +111,8 @@ export default async function EditUserPage(props: Props) { } /> - row.original.disabled ? ( - {t("user.field.status.disabled", { defaultValue: "Disabled" })} - ) : null, + Cell: ({ row }) => { + if (!row.original.disabled) return null; + return {t("user.field.status.disabled", { defaultValue: "Disabled" })}; + }, }, ], [t],