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

View File

@ -208,6 +208,18 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.broken {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
p {
max-width: 80%;
text-align: center;
}
}
} }
app-accordion { 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 { MatBottomSheet } from '@angular/material/bottom-sheet';
import { ExitComponent } from 'src/app/components/exit/exit.component'; import { ExitComponent } from 'src/app/components/exit/exit.component';
import { CookiesService } from 'src/app/services/cookies.service'; import { CookiesService } from 'src/app/services/cookies.service';
@ -115,7 +115,7 @@ export class GuestCardComponent implements OnInit {
return format( return format(
template, 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')}` `${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 { environment } from 'src/environments/environment';
import { JsonrpcService, RpcService } from './jsonrpc.service'; import { JsonrpcService, RpcService } from './jsonrpc.service';
import { MessageService } from 'primeng/api'; 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 { lvlPeriods } from 'src/app/app.constants';
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
@ -22,7 +27,10 @@ export class AuthService {
get currentLvlPeriod(): lvlPeriod { get currentLvlPeriod(): lvlPeriod {
return lvlPeriods[ 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( constructor(
@ -30,7 +38,7 @@ export class AuthService {
private wpJsonService: WpJsonService, private wpJsonService: WpJsonService,
private jsonrpc: JsonrpcService, private jsonrpc: JsonrpcService,
private messageService: MessageService, private messageService: MessageService,
private router: Router, private router: Router
) { ) {
this.getCurrentQuarterOfYear(); this.getCurrentQuarterOfYear();
} }
@ -50,31 +58,25 @@ export class AuthService {
return; return;
} }
this.error = null; this.error = null;
this.loading = true; this.loading = true;
this.wpJsonService this.wpJsonService
.getCustomerInfo( .getCustomerInfo(environment.systemId, token, environment.icardProxy)
environment.systemId,
token,
environment.icardProxy,
)
.subscribe({ .subscribe({
next: (value) => { next: (value) => {
this.loading = false;
this.userInfo = value.customer_info; this.userInfo = value.customer_info;
if (value && value.error && value.error.code === 11) { if (value && value.error && value.error.code === 11) {
this.wpJsonService.newCustomer( this.wpJsonService
environment.systemId, .newCustomer(environment.systemId, token, environment.icardProxy)
token,
environment.icardProxy,
)
.subscribe({ .subscribe({
next: () => { next: () => {
this.getUserInfo(); this.getUserInfo();
} },
}) });
} else if (value && value.error && value.error.code > 1) { } else if (value && value.error && value.error.code > 1) {
this.error = value.error; this.error = value.error;
this.messageService.clear(); this.messageService.clear();
this.messageService.add({ this.messageService.add({
severity: 'error', severity: 'error',
@ -86,10 +88,8 @@ export class AuthService {
}, },
error: (e) => { error: (e) => {
this.error = e; this.error = e;
},
complete: () => {
this.loading = false; this.loading = false;
} },
}); });
} }
@ -121,6 +121,7 @@ export class AuthService {
) )
.subscribe({ .subscribe({
next: (result) => { next: (result) => {
this.loading = false;
if (result.code !== 0) { if (result.code !== 0) {
this.messageService.clear(); this.messageService.clear();
this.messageService.add({ this.messageService.add({
@ -141,8 +142,6 @@ export class AuthService {
}, },
error: (error) => { error: (error) => {
console.error('Error: ', error); console.error('Error: ', error);
},
complete: () => {
this.loading = false; this.loading = false;
}, },
}); });
@ -161,29 +160,32 @@ export class AuthService {
) )
.subscribe({ .subscribe({
next: (result) => { next: (result) => {
this.loading = false;
if (result.code === 0) { if (result.code === 0) {
this.cookiesService.setCookie('token', result?.data?.token); this.cookiesService.setCookie('token', result?.data?.token);
this.jsonrpc.rpc( this.jsonrpc
{ .rpc(
method: 'updateAdditionalInfo', {
params: [ method: 'updateAdditionalInfo',
{ params: [
first_name: name, {
birth_day: '01.01.1999' first_name: name,
}, birth_day: '01.01.1999',
], },
}, ],
RpcService.authService, },
true RpcService.authService,
).subscribe({ true
next: () => { )
this.router.navigate(['/']); .subscribe({
this.getUserInfo(); next: () => {
}, this.router.navigate(['/']);
error: (err) => { this.getUserInfo();
console.error(err); },
}, error: (err) => {
}) console.error(err);
},
});
} else if (result.code === 230) { } else if (result.code === 230) {
this.messageService.clear(); this.messageService.clear();
this.messageService.add({ this.messageService.add({
@ -194,10 +196,8 @@ export class AuthService {
}, },
error: (error) => { error: (error) => {
console.error(error); console.error(error);
},
complete: () => {
this.loading = false; this.loading = false;
} },
}); });
} }
@ -236,7 +236,7 @@ export class AuthService {
getBalanceAmount(loyaltyPrograms: UserInfoWalletBalance[]) { getBalanceAmount(loyaltyPrograms: UserInfoWalletBalance[]) {
return (loyaltyPrograms || []).reduce((accumulator, currentValue) => { return (loyaltyPrograms || []).reduce((accumulator, currentValue) => {
if (currentValue.wallet.name !== 'Федеральная программа лояльности') { if (currentValue.wallet.name !== 'Федеральная программа лояльности') {
return accumulator return accumulator;
} }
return accumulator + currentValue.balance; return accumulator + currentValue.balance;
}, 0); }, 0);