From 467fb759cf457d48be18e0bfc5bcb5055f85ec23 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:01:40 -0300 Subject: [PATCH] Regression: nickname field in user profile. (#18359) * Added nickname field, hints for disabled fields * More missing nicknames --- client/account/AccountProfileForm.js | 23 +++++++++++++++++++++++ client/account/AccountProfilePage.js | 8 +++++++- client/admin/users/UserInfo.js | 2 ++ client/channel/UserCard/index.js | 2 ++ client/channel/UserInfo/index.js | 2 ++ client/components/basic/UserCard.js | 8 +++++--- client/components/basic/UserInfo.js | 12 +++++++++--- 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/client/account/AccountProfileForm.js b/client/account/AccountProfileForm.js index 5965e50a30e..368889d16ba 100644 --- a/client/account/AccountProfileForm.js +++ b/client/account/AccountProfileForm.js @@ -45,6 +45,7 @@ export default function AccountProfileForm({ values, handlers, user, settings, o bio, statusType, customFields, + nickname, } = values; const { @@ -58,6 +59,7 @@ export default function AccountProfileForm({ values, handlers, user, settings, o handleStatusType, handleBio, handleCustomFields, + handleNickname, } = handlers; const previousEmail = getUserEmailAddress(user); @@ -136,6 +138,9 @@ export default function AccountProfileForm({ values, handlers, user, settings, o + {!allowRealNameChange && + {t('RealName_Change_Disabled')} + } {nameError} @@ -145,6 +150,9 @@ export default function AccountProfileForm({ values, handlers, user, settings, o }/> + {!canChangeUsername && + {t('Username_Change_Disabled')} + } {usernameError} @@ -155,10 +163,19 @@ export default function AccountProfileForm({ values, handlers, user, settings, o }/> + {!allowUserStatusMessageChange && + {t('StatusMessage_Change_Disabled')} + } {statusTextError} , [t, statusTextError, allowUserStatusMessageChange, statusText, handleStatusText, handleStatusType, statusType])} + {useMemo(() => + {t('Nickname')} + + }/> + + , [nickname, handleNickname, t])} {useMemo(() => {t('Bio')} @@ -183,6 +200,9 @@ export default function AccountProfileForm({ values, handlers, user, settings, o disabled={!allowEmailChange} /> + {!allowEmailChange && + {t('Email_Change_Disabled')} + } {t(emailError)} @@ -203,6 +223,9 @@ export default function AccountProfileForm({ values, handlers, user, settings, o }/> + {!allowPasswordChange && + {t('Password_Change_Disabled')} + } , [t, password, handlePassword, passwordError, allowPasswordChange])} {useMemo(() => diff --git a/client/account/AccountProfilePage.js b/client/account/AccountProfilePage.js index a6fca317a0a..d6e897aad76 100644 --- a/client/account/AccountProfilePage.js +++ b/client/account/AccountProfilePage.js @@ -54,6 +54,7 @@ const getInitialValues = (user) => ({ statusType: user.status ?? '', bio: user.bio ?? '', customFields: user.customFields ?? {}, + nickname: user.nickname ?? '', }); const AccountProfilePage = () => { @@ -62,7 +63,7 @@ const AccountProfilePage = () => { const user = useUser(); - const { values, handlers, hasUnsavedChanges } = useForm(getInitialValues(user)); + const { values, handlers, hasUnsavedChanges, commit } = useForm(getInitialValues(user)); const [canSave, setCanSave] = useState(true); const setModal = useSetModal(); const [loggingOut, setLoggingOut] = useState(false); @@ -124,6 +125,7 @@ const AccountProfilePage = () => { statusType, customFields, bio, + nickname, } = values; const { handleAvatar } = handlers; @@ -143,8 +145,10 @@ const AccountProfilePage = () => { ...allowUserStatusMessageChange && { statusText }, ...typedPassword && { typedPassword: SHA256(typedPassword) }, statusType, + nickname, bio: bio || '', }, customFields); + commit(); dispatchToastMessage({ type: 'success', message: t('Profile_saved_successfully') }); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); @@ -185,6 +189,8 @@ const AccountProfilePage = () => { customFields, statusType, setModal, + commit, + nickname, ]); const handleLogoutOtherLocations = useCallback(async () => { diff --git a/client/admin/users/UserInfo.js b/client/admin/users/UserInfo.js index 7e2346a7536..7d4c345d928 100644 --- a/client/admin/users/UserInfo.js +++ b/client/admin/users/UserInfo.js @@ -32,6 +32,7 @@ export function UserInfoWithData({ uid, username, ...props }) { bio, utcOffset, lastLogin, + nickname, } = user; return { name: showRealNames ? name : username, @@ -48,6 +49,7 @@ export function UserInfoWithData({ uid, username, ...props }) { createdAt: user.createdAt, status: UserStatus.getStatus(status), customStatus: statusText, + nickname, }; }, [data, showRealNames]); diff --git a/client/channel/UserCard/index.js b/client/channel/UserCard/index.js index 05697ab71ec..9555388a5c6 100644 --- a/client/channel/UserCard/index.js +++ b/client/channel/UserCard/index.js @@ -59,6 +59,7 @@ const UserCardWithData = ({ username, onClose, target, open, rid }) => { statusText = status, bio = defaultValue, utcOffset = defaultValue, + nickname, } = user; return { @@ -74,6 +75,7 @@ const UserCardWithData = ({ username, onClose, target, open, rid }) => { ), status: UserStatus.getStatus(status), customStatus: statusText, + nickname, }; }, [data, username, showRealNames, state]); diff --git a/client/channel/UserInfo/index.js b/client/channel/UserInfo/index.js index a4cc799876b..e8549af9b4e 100644 --- a/client/channel/UserInfo/index.js +++ b/client/channel/UserInfo/index.js @@ -38,6 +38,7 @@ export const UserInfoWithData = React.memo(function UserInfoWithData({ uid, user bio, utcOffset, lastLogin, + nickname, } = user; return { name: showRealNames ? name : username, @@ -55,6 +56,7 @@ export const UserInfoWithData = React.memo(function UserInfoWithData({ uid, user // localTime: , status: UserStatus.getStatus(status), customStatus: statusText, + nickname, }; }, [data, showRealNames]); diff --git a/client/components/basic/UserCard.js b/client/components/basic/UserCard.js index 1f437ae7b88..942408d1e22 100644 --- a/client/components/basic/UserCard.js +++ b/client/components/basic/UserCard.js @@ -47,7 +47,7 @@ const Role = ({ children }) => ; -const UserCardConteiner = forwardRef((props, ref) => ); +const UserCardContainer = forwardRef((props, ref) => ); const UserCard = forwardRef(({ className, style, @@ -69,8 +69,9 @@ const UserCard = forwardRef(({ actions, localTime = , onClose, + nickname, t = (e) => e, -}, ref) => +}, ref) => { actions && @@ -79,6 +80,7 @@ const UserCard = forwardRef(({ + {nickname && {nickname}} { customStatus && {customStatus} } {roles} {localTime} @@ -86,7 +88,7 @@ const UserCard = forwardRef(({ {open && {t('See_full_profile')}} {onClose && } -); +); export default UserCard; diff --git a/client/components/basic/UserInfo.js b/client/components/basic/UserInfo.js index 165fb4cf5cb..37a131106a2 100644 --- a/client/components/basic/UserInfo.js +++ b/client/components/basic/UserInfo.js @@ -32,6 +32,7 @@ export const UserInfo = React.memo(function UserInfo({ customFields = [], name, data, + nickname, // onChange, actions, ...props @@ -68,6 +69,11 @@ export const UserInfo = React.memo(function UserInfo({ {name} } + {nickname && <> + + {nickname} + } + {bio && <> @@ -89,9 +95,9 @@ export const UserInfo = React.memo(function UserInfo({ } - { customFields && customFields.map((customField) => - - {customField.value} + { customFields && Object.entries(customFields).map(([label, value]) => + + {value} ) }