fix: cart email/phone capture form was never rendered
recordOrder() and autoSubmitPurchase() read userEmail()/userPhone() signals and submitEmail() was fully implemented (validation, error handling), but the success screen's template never rendered the inputs - so the form was unreachable and the fallback auto-submit always sent blank email/phone. - Added the email/phone form to the payment-success screen, wired to the existing signals/handlers. - autoSubmitPurchase() (the 5s fallback if the user doesn't submit manually) no longer navigates home via an unconditional setTimeout(0) fired before the submission result is known - it now waits for submitPurchaseEmail() to settle, same as the manual path, and skips entirely if the user already submitted (new purchaseSubmitted flag). - It also now sends whatever the user has typed instead of hardcoded-blank fields, and shows a toast instead of only logging to console when no Telegram user id is available. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,7 @@ export class CartComponent implements OnDestroy {
|
||||
emailError = signal<string>('');
|
||||
phoneError = signal<string>('');
|
||||
emailSubmitting = signal<boolean>(false);
|
||||
purchaseSubmitted = signal<boolean>(false);
|
||||
paidItems: CartItem[] = [];
|
||||
|
||||
maxChecks = Math.ceil(PAYMENT_MIN_POLL_SECONDS / (PAYMENT_POLL_INTERVAL_MS / 1000));
|
||||
@@ -219,6 +220,7 @@ export class CartComponent implements OnDestroy {
|
||||
this.emailError.set('');
|
||||
this.phoneError.set('');
|
||||
this.emailSubmitting.set(false);
|
||||
this.purchaseSubmitted.set(false);
|
||||
this.paidItems = [...this.items()];
|
||||
this.createPayment(paymentMethod);
|
||||
}
|
||||
@@ -439,29 +441,39 @@ export class CartComponent implements OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback fired a few seconds after payment success if the user hasn't
|
||||
* already submitted the email/phone form themselves (submitEmail()).
|
||||
* Navigates home only once the submission result is known, never before -
|
||||
* and sends whatever the user has typed so far instead of blank fields.
|
||||
*/
|
||||
private autoSubmitPurchase(): void {
|
||||
setTimeout(() => {
|
||||
const lang = this.langService.currentLanguage();
|
||||
this.router.navigate([`/${lang}`]);}, 0);
|
||||
const telegramUserId = this.getTelegramUserId();
|
||||
|
||||
// Telegram ID is mandatory
|
||||
if (!telegramUserId) {
|
||||
console.error('Cannot submit purchase: Telegram ID is required');
|
||||
this.emailSubmitting.set(false);
|
||||
if (this.purchaseSubmitted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const telegramUserId = this.getTelegramUserId();
|
||||
|
||||
// Telegram ID is mandatory for submitPurchaseEmail.
|
||||
if (!telegramUserId) {
|
||||
this.notifications.show(this.i18n.t('cart.telegramIdMissing'), 'warning');
|
||||
this.emailSubmitting.set(false);
|
||||
this.closePaymentPopup();
|
||||
const lang = this.langService.currentLanguage();
|
||||
this.router.navigate([`/${lang}`]);
|
||||
return;
|
||||
}
|
||||
|
||||
this.emailSubmitting.set(true);
|
||||
|
||||
|
||||
const emailData = {
|
||||
email: '',
|
||||
phone: '',
|
||||
email: this.userEmail().trim(),
|
||||
phone: this.userPhone().replace(/\D/g, ''),
|
||||
telegramUserId: telegramUserId,
|
||||
items: this.paidItems.map((item: CartItem) => ({
|
||||
itemID: item.itemID,
|
||||
name: item.name,
|
||||
price: item.discount > 0
|
||||
price: item.discount > 0
|
||||
? item.price * (1 - item.discount / 100)
|
||||
: item.price,
|
||||
currency: item.currency,
|
||||
@@ -469,9 +481,10 @@ export class CartComponent implements OnDestroy {
|
||||
...(item.selectedDelivery ? { delivery: [item.selectedDelivery] } : {})
|
||||
}))
|
||||
};
|
||||
|
||||
|
||||
this.apiService.submitPurchaseEmail(emailData).subscribe({
|
||||
next: () => {
|
||||
this.purchaseSubmitted.set(true);
|
||||
this.emailSubmitting.set(false);
|
||||
this.closePaymentPopup();
|
||||
const lang = this.langService.currentLanguage();
|
||||
@@ -487,8 +500,6 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
});
|
||||
this.paymentStatus.set(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
copyPaymentLink(): void {
|
||||
@@ -541,6 +552,11 @@ export class CartComponent implements OnDestroy {
|
||||
|
||||
this.apiService.submitPurchaseEmail(emailData).subscribe({
|
||||
next: () => {
|
||||
this.purchaseSubmitted.set(true);
|
||||
if (this.closeTimeout) {
|
||||
clearTimeout(this.closeTimeout);
|
||||
this.closeTimeout = undefined;
|
||||
}
|
||||
this.emailSubmitting.set(false);
|
||||
this.notifications.show(this.i18n.t('cart.emailSuccess'), 'success');
|
||||
// Close popup and redirect to home page
|
||||
|
||||
Reference in New Issue
Block a user