diff --git a/src/FrontOffice.Main/Shared/AuthDialog.razor b/src/FrontOffice.Main/Shared/AuthDialog.razor index 650d24d..d4e7b30 100644 --- a/src/FrontOffice.Main/Shared/AuthDialog.razor +++ b/src/FrontOffice.Main/Shared/AuthDialog.razor @@ -22,7 +22,9 @@ PhoneNumber="@_phoneNumber" ResendRemaining="_resendRemaining" OnChangePhone="ChangePhoneAsync" - OnResendOtp="ResendOtpAsync" /> + OnResendOtp="ResendOtpAsync" + ReferralCode="@_referralCode" + ReferralCodeChanged="OnReferralCodeChanged" /> } else @@ -51,7 +53,9 @@ else PhoneNumber="@_phoneNumber" ResendRemaining="_resendRemaining" OnChangePhone="ChangePhoneAsync" - OnResendOtp="ResendOtpAsync" /> + OnResendOtp="ResendOtpAsync" + ReferralCode="@_referralCode" + ReferralCodeChanged="OnReferralCodeChanged" /> @if (_currentStep == AuthStep.Phone) diff --git a/src/FrontOffice.Main/Shared/AuthDialog.razor.cs b/src/FrontOffice.Main/Shared/AuthDialog.razor.cs index 57df4b9..0ce1755 100644 --- a/src/FrontOffice.Main/Shared/AuthDialog.razor.cs +++ b/src/FrontOffice.Main/Shared/AuthDialog.razor.cs @@ -42,6 +42,9 @@ public partial class AuthDialog : IDisposable private string? _captchaCode; private string? _captchaInput; + // Referral code field + private string? _referralCode; + [Inject] private ILocalStorageService LocalStorage { get; set; } = default!; [Inject] private UserContract.UserContractClient UserClient { get; set; } = default!; @@ -66,9 +69,20 @@ public partial class AuthDialog : IDisposable { _phoneRequest.Mobile = storedPhone; } + + _referralCode = await LocalStorage.GetItemAsync("referral:code"); // await LocalStorage.RemoveItemAsync(TokenStorageKey); } + private async Task OnReferralCodeChanged(string? value) + { + _referralCode = value; + if (!string.IsNullOrWhiteSpace(value)) + await LocalStorage.SetItemAsync("referral:code", value); + else + await LocalStorage.RemoveItemAsync("referral:code"); + } + private void GenerateCaptcha() { _captchaCode = Guid.NewGuid().ToString("N")[..6].ToUpperInvariant(); @@ -182,9 +196,12 @@ public partial class AuthDialog : IDisposable _verifyRequest.Mobile = _phoneNumber; var storedReferralCode = await LocalStorage.GetItemAsync("referral:code"); - if (!string.IsNullOrWhiteSpace(storedReferralCode)) + var effectiveReferralCode = !string.IsNullOrWhiteSpace(_referralCode) + ? _referralCode + : storedReferralCode; + if (!string.IsNullOrWhiteSpace(effectiveReferralCode)) { - _verifyRequest.ParentReferralCode = storedReferralCode; + _verifyRequest.ParentReferralCode = effectiveReferralCode; } var validationResult = true; // _verifyRequestValidator.Validate(_verifyRequest); diff --git a/src/FrontOffice.Main/Shared/PhoneVerifyForm.razor b/src/FrontOffice.Main/Shared/PhoneVerifyForm.razor index 16dc8bf..3ca37a4 100644 --- a/src/FrontOffice.Main/Shared/PhoneVerifyForm.razor +++ b/src/FrontOffice.Main/Shared/PhoneVerifyForm.razor @@ -36,6 +36,14 @@ Color="Color.Primary" Class="mb-2" /> + + @if (!string.IsNullOrWhiteSpace(ErrorMessage)) { ReferralCodeChanged { get; set; } + // ── Verify actions ── [Parameter] public EventCallback OnChangePhone { get; set; } [Parameter] public EventCallback OnResendOtp { get; set; }