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;
+ });
+}