Fix adding to group by username

This commit is contained in:
Fedor Indutny 2023-01-02 09:25:44 -08:00 committed by GitHub
parent 98ffdc2823
commit 53fbc85b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,11 +14,13 @@ import Measure from 'react-measure';
import type { LocalizerType, ThemeType } from '../../../../types/Util'; import type { LocalizerType, ThemeType } from '../../../../types/Util';
import { getUsernameFromSearch } from '../../../../types/Username'; import { getUsernameFromSearch } from '../../../../types/Username';
import { strictAssert } from '../../../../util/assert';
import { refMerger } from '../../../../util/refMerger'; import { refMerger } from '../../../../util/refMerger';
import { useRestoreFocus } from '../../../../hooks/useRestoreFocus'; import { useRestoreFocus } from '../../../../hooks/useRestoreFocus';
import { missingCaseError } from '../../../../util/missingCaseError'; import { missingCaseError } from '../../../../util/missingCaseError';
import type { LookupConversationWithoutUuidActionsType } from '../../../../util/lookupConversationWithoutUuid'; import type { LookupConversationWithoutUuidActionsType } from '../../../../util/lookupConversationWithoutUuid';
import { parseAndFormatPhoneNumber } from '../../../../util/libphonenumberInstance'; import { parseAndFormatPhoneNumber } from '../../../../util/libphonenumberInstance';
import type { ParsedE164Type } from '../../../../util/libphonenumberInstance';
import { filterAndSortConversationsByRecent } from '../../../../util/filterAndSortConversations'; import { filterAndSortConversationsByRecent } from '../../../../util/filterAndSortConversations';
import type { ConversationType } from '../../../../state/ducks/conversations'; import type { ConversationType } from '../../../../state/ducks/conversations';
import type { PreferredBadgeSelectorType } from '../../../../state/selectors/badges'; import type { PreferredBadgeSelectorType } from '../../../../state/selectors/badges';
@ -91,8 +93,6 @@ export function ChooseGroupMembersModal({
}: PropsType): JSX.Element { }: PropsType): JSX.Element {
const [focusRef] = useRestoreFocus(); const [focusRef] = useRestoreFocus();
const phoneNumber = parseAndFormatPhoneNumber(searchTerm, regionCode);
let username: string | undefined; let username: string | undefined;
let isUsernameChecked = false; let isUsernameChecked = false;
let isUsernameVisible = false; let isUsernameVisible = false;
@ -108,16 +108,23 @@ export function ChooseGroupMembersModal({
candidateContacts.every(contact => contact.username !== username); candidateContacts.every(contact => contact.username !== username);
} }
let isPhoneNumberChecked = false; let phoneNumber: ParsedE164Type | undefined;
if (!username && phoneNumber) { if (!username) {
isPhoneNumberChecked = phoneNumber = parseAndFormatPhoneNumber(searchTerm, regionCode);
phoneNumber.isValid &&
selectedContacts.some(contact => contact.e164 === phoneNumber.e164);
} }
const isPhoneNumberVisible = let isPhoneNumberChecked = false;
phoneNumber && let isPhoneNumberVisible = false;
candidateContacts.every(contact => contact.e164 !== phoneNumber.e164); if (phoneNumber) {
const { e164 } = phoneNumber;
isPhoneNumberChecked =
phoneNumber.isValid &&
selectedContacts.some(contact => contact.e164 === e164);
isPhoneNumberVisible = candidateContacts.every(
contact => contact.e164 !== e164
);
}
const inputRef = useRef<null | HTMLInputElement>(null); const inputRef = useRef<null | HTMLInputElement>(null);
@ -229,6 +236,10 @@ export function ChooseGroupMembersModal({
virtualIndex -= filteredContacts.length; virtualIndex -= filteredContacts.length;
if (isPhoneNumberVisible) { if (isPhoneNumberVisible) {
strictAssert(
phoneNumber !== undefined,
"phone number can't be visible if not present"
);
if (virtualIndex === 0) { if (virtualIndex === 0) {
return { return {
type: RowType.Header, type: RowType.Header,