New Contact Modal: Fix adding contact with hidden number (#1849)

This commit is contained in:
Alexander Zinchuk 2022-05-03 14:17:11 +01:00
parent 697b709d89
commit 39ce1790d1
3 changed files with 14 additions and 3 deletions

View File

@ -147,7 +147,10 @@ const NewContactModal: FC<OwnProps & StateProps> = ({
onChange={handleLastNameChange} onChange={handleLastNameChange}
/> />
<p className="NewContactModal__help-text"> <p className="NewContactModal__help-text">
{renderText(lang('NewContact.Phone.Hidden.Text', renderingUser?.firstName), ['emoji', 'simple_markdown'])} {renderText(
lang('NewContact.Phone.Hidden.Text', renderingUser?.firstName || ''),
['emoji', 'simple_markdown'],
)}
</p> </p>
<Checkbox <Checkbox
checked={shouldSharePhoneNumber} checked={shouldSharePhoneNumber}

View File

@ -194,12 +194,11 @@ async function updateContact(
}); });
} }
global = getGlobal();
if (result) { if (result) {
getActions().loadChatSettings({ chatId: userId }); getActions().loadChatSettings({ chatId: userId });
setGlobal(updateUser( setGlobal(updateUser(
global, getGlobal(),
user.id, user.id,
{ {
firstName, firstName,
@ -208,6 +207,7 @@ async function updateContact(
)); ));
} }
global = getGlobal();
global = updateManagementProgress(global, ManagementProgress.Complete); global = updateManagementProgress(global, ManagementProgress.Complete);
global = closeNewContactDialog(global); global = closeNewContactDialog(global);
setGlobal(global); setGlobal(global);

View File

@ -32,6 +32,10 @@ export function getCountryFromPhoneNumber(phoneCodeList: ApiCountryCode[], input
} }
export function formatPhoneNumber(input: string, country?: ApiCountryCode) { export function formatPhoneNumber(input: string, country?: ApiCountryCode) {
if (!input) {
return '';
}
let phoneNumber = input.replace(/[^\d]+/g, ''); let phoneNumber = input.replace(/[^\d]+/g, '');
if (country) { if (country) {
phoneNumber = phoneNumber.substr(country.countryCode.length); phoneNumber = phoneNumber.substr(country.countryCode.length);
@ -81,6 +85,10 @@ function getBestPattern(numberWithoutCode: string, patterns?: string[]) {
} }
export function formatPhoneNumberWithCode(phoneCodeList: ApiCountryCode[], phoneNumber: string) { export function formatPhoneNumberWithCode(phoneCodeList: ApiCountryCode[], phoneNumber: string) {
if (!phoneNumber) {
return '';
}
const numberWithPlus = phoneNumber.startsWith('+') ? phoneNumber : `+${phoneNumber}`; const numberWithPlus = phoneNumber.startsWith('+') ? phoneNumber : `+${phoneNumber}`;
const country = getCountryFromPhoneNumber(phoneCodeList, numberWithPlus); const country = getCountryFromPhoneNumber(phoneCodeList, numberWithPlus);
if (!country) { if (!country) {