Merge branch 'coffee-like-test' into coffee-like

This commit is contained in:
nikolay 2023-07-26 10:30:24 +04:00
commit e02a1aa916
4 changed files with 85 additions and 73 deletions

View File

@ -1,19 +1,19 @@
<app-navbar title="Карта гостя"></app-navbar>
<ng-container *ngIf="!authService.loading && authService.userInfo">
<ng-container *ngIf="!authService.loading">
<div class="guest-card">
<div class="top-info">
<div class="top-info__level">
<p id="level">Уровень {{ authService.error ? '--' : authService.userInfo.current_level_and_cashback?.current_level }}</p>
<p id="level">Уровень {{ authService.error ? '--' : authService.userInfo?.current_level_and_cashback?.current_level }}</p>
<p id="level-percent">Кэшбек {{ authService.error ? '--' : authService.currentLvlPeriod.percent }}%</p>
</div>
<ng-container *ngIf="!authService.error && authService.userInfo.walletBalances < 0">
<ng-container *ngIf="!authService.error && authService.userInfo!.walletBalances < 0">
<p class="top-info__bonus">
Отрицательный баланс бонусов, свяжитесь с техподдержкой
</p>
</ng-container>
<ng-container *ngIf="authService.error || authService.userInfo.walletBalances >= 0">
<ng-container *ngIf="authService.error || authService.userInfo!.walletBalances >= 0">
<p class="top-info__bonus">
{{ authService.error ? '--' : Math.floor(authService.userInfo.walletBalances) }}
{{ authService.error ? '--' : Math.floor(authService.userInfo!.walletBalances) }}
бонусов
</p>
</ng-container>
@ -32,40 +32,40 @@
</div>
<span>Покажи бариста</span>
</div>
<ng-container *ngIf="!authService.error">
<div class="guest-card__user-description">
<p [innerHtml]="getLevelDescription() | safeHtml"></p>
</div>
</ng-container>
<ng-container *ngIf="!authService.error">
<span id="bonuses-condition"></span>
<app-last-order
[lastOrder]="authService.userInfo?.last_purchase"
[loading]="authService.loading"
></app-last-order>
></app-last-order>
</ng-container>
<ng-container *ngIf="authService.error">
<div class="broken">
<img src="./assets/broken.jpg" alt="" />
<p>
Упс, что-то пошло не так..
Мы уже работаем над этой проблемой.
Попробуйте обновить страницу или зайти попозже.
Приносим извинения за неудобства.
</p>
</div>
</ng-container>
<ng-container *ngIf="authService.error">
<img src="./assets/broken.jpg" alt="" />
<p>
Упс, что-то пошло не так..
Мы уже работаем над этой проблемой.
Попробуйте обновить страницу или зайти попозже.
Приносим извинения за неудобства.
</p>
</ng-container>
</div>
<app-footer></app-footer>
</ng-container>
<ng-container *ngIf="!authService.loading && !authService.userInfo">
<div class="not-found">
<p>Данные недоступны, попробуйте позже</p>
</div>
</ng-container>
<ng-container *ngIf="authService.loading">
<app-footer></app-footer>
</div>
</ng-container>
<ng-container *ngIf="authService.loading">
<ng-container
*ngTemplateOutlet="spinner; context: { $implicit: 85 }"
></ng-container>
</ng-container>
<ng-template #spinner let-diameter>
<div class="center wrapper">
<mat-spinner [strokeWidth]="3" [diameter]="diameter"></mat-spinner>

View File

@ -208,6 +208,18 @@
justify-content: center;
align-items: center;
}
.broken {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
p {
max-width: 80%;
text-align: center;
}
}
}
app-accordion {

View File

@ -1,4 +1,4 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { MatBottomSheet } from '@angular/material/bottom-sheet';
import { ExitComponent } from 'src/app/components/exit/exit.component';
import { CookiesService } from 'src/app/services/cookies.service';
@ -115,7 +115,7 @@ export class GuestCardComponent implements OnInit {
return format(
template,
`${this.authService.userInfo?.next_level.sum_for_next_level}`,
`${this.authService.userInfo?.next_level.sum_for_next_level ?? '--'}`,
`${this.authService.currentPeriod[1].locale('ru').format('D MMMM')}`
);
}

View File

@ -4,7 +4,12 @@ import { WpJsonService } from './wp-json.service';
import { environment } from 'src/environments/environment';
import { JsonrpcService, RpcService } from './jsonrpc.service';
import { MessageService } from 'primeng/api';
import { UserInfo, lvlPeriod, UserInfoWalletBalance, Moment } from '../interface/data';
import {
UserInfo,
lvlPeriod,
UserInfoWalletBalance,
Moment,
} from '../interface/data';
import { lvlPeriods } from 'src/app/app.constants';
import moment from 'moment-timezone';
import { Router } from '@angular/router';
@ -22,7 +27,10 @@ export class AuthService {
get currentLvlPeriod(): lvlPeriod {
return lvlPeriods[
this.userInfo?.current_level_and_cashback ? this.userInfo?.current_level_and_cashback.current_level - 1 : 0];
this.userInfo?.current_level_and_cashback
? this.userInfo?.current_level_and_cashback.current_level - 1
: 0
];
}
constructor(
@ -30,7 +38,7 @@ export class AuthService {
private wpJsonService: WpJsonService,
private jsonrpc: JsonrpcService,
private messageService: MessageService,
private router: Router,
private router: Router
) {
this.getCurrentQuarterOfYear();
}
@ -50,31 +58,25 @@ export class AuthService {
return;
}
this.error = null;
this.error = null;
this.loading = true;
this.wpJsonService
.getCustomerInfo(
environment.systemId,
token,
environment.icardProxy,
)
.getCustomerInfo(environment.systemId, token, environment.icardProxy)
.subscribe({
next: (value) => {
this.loading = false;
this.userInfo = value.customer_info;
if (value && value.error && value.error.code === 11) {
this.wpJsonService.newCustomer(
environment.systemId,
token,
environment.icardProxy,
)
this.wpJsonService
.newCustomer(environment.systemId, token, environment.icardProxy)
.subscribe({
next: () => {
this.getUserInfo();
}
})
},
});
} else if (value && value.error && value.error.code > 1) {
this.error = value.error;
this.error = value.error;
this.messageService.clear();
this.messageService.add({
severity: 'error',
@ -86,10 +88,8 @@ export class AuthService {
},
error: (e) => {
this.error = e;
},
complete: () => {
this.loading = false;
}
},
});
}
@ -121,6 +121,7 @@ export class AuthService {
)
.subscribe({
next: (result) => {
this.loading = false;
if (result.code !== 0) {
this.messageService.clear();
this.messageService.add({
@ -141,8 +142,6 @@ export class AuthService {
},
error: (error) => {
console.error('Error: ', error);
},
complete: () => {
this.loading = false;
},
});
@ -161,29 +160,32 @@ export class AuthService {
)
.subscribe({
next: (result) => {
this.loading = false;
if (result.code === 0) {
this.cookiesService.setCookie('token', result?.data?.token);
this.jsonrpc.rpc(
{
method: 'updateAdditionalInfo',
params: [
{
first_name: name,
birth_day: '01.01.1999'
},
],
},
RpcService.authService,
true
).subscribe({
next: () => {
this.router.navigate(['/']);
this.getUserInfo();
},
error: (err) => {
console.error(err);
},
})
this.jsonrpc
.rpc(
{
method: 'updateAdditionalInfo',
params: [
{
first_name: name,
birth_day: '01.01.1999',
},
],
},
RpcService.authService,
true
)
.subscribe({
next: () => {
this.router.navigate(['/']);
this.getUserInfo();
},
error: (err) => {
console.error(err);
},
});
} else if (result.code === 230) {
this.messageService.clear();
this.messageService.add({
@ -194,10 +196,8 @@ export class AuthService {
},
error: (error) => {
console.error(error);
},
complete: () => {
this.loading = false;
}
},
});
}
@ -236,7 +236,7 @@ export class AuthService {
getBalanceAmount(loyaltyPrograms: UserInfoWalletBalance[]) {
return (loyaltyPrograms || []).reduce((accumulator, currentValue) => {
if (currentValue.wallet.name !== 'Федеральная программа лояльности') {
return accumulator
return accumulator;
}
return accumulator + currentValue.balance;
}, 0);