private IEnumerator RevertValueOnError(UserProfileEntryUI sender, UserProfileEntryType entryType, string oldValue)
        {
            yield return(new WaitWhile(_commonWaitCondition));

            if (_isProfileUpdated == false)
            {
                sender.InitializeEntry(entryType, oldValue);
            }
        }
        private void ShowInvalidValue(UserProfileEntryType entryType, string value)
        {
            if (value.Length > POPUP_VALUE_LIMIT)
            {
                value = $"{value.Substring(0, POPUP_VALUE_LIMIT)}...";
            }

            var errorMessage = $"Incorrect new value for {entryType}: '{value}'";
            var error        = new Error(ErrorType.InvalidData, errorMessage: errorMessage);

            StoreDemoPopup.ShowError(error);
        }
        private void OnUserEntryEdited(UserProfileEntryUI sender, UserProfileEntryType entryType, string oldValue, string newValue)
        {
            if (newValue == null)
            {
                Debug.LogError($"New value of entryType {entryType} is null. Can not update");
                sender.InitializeEntry(entryType, oldValue);
                return;
            }

            if (_isUpdateInProgress)
            {
                Debug.LogWarning("Can not update new entry while another update is in progress");
                sender.InitializeEntry(entryType, oldValue);
                return;
            }

            _isUpdateInProgress = true;
            _isProfileUpdated   = null;
            ShowWaiting(waitWhile: _commonWaitCondition);
            StartCoroutine(UnsetIsInProgressOnCompletion());
            StartCoroutine(RevertValueOnError(sender, entryType, oldValue));

            switch (entryType)
            {
            case UserProfileEntryType.DateOfBirth:
            case UserProfileEntryType.FirstName:
            case UserProfileEntryType.Gender:
            case UserProfileEntryType.LastName:
            case UserProfileEntryType.Nickname:
                UpdateCommonEntries(entryType, newValue);
                break;

            case UserProfileEntryType.PhoneNumber:
                if (!string.IsNullOrEmpty(newValue))
                {
                    UpdateUserPhoneNumber(newValue);
                }
                else
                {
                    StartCoroutine(DeleteUserPhoneNumber());
                }
                break;

            default:
                Debug.LogWarning($"Update of {entryType} is not supported");
                _isProfileUpdated = false;
                return;
            }
        }
        private void UpdateCommonEntries(UserProfileEntryType entryType, string newValue)
        {
            var infoUpdatePack = new UserInfoUpdate();
            var isValueValid   = newValue.Length <= 255;

            switch (entryType)
            {
            case UserProfileEntryType.DateOfBirth:
                if (DateTime.TryParse(newValue, out DateTime birthday))
                {
                    infoUpdatePack.birthday = newValue;
                }
                else
                {
                    isValueValid = false;
                }
                break;

            case UserProfileEntryType.FirstName:
                infoUpdatePack.first_name = newValue;
                break;

            case UserProfileEntryType.Gender:
                if (newValue == UserProfileGender.MALE_SHORT ||
                    newValue == UserProfileGender.FEMALE_SHORT ||
                    newValue == UserProfileGender.OTHER_LOWERCASE ||
                    newValue == UserProfileGender.PREFER_NOT_LOWERCASE)
                {
                    infoUpdatePack.gender = newValue;
                }
                else
                {
                    isValueValid = false;
                }
                break;

            case UserProfileEntryType.LastName:
                infoUpdatePack.last_name = newValue;
                break;

            case UserProfileEntryType.Nickname:
                StartCoroutine(UpdateUpperRightCornerInfoOnCompletion());
                infoUpdatePack.nickname = newValue;
                break;
            }

            if (!isValueValid)
            {
                ShowInvalidValue(entryType, newValue);
                _isProfileUpdated = false;
                return;
            }


            var token = Token.Instance;

            SdkLoginLogic.Instance.UpdateUserInfo(token, infoUpdatePack,
                                                  onSuccess: newInfo =>
            {
                InitializeEntries(newInfo);
                _isProfileUpdated = true;
            },
                                                  onError: _commonErrorCallback);
        }