From 56b1249e3de90980417f96b0f1208f2821e22534 Mon Sep 17 00:00:00 2001 From: nikolay Date: Mon, 17 Jul 2023 11:33:26 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14760=20=D0=9A=D0=BE=D1=84=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=B9=D0=BA=20WPA=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B5=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=B7=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F:=20add=20description=20?= =?UTF-8?q?table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular/src/app/interface/data.ts | 4 +- .../guest-card/guest-card.component.html | 13 +---- .../pages/guest-card/guest-card.component.ts | 55 ++++++++++++++++++- angular/src/app/utils.ts | 10 +++- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/angular/src/app/interface/data.ts b/angular/src/app/interface/data.ts index 47f34e9..9ca4985 100644 --- a/angular/src/app/interface/data.ts +++ b/angular/src/app/interface/data.ts @@ -6,7 +6,7 @@ export enum PageCode { UserData, } -export interface Moment extends moment.Moment { } +export interface Moment extends moment.Moment {} export interface Page { code: PageCode; @@ -216,7 +216,7 @@ export interface NextLevel { } export interface UserInfo { - current_level_and_cashback?: CurrentInfo; + current_level_and_cashback: CurrentInfo; last_purchase?: LastPurchase; id: string; phone: string; diff --git a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html index c7f414a..60ed553 100644 --- a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html +++ b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html @@ -29,18 +29,7 @@

- Осталось купить на сумму - {{ - authService.error ? '--' : authService.userInfo.next_level.sum_for_next_level - }} - рублей, тогда кэшбек будет - {{ authService.error ? '--' : authService.userInfo.next_level.cashback}}% - с - {{ - authService.currentPeriod[1] - .locale("ru") - .format("D MMMM") - }} + {{getLevelDescription()}}

diff --git a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts index 9229ca6..8c26c35 100644 --- a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts +++ b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts @@ -5,6 +5,34 @@ import { CookiesService } from 'src/app/services/cookies.service'; import { MessageService } from 'primeng/api'; import { MessagingService } from 'src/app/services/messaging.service'; import { AuthService } from 'src/app/services/auth.service'; +import { format } from 'src/app/utils'; + +const levelDescriptionsTable = [ + [ + 'Поднимай свой уровень! Купи еще на {0}₽ и твой кешбек будет 6% с {1}!', + 'А ты хорош! Купи еще на {0}₽ и получай кешбек 10% с {1}', + 'Ты крут! Купи еще на {0}₽ и получай максимальный кешбек 15% с {1}', + 'Ты сделал это! Купи на {0}₽ и сохраняй максимальный кешбек 15% с {1}', + ], + [ + 'Oops! Ты оказался на 1 уровне. Купи еще на {0}₽ и твой кешбек будет 6% с {1}!', + 'Ты можешь стать круче! Купи еще на {0}₽ и получай кешбек 10% с {1}', + 'Ого! Ты уже здесь! Хочешь еще больше кешбека? Купи на {0}₽ и получай максимальный кешбек 15% с {1}', + 'Ты потрясающий! Покупай на {0}₽ и сохраняй максимальный кешбек 15% с {1}', + ], + [ + 'Oops! Ты оказался на 1 уровне. Купи еще на {0}₽ и твой кешбек будет 6% с {1}!', + 'Ты вернулся на 2 уровень. Купи еще на {0}₽ и получай кешбек 10% с {1}', + 'Ты почти на последнем уровне! Купи на {0}₽ и получай максимальный кешбек 15% с {1}', + 'Ты лучший! Покупай на {0}₽ и сохраняй максимальный кешбек 15% с {1}', + ], + [ + 'Oops! Ты оказался на 1 уровне. Купи еще на {0}₽ и твой кешбек будет 6% с {1}!', + 'Ты вернулся на 2 уровень. Купи еще на {0}₽ и получай кешбек 10% с {1}', + 'Оу! Ты оказался на 3 уровне. Купи на {0}₽ и возвращай себе максимальный кешбек 15% с {1}', + 'Ты наш герой! Покупай на {0}₽ и сохраняй максимальный кешбек 15% с {1}', + ], +]; @Component({ selector: 'app-guest-card', @@ -22,11 +50,13 @@ export class GuestCardComponent implements OnInit { public cookiesService: CookiesService, private messagingService: MessagingService, private messageService: MessageService, - public authService: AuthService, - ) { } + public authService: AuthService + ) {} ngOnInit(): void { - this.phone = this.cookiesService.getItem('phone-number') || this.authService.userInfo?.phone; + this.phone = + this.cookiesService.getItem('phone-number') || + this.authService.userInfo?.phone; this.requestPermission(); } @@ -69,5 +99,24 @@ export class GuestCardComponent implements OnInit { } }, }); + }; + + getLevelDescription() { + let curLevel = 0; + let nextLevel = 0; + + if (this.authService.userInfo) { + curLevel = + this.authService.userInfo.current_level_and_cashback.current_level - 1; + nextLevel = this.authService.userInfo.next_level.next_level - 1; + } + + const template = levelDescriptionsTable[curLevel][nextLevel]; + + return format( + template, + `${this.authService.userInfo?.next_level.sum_for_next_level}`, + `${this.authService.currentPeriod[1].locale('ru').format('D MMMM')}` + ); } } diff --git a/angular/src/app/utils.ts b/angular/src/app/utils.ts index 84080be..223a836 100644 --- a/angular/src/app/utils.ts +++ b/angular/src/app/utils.ts @@ -1,4 +1,4 @@ -import { environment } from "src/environments/environment.prod"; +import { environment } from 'src/environments/environment.prod'; export enum DeviceType { ios, @@ -12,7 +12,7 @@ export function getTypeDevice(): DeviceType { } export async function pwaInstalled(): Promise { - if ("getInstalledRelatedApps" in navigator) { + if ('getInstalledRelatedApps' in navigator) { const apps = await (window.navigator as any).getInstalledRelatedApps(); for (const app of apps) { if (app.url == environment.manifestUrl) { @@ -22,3 +22,9 @@ export async function pwaInstalled(): Promise { } return false; } + +export function format(s: string, ...args: string[]) { + return s.replace(/{(\d+)}/g, function (match, number) { + return typeof args[number] != 'undefined' ? args[number] : match; + }); +}