|
1 | 1 | import {format, isValid, parse} from 'date-fns'; |
| 2 | +import {Str} from 'expensify-common'; |
2 | 3 | import {deepEqual} from 'fast-equals'; |
3 | 4 | import lodashDeepClone from 'lodash/cloneDeep'; |
4 | 5 | import lodashSet from 'lodash/set'; |
@@ -1205,20 +1206,23 @@ function getAttendees(transaction: OnyxInputOrEntry<Transaction>, currentUserPer |
1205 | 1206 | } |
1206 | 1207 |
|
1207 | 1208 | /** |
1208 | | - * Returns attendees joined as an alphabetically sorted display string. Sort is part of the contract — every consumer relies on it. |
| 1209 | + * Returns attendees joined as a display string. Pass `localeCompare` to sort alphabetically (matches the pill sort); |
| 1210 | + * omit it to keep insertion order — used by non-React callers that don't want to thread the comparator. |
| 1211 | + * Strips the SMS domain so phone-login attendees render the same as in the rendered pills. |
1209 | 1212 | */ |
1210 | | -function getAttendeesListDisplayString(attendees: Attendee[], localeCompare: LocaleContextProps['localeCompare']): string { |
1211 | | - // Lowercase to match sortAlphabetically (the pill sort) so joined string and pill order never disagree on case. |
1212 | | - return [...attendees] |
1213 | | - .sort((a, b) => localeCompare((a.displayName ?? a.login ?? '').toLowerCase(), (b.displayName ?? b.login ?? '').toLowerCase())) |
1214 | | - .map((item) => item.displayName ?? item.login) |
1215 | | - .join(', '); |
| 1213 | +function getAttendeesListDisplayString(attendees: Attendee[], localeCompare?: LocaleContextProps['localeCompare']): string { |
| 1214 | + const getName = (a: Attendee) => Str.removeSMSDomain(a.displayName ?? a.login ?? ''); |
| 1215 | + const ordered = localeCompare |
| 1216 | + ? // Lowercase to match sortAlphabetically (the pill sort) so joined string and pill order never disagree on case. |
| 1217 | + [...attendees].sort((a, b) => localeCompare(getName(a).toLowerCase(), getName(b).toLowerCase())) |
| 1218 | + : attendees; |
| 1219 | + return ordered.map(getName).join(', '); |
1216 | 1220 | } |
1217 | 1221 |
|
1218 | 1222 | /** |
1219 | 1223 | * Return the list of attendees as a string and modified list of attendees as a string if present. |
1220 | 1224 | */ |
1221 | | -function getFormattedAttendees(localeCompare: LocaleContextProps['localeCompare'], modifiedAttendees?: Attendee[], attendees?: Attendee[]): [string, string] { |
| 1225 | +function getFormattedAttendees(modifiedAttendees?: Attendee[], attendees?: Attendee[], localeCompare?: LocaleContextProps['localeCompare']): [string, string] { |
1222 | 1226 | const oldAttendees = modifiedAttendees ?? []; |
1223 | 1227 | const newAttendees = attendees ?? []; |
1224 | 1228 | return [getAttendeesListDisplayString(oldAttendees, localeCompare), getAttendeesListDisplayString(newAttendees, localeCompare)]; |
|
0 commit comments