From 191011e1089a72501701e60e8118cd1c9532d1ab Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 20 Apr 2023 18:13:05 +0200 Subject: [PATCH] refactor(client): profile component into sub components (#49956) * refactor(client): profile component into sub components * Clean the future PR changes * fix the broken if statement cased by prettier and clean change log * Better variable name for boolean variable Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> * Revert the removing of vistor Co-authored-by: ahmad abdolsaheb * better naming for the component * fix typo in message components Co-authored-by: sembauke --------- Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Co-authored-by: ahmad abdolsaheb Co-authored-by: sembauke --- client/src/components/profile/profile.tsx | 101 ++++++++++++---------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/client/src/components/profile/profile.tsx b/client/src/components/profile/profile.tsx index 14333227995..97cbed938bc 100644 --- a/client/src/components/profile/profile.tsx +++ b/client/src/components/profile/profile.tsx @@ -16,51 +16,58 @@ interface ProfileProps { isSessionUser: boolean; user: User; } - -function renderMessage( - isSessionUser: boolean, - username: string, - t: TFunction -): JSX.Element { - return isSessionUser ? ( - <> - -

{t('profile.you-not-public')}

-
- -

{t('profile.you-change-privacy')}

-
- - - ) : ( - <> - -

- {t('profile.username-not-public', { username: username })} -

-
- -

- {t('profile.username-change-privacy', { username: username })} -

-
- - - ); +interface MessageProps { + isSessionUser: boolean; + t: TFunction; + username: string; } -function renderProfile(user: ProfileProps['user']): JSX.Element { +const UserMessage = ({ t }: Pick) => { + return ( + +

{t('profile.you-not-public')}

+

{t('profile.you-change-privacy')}

+ +
+ ); +}; + +const VisitorMessage = ({ + t, + username +}: Omit) => { + return ( + +

+ {t('profile.username-not-public', { username: username })} +

+

+ {t('profile.username-change-privacy', { username: username })} +

+ +
+ ); +}; + +const Message = ({ isSessionUser, t, username }: MessageProps) => { + if (isSessionUser) { + return ; + } + return ; +}; + +function UserProfile({ user }: { user: ProfileProps['user'] }): JSX.Element { const { profileUI: { - showAbout = false, - showCerts = false, - showDonation = false, - showHeatMap = false, - showLocation = false, - showName = false, - showPoints = false, - showPortfolio = false, - showTimeLine = false + showAbout, + showCerts, + showDonation, + showHeatMap, + showLocation, + showName, + showPoints, + showPortfolio, + showTimeLine }, calendar, completedChallenges, @@ -112,10 +119,12 @@ function renderProfile(user: ProfileProps['user']): JSX.Element { function Profile({ user, isSessionUser }: ProfileProps): JSX.Element { const { t } = useTranslation(); const { - profileUI: { isLocked = true }, + profileUI: { isLocked }, username } = user; + const showUserProfile = !isLocked || isSessionUser; + return ( <> @@ -124,9 +133,11 @@ function Profile({ user, isSessionUser }: ProfileProps): JSX.Element { - {isLocked ? renderMessage(isSessionUser, username, t) : null} - {!isLocked || isSessionUser ? renderProfile(user) : null} - {isSessionUser ? null : ( + {isLocked && ( + + )} + {showUserProfile && } + {!isSessionUser && ( {t('buttons.flag-user')}