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}
/>
<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>
<Checkbox
checked={shouldSharePhoneNumber}

View File

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

View File

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