Skip to content

Commit

Permalink
refactor(CompanionRefactor): Format invalid companion/observer refere…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
binh-dam-ibigroup committed Dec 11, 2024
1 parent bca35c5 commit cc4b7a7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/components/user/mobility-profile/companion-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { lazy, Suspense, useCallback } from 'react'

import { AppReduxState } from '../../../util/state-types'
import { CompanionInfo, User } from '../types'
import StatusBadge from '../../util/status-badge'

export interface Option {
label: string
Expand All @@ -23,6 +24,22 @@ function makeOption(companion?: CompanionInfo) {
}
}

function isConfirmed({ status = '' }: CompanionInfo) {
return status === 'CONFIRMED'
}

function formatOptionLabel(option: Option) {
if (!isConfirmed(option.value)) {
return (
<>
{option.label} <StatusBadge status={option.value.status} />
</>
)
} else {
return option.label
}
}

const CompanionSelector = ({
disabled,
excludedUsers = [],
Expand All @@ -40,7 +57,7 @@ const CompanionSelector = ({
}): JSX.Element => {
const companionOptions = (loggedInUser?.relatedUsers || [])
.filter(notNull)
.filter(({ status = '' }) => status === 'CONFIRMED')
.filter(isConfirmed)
.map(makeOption)
const companionValues = multi
? selectedCompanions?.filter(notNull).map(makeOption)
Expand All @@ -56,6 +73,7 @@ const CompanionSelector = ({
return (
<Suspense fallback={<span>...</span>}>
<Select
formatOptionLabel={formatOptionLabel}
isClearable
isDisabled={disabled}
isMulti={multi}
Expand Down

0 comments on commit cc4b7a7

Please sign in to comment.