dev #14760 Кофелайк WPA динамическое сообщение в зависимости от уровня: add description table

This commit is contained in:
nikolay 2023-07-17 11:33:26 +04:00
parent db666df676
commit 56b1249e3d
4 changed files with 63 additions and 19 deletions

View File

@ -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;

View File

@ -29,18 +29,7 @@
</div>
<div class="guest-card__user-description">
<p>
Осталось купить на сумму
<span class="price">{{
authService.error ? '--' : authService.userInfo.next_level.sum_for_next_level
}}</span>
рублей, тогда кэшбек будет
<span class="percent">{{ authService.error ? '--' : authService.userInfo.next_level.cashback}}%</span>
с
{{
authService.currentPeriod[1]
.locale("ru")
.format("D MMMM")
}}
{{getLevelDescription()}}
</p>
</div>
<ng-container *ngIf="!authService.error">

View File

@ -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')}`
);
}
}

View File

@ -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<boolean> {
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<boolean> {
}
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;
});
}