Skip to content

Commit

Permalink
Add an error tooltip for User Profile (#2164)
Browse files Browse the repository at this point in the history
* Add an error tooltip for User Profile

* Add open on hover behaviour

* Fix style: added gap and decreased error icon

* Add an error tooltip to the personal info tab

* Fix test

* Fix linter errors

* Update src/pages/edit-profile/EditProfile.tsx

Co-authored-by: Olenka Hryk <[email protected]>

* Refactor enableTooltipError to use optional chain expression

---------

Co-authored-by: Olenka Hryk <[email protected]>
  • Loading branch information
ipasic-softserve and Olenka-Hryk authored Aug 2, 2024
1 parent 1428ac8 commit 702daaa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/components/sidebar-menu/SidebarMenu.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,14 @@ export const styles = {
minWidth: 'unset'
}
}
},
listItemContent: {
display: 'flex',
alignItems: 'center',
gap: 1.25
},
errorIcon: {
color: `${palette.error[800]} !important`,
fontSize: '1.25rem'
}
}
29 changes: 27 additions & 2 deletions src/components/sidebar-menu/SidebarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ListItemButton from '@mui/material/ListItemButton'
import ListItemText from '@mui/material/ListItemText'
import List from '@mui/material/List'
import ListItemIcon from '@mui/material/ListItemIcon'
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'
import { Box, Tooltip } from '@mui/material'

import { FC } from 'react'
import { useTranslation } from 'react-i18next'
Expand All @@ -16,9 +18,15 @@ interface SidebarMenu {
tabsData: UserProfileProps
handleClick: (tab: UserProfileTabsEnum) => void
activeTab: UserProfileTabsEnum
errorTooltipHolders: Partial<Record<UserProfileTabsEnum, boolean>>
}

const SidebarMenu: FC<SidebarMenu> = ({ handleClick, tabsData, activeTab }) => {
const SidebarMenu: FC<SidebarMenu> = ({
handleClick,
tabsData,
activeTab,
errorTooltipHolders
}) => {
const { t } = useTranslation()

const list = Object.keys(tabsData).map((key) => {
Expand All @@ -27,11 +35,28 @@ const SidebarMenu: FC<SidebarMenu> = ({ handleClick, tabsData, activeTab }) => {

const isTabActive = tabKey === activeTab

const enableTooltipError = !isTabActive && errorTooltipHolders?.[tabKey]

const toolTip = enableTooltipError && (
<Tooltip
arrow
placement='right'
title={t('editProfilePage.profile.generalTab.errorTooltip')}
>
<ErrorOutlineIcon sx={styles.errorIcon} />
</Tooltip>
)

return (
<ListItem key={tabKey} onClick={() => handleClick(tabKey)}>
<ListItemButton sx={styles.tabButton(isTabActive)}>
<ListItemIcon>{item.icon}</ListItemIcon>
<ListItemText primary={t(item.title)} />
<ListItemText>
<Box sx={styles.listItemContent}>
{t(item.title)}
{toolTip}
</Box>
</ListItemText>
</ListItemButton>
</ListItem>
)
Expand Down
3 changes: 2 additions & 1 deletion src/constants/translations/en/edit-profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"professionalStatus": "Describe in short your professional summary. Maximum 200 characters.",
"languagesTitle": "Language",
"languagesDesc": "Select the language in which you would like to study and cooperate.",
"videoPresentationDesc": "Add the link to your presentational video. Your video needs to be public and uploaded to YouTube."
"videoPresentationDesc": "Add the link to your presentational video. Your video needs to be public and uploaded to YouTube.",
"errorTooltip": "There is a problem with your changes"
},
"professionalTab": {
"tabTitle": "Professional info",
Expand Down
3 changes: 2 additions & 1 deletion src/constants/translations/uk/edit-profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"professionalStatus": "Коротко опишіть своє професійне резюме. Максимум 200 символів.",
"languagesTitle": "Мова",
"languagesDesc": "Виберіть мову, якою ви б хотіли навчатися та співпрацювати.",
"videoPresentationDesc": "Додайте посилання на вашу відеопрезентацію. Відео має бути публічним та розміщеним на YouTube."
"videoPresentationDesc": "Додайте посилання на вашу відеопрезентацію. Відео має бути публічним та розміщеним на YouTube.",
"errorTooltip": "Виникла проблема з вашими змінами"
},
"professionalTab": {
"tabTitle": "Професійні відомості",
Expand Down
10 changes: 9 additions & 1 deletion src/pages/edit-profile/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import { LoadingStatusEnum } from '~/redux/redux.constants'
const EditProfile = () => {
const { t } = useTranslation()
const dispatch = useAppDispatch()
const { loading } = useAppSelector((state) => state.editProfile)
const { loading, tabValidityStatus } = useAppSelector(
(state) => state.editProfile
)

const [searchParams, setSearchParams] = useSearchParams({
tab: UserProfileTabsEnum.Profile
Expand Down Expand Up @@ -66,6 +68,11 @@ const EditProfile = () => {
}

const cooperationContent = activeTab && tabsData[activeTab]?.content
const errorTooltipHolders = {
[UserProfileTabsEnum.Profile]: !tabValidityStatus.profileTab,
[UserProfileTabsEnum.ProfessionalInfo]:
!tabValidityStatus.professionalInfoTab
}

return (
<PageWrapper>
Expand All @@ -92,6 +99,7 @@ const EditProfile = () => {
<Box sx={styles.mainContainer}>
<SidebarMenu
activeTab={activeTab}
errorTooltipHolders={errorTooltipHolders}
handleClick={(tab) => void handleClick(tab)}
tabsData={tabsData}
/>
Expand Down

0 comments on commit 702daaa

Please sign in to comment.