-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trip sharing #1304
Open
binh-dam-ibigroup
wants to merge
29
commits into
dev
Choose a base branch
from
trip-sharing
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+388
−90
Open
Trip sharing #1304
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cee60f4
feat(TripCompanionsPane): Add basic trip companions pane to trip sett…
binh-dam-ibigroup 354d41b
refactor(user/types): Add trip companion types
binh-dam-ibigroup 01ec9dc
feat(TripCompanionsPane): Support assigning companions
binh-dam-ibigroup 3559218
refactor(TripCompanionPane): Unwrap props
binh-dam-ibigroup 89bc8e0
refactor(CompanionSelector): Disable users used elsewhere
binh-dam-ibigroup 9b2e61a
refactor(TripCompanionsPane): Disable companion selection if trip was…
binh-dam-ibigroup c36f597
refactor(util/user): Extract code to get user from email
binh-dam-ibigroup 04fe8cc
feat(SavedTripScreen): Populate primary and companion traveler upon s…
binh-dam-ibigroup 73447d9
refactor(TripCompanionPane): Relax criterion for setting observers
binh-dam-ibigroup 10b13aa
refactor(actions/user): Usenew endpoint for retrieving trips
binh-dam-ibigroup ccd4d57
refactor(SavedTripScreen): Add readonly prop
binh-dam-ibigroup d7794a6
refactor(actions/user): Use existing endpoint for fetching trips
binh-dam-ibigroup 0a112e7
refactor(SavedTripScreen): Check that monitoredTrip is defined for re…
binh-dam-ibigroup 90ae3b3
Merge branch 'plan-trip-on-behalf-of' into trip-sharing
binh-dam-ibigroup 78e06d4
improvement(StackedPanesWithSave): Hide extra/okay btns if readonly
binh-dam-ibigroup 29a03df
refactor(Trip panes): Disable all inputs if readonly state
binh-dam-ibigroup 5af66ee
improvement(TripCompanionsPane): Display dependent info for trip wher…
binh-dam-ibigroup ab722cb
Merge branch 'plan-trip-on-behalf-of' into trip-sharing
binh-dam-ibigroup a8cba12
refactor(TripCompanionsPane): Implement i18n
binh-dam-ibigroup dcbdf32
improvement(SavedTripList): Hide pause button on read-only trips
binh-dam-ibigroup 8f33c04
refactor: Fix types
binh-dam-ibigroup aad9621
Merge branch 'plan-trip-on-behalf-of' into trip-sharing
binh-dam-ibigroup bca35c5
fix(TripCompanionsPane): Handle deleting companions.
binh-dam-ibigroup cc4b7a7
refactor(CompanionRefactor): Format invalid companion/observer refere…
binh-dam-ibigroup cf9d231
Merge branch 'dev' into trip-sharing
binh-dam-ibigroup 4a406cd
refactor(AdvancedSettingsPanel): Remove unused ui link
binh-dam-ibigroup b51a077
refactor(CompanionSelector): Fix types
binh-dam-ibigroup fab8b10
Merge branch 'dev' into trip-sharing
binh-dam-ibigroup 1dbdf17
Merge branch 'dev' into trip-sharing
binh-dam-ibigroup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
lib/components/user/mobility-profile/companion-selector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { connect } from 'react-redux' | ||
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 | ||
value: CompanionInfo | ||
} | ||
|
||
// @ts-expect-error: No types for react-select. | ||
const Select = lazy(() => import('react-select')) | ||
|
||
function notNull(item: unknown) { | ||
return !!item | ||
} | ||
|
||
function makeOption(companion?: CompanionInfo) { | ||
return { | ||
label: companion?.nickname || companion?.email, | ||
value: companion | ||
} | ||
} | ||
|
||
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 = [], | ||
loggedInUser, | ||
multi = false, | ||
onChange, | ||
selectedCompanions | ||
}: { | ||
disabled?: boolean | ||
excludedUsers?: (CompanionInfo | undefined)[] | ||
loggedInUser?: User | ||
multi?: boolean | ||
onChange: (e: Option | Option[]) => void | ||
selectedCompanions?: (CompanionInfo | undefined)[] | ||
}): JSX.Element => { | ||
const companionOptions = (loggedInUser?.relatedUsers || []) | ||
.filter(notNull) | ||
.filter(isConfirmed) | ||
.map(makeOption) | ||
const companionValues = multi | ||
? selectedCompanions?.filter(notNull).map(makeOption) | ||
: selectedCompanions?.[0] | ||
? makeOption(selectedCompanions[0]) | ||
: null | ||
|
||
const isOptionDisabled = useCallback( | ||
(option: Option) => excludedUsers.includes(option?.value), | ||
[excludedUsers] | ||
) | ||
|
||
return ( | ||
<Suspense fallback={<span>...</span>}> | ||
<Select | ||
formatOptionLabel={formatOptionLabel} | ||
isClearable | ||
isDisabled={disabled} | ||
isMulti={multi} | ||
isOptionDisabled={isOptionDisabled} | ||
onChange={onChange} | ||
options={companionOptions} | ||
value={companionValues} | ||
/> | ||
</Suspense> | ||
) | ||
} | ||
|
||
const mapStateToProps = (state: AppReduxState) => { | ||
return { | ||
loggedInUser: state.user.loggedInUser | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(CompanionSelector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
lib/components/user/mobility-profile/trip-companions-pane.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { connect } from 'react-redux' | ||
import { | ||
FormattedMessage, | ||
IntlShape, | ||
useIntl, | ||
WrappedComponentProps | ||
} from 'react-intl' | ||
import { FormikProps } from 'formik' | ||
import React, { useCallback, useEffect } from 'react' | ||
|
||
import * as userActions from '../../../actions/user' | ||
import { AppReduxState } from '../../../util/state-types' | ||
import { getDependentName } from '../../../util/user' | ||
import { MonitoredTrip, User } from '../types' | ||
|
||
import CompanionSelector, { Option } from './companion-selector' | ||
|
||
type Props = WrappedComponentProps & | ||
FormikProps<MonitoredTrip> & { | ||
getDependentUserInfo: (userIds: string[], intl: IntlShape) => void | ||
isReadOnly: boolean | ||
loggedInUser: User | ||
} | ||
|
||
function optionValue(option: Option | null) { | ||
if (!option) return null | ||
return option?.value | ||
} | ||
|
||
/** | ||
* Pane for showing/setting trip companions and observers. | ||
*/ | ||
const TripCompanions = ({ | ||
getDependentUserInfo, | ||
isReadOnly, | ||
loggedInUser, | ||
setFieldValue, | ||
values: trip | ||
}: Props): JSX.Element => { | ||
const handleCompanionChange = useCallback( | ||
(option: Option | Option[] | null) => { | ||
if (!option || 'label' in option) { | ||
setFieldValue('companion', optionValue(option)) | ||
} | ||
}, | ||
[setFieldValue] | ||
) | ||
|
||
const handleObserversChange = useCallback( | ||
(options: Option | Option[] | null) => { | ||
if (!options || 'length' in options) { | ||
setFieldValue('observers', (options || []).map(optionValue)) | ||
} | ||
}, | ||
[setFieldValue] | ||
) | ||
|
||
const intl = useIntl() | ||
const dependents = loggedInUser?.dependents | ||
|
||
useEffect(() => { | ||
if (dependents && dependents.length > 0) { | ||
getDependentUserInfo(dependents, intl) | ||
} | ||
}, [dependents, getDependentUserInfo, intl]) | ||
|
||
const { companion, observers, primary } = trip | ||
|
||
const iAmThePrimaryTraveler = | ||
(!primary && trip.userId === loggedInUser?.id) || | ||
primary?.userId === loggedInUser?.id | ||
|
||
const primaryTraveler = iAmThePrimaryTraveler | ||
? intl.formatMessage({ id: 'components.MobilityProfile.myself' }) | ||
: primary | ||
? primary.email | ||
: getDependentName( | ||
loggedInUser?.dependentsInfo?.find((d) => d.userId === trip.userId) | ||
) | ||
|
||
return ( | ||
<div> | ||
<p> | ||
<FormattedMessage id="components.TripCompanionsPane.primaryLabel" /> | ||
<strong>{primaryTraveler}</strong> | ||
</p> | ||
<p> | ||
<FormattedMessage id="components.TripCompanionsPane.companionLabel" /> | ||
<CompanionSelector | ||
disabled={isReadOnly || !iAmThePrimaryTraveler} | ||
excludedUsers={observers} | ||
onChange={handleCompanionChange} | ||
selectedCompanions={[companion]} | ||
/> | ||
</p> | ||
<p> | ||
<FormattedMessage id="components.TripCompanionsPane.observersLabel" /> | ||
<CompanionSelector | ||
disabled={isReadOnly} | ||
excludedUsers={[companion]} | ||
multi | ||
onChange={handleObserversChange} | ||
selectedCompanions={observers} | ||
/> | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
// connect to the redux store | ||
|
||
const mapStateToProps = (state: AppReduxState) => ({ | ||
loggedInUser: state.user.loggedInUser | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
getDependentUserInfo: userActions.getDependentUserInfo | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(TripCompanions) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the issue stems from this PR but I am seeing an issue with i18n strings in the wizard when it comes to the travel companion field