Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ProfileCompletenessProps {

const ProfileCompleteness: FC<ProfileCompletenessProps> = props => {
const completeness = useProfileCompleteness(props.profile.handle)
const completed = completeness.percent
const completed = Number(completeness.percent?.toFixed(2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of Number(completeness.percent?.toFixed(2)) could potentially lead to NaN if completeness.percent is null or undefined. Consider providing a default value to handle such cases, e.g., Number(completeness.percent?.toFixed(2) || 0). This ensures completed is always a valid number.

const isLoading = completeness.isLoading
const isCompleted = completed === 100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import moment from 'moment'
import {
NamesAndHandleAppearance,
UserProfile,
UserRole,
} from '~/libs/core'
import { ProfilePicture, useCheckIsMobile } from '~/libs/shared'
import { Tooltip } from '~/libs/ui'
Expand All @@ -32,6 +33,17 @@ const ProfileHeader: FC<ProfileHeaderProps> = (props: ProfileHeaderProps) => {
const hasProfilePicture = !!props.profile.photoURL

const canEdit: boolean = props.authProfile?.handle === props.profile.handle

const roles = props.authProfile?.roles || []

const isPrivilegedViewer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 readability]
The variable isPrivilegedViewer is defined using a combination of negation and logical operators, which can be difficult to read and understand at a glance. Consider refactoring to improve readability, such as by using a positive condition or extracting the logic into a well-named function.

= !canEdit
&& (
roles.includes(UserRole.administrator)
|| roles.includes(UserRole.projectManager)
|| roles.includes(UserRole.talentManager)
)

const canSeeActivityBadge = props.profile.recentActivity

const [isNameEditMode, setIsNameEditMode]: [boolean, Dispatch<SetStateAction<boolean>>]
Expand Down Expand Up @@ -95,9 +107,20 @@ const ProfileHeader: FC<ProfileHeaderProps> = (props: ProfileHeaderProps) => {
}

function renderOpenForWork(): JSX.Element {
const showMyStatusLabel = canEdit
const showAdminLabel = isPrivilegedViewer

return (
<div className={styles.profileActions}>
<span>My status:</span>
{showMyStatusLabel && <span>My status:</span>}

{showAdminLabel && (
<span>
{props.profile.firstName}
{' '}
is
</span>
)}
<OpenForGigs
canEdit={canEdit}
authProfile={props.authProfile}
Expand Down Expand Up @@ -201,7 +224,7 @@ const ProfileHeader: FC<ProfileHeaderProps> = (props: ProfileHeaderProps) => {
{
// Showing only when they can edit until we have the talent search app
// and enough data to make this useful
canEdit ? renderOpenForWork() : undefined
canEdit || isPrivilegedViewer ? renderOpenForWork() : undefined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 style]
The conditional expression canEdit || isPrivilegedViewer ? renderOpenForWork() : undefined could be simplified by using a short-circuit evaluation: canEdit || isPrivilegedViewer && renderOpenForWork(). This would make the code more concise and potentially easier to read.

}

{
Expand Down
Loading