dev #14507 Авто подписка на уведомления для андроид WPA Кофелайк

This commit is contained in:
nikolay 2023-06-14 15:36:02 +04:00
parent 4e52e180d8
commit 0e38321526
6 changed files with 71 additions and 22 deletions

View File

@ -16,7 +16,6 @@ import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DialogService } from 'primeng/dynamicdialog';
import { BonusProgramComponent } from './pages/account/bonus-program/bonus-program.component';
import { OrdersComponent } from './pages/account/orders/orders.component';
import { OrderInfoComponent } from './components/order-info/order-info.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
@ -49,7 +48,7 @@ import {
MatBottomSheetModule,
MatBottomSheetRef,
} from '@angular/material/bottom-sheet';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { DirectivesModule } from './directives/directives.module';
@NgModule({
@ -62,7 +61,6 @@ import { DirectivesModule } from './directives/directives.module';
AccountComponent,
ExitComponent,
BonusProgramComponent,
OrdersComponent,
OrderInfoComponent,
FooterButtonsComponent,
UserDataComponent,
@ -76,7 +74,7 @@ import { DirectivesModule } from './directives/directives.module';
SocialMediaButtonsComponent,
LoginComponent,
// FocusNextInputDirective,
LoyalityProgramComponent,
LoyalityProgramComponent,
],
imports: [
BrowserModule,
@ -120,4 +118,4 @@ import { DirectivesModule } from './directives/directives.module';
],
bootstrap: [AppComponent],
})
export class AppModule {}
export class AppModule { }

View File

@ -19,7 +19,8 @@ import { NgxMatIntlTelInputComponent } from 'ngx-mat-intl-tel-input';
import { MatInputModule } from '@angular/material/input';
import { DirectivesModule } from 'src/app/directives/directives.module';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
import {MatButtonModule} from '@angular/material/button';
import { MatButtonModule } from '@angular/material/button';
import { ToastModule } from 'primeng/toast';
@NgModule({
declarations: [
@ -35,6 +36,7 @@ import {MatButtonModule} from '@angular/material/button';
LoyalityProgramComponent
],
imports: [
ToastModule,
CommonModule,
DefaultOptionRoutingModule,
MatIconModule,
@ -50,4 +52,4 @@ import {MatButtonModule} from '@angular/material/button';
],
bootstrap: [IndexComponent],
})
export class DefaultOptionModule {}
export class DefaultOptionModule { }

View File

@ -1,5 +1,5 @@
<app-navbar title="Карта гостя" (backEvent)="logout()"></app-navbar>
<p-toast position="top-center"></p-toast>
<ng-container *ngIf="!this.loyaltyProgram.purchaseData.$loading && customerInfo">
<div class="guest-card">
<div class="top-info">

View File

@ -7,10 +7,10 @@ import { CookiesService } from 'src/app/services/cookies.service';
import { WpJsonService } from 'src/app/services/wp-json.service';
import { environment } from 'src/environments/environment';
import moment from 'moment';
import { Moment, Purchase, lvlPeriod } from 'src/app/interface/data';
import { lvlPeriods } from 'src/app/app.constants';
import { Moment, Purchase } from 'src/app/interface/data';
import { LoyaltyProgramService } from 'src/app/services/loyalty-program.service';
import { MessageService } from 'primeng/api';
import { MessagingService } from 'src/app/services/messaging.service';
@Component({
selector: 'app-guest-card',
@ -30,11 +30,16 @@ export class GuestCardComponent implements OnInit {
public cookiesService: CookiesService,
private router: Router,
private wpJsonService: WpJsonService,
public loyaltyProgram: LoyaltyProgramService
public loyaltyProgram: LoyaltyProgramService,
private messagingService: MessagingService,
private messageService: MessageService,
) { }
ngOnInit(): void {
const token = this.cookiesService.getItem('token');
this.requestPermission();
this.loyaltyProgram.purchaseData.$loading = true;
this.wpJsonService
.getCustomerInfo(
@ -63,6 +68,26 @@ export class GuestCardComponent implements OnInit {
});
}
requestPermission() {
const userAgent = window.navigator.userAgent.toLowerCase();
const ios = /iphone|ipod|ipad/.test(userAgent);
if (ios) {
this.messageService.add({
severity: 'custom',
summary: `Чтобы получать уведомления, добавьте карту в Apple Wallet`,
life: 5000,
});
// var permissionData = window.safari.pushNotification.permission('web.com.example.domain');
// $scope.checkRemotePermission(permissionData);
} else {
//FIREBASE HERE
this.messagingService.requestPermission();
this.messagingService.receiveMessage();
// this.message = this.messagingService.currentMessage;
}
}
qrCodeClick() {
this.isQrCodeClicked = !this.isQrCodeClicked;
this.qrCodeSize = this.isQrCodeClicked ? 180 : 85;

View File

@ -26,15 +26,15 @@ export class MessagingService {
method: 'getAdditionalInfo',
params: []
}, RpcService.authService, true)
)).data
let tokens: string[] = []
if (typeof additionalInfo['fmc-token'] === 'string') {
tokens.push(additionalInfo['fmc-token'], token)
} else if (typeof additionalInfo['fmc-token'] === 'object') {
tokens = [...additionalInfo['fmc-token'], token]
} else {
tokens = [token]
}
)).data
let tokens: string[] = []
if (typeof additionalInfo['fmc-token'] === 'string') {
tokens.push(additionalInfo['fmc-token'], token)
} else if (typeof additionalInfo['fmc-token'] === 'object') {
tokens = [...additionalInfo['fmc-token'], token]
} else {
tokens = [token]
}
this.jsonRpcService
.rpc(
{
@ -65,7 +65,15 @@ export class MessagingService {
});
}
checkRequestPermission() {
return Notification.permission !== 'granted' ? false : true;
}
requestPermission() {
if (this.checkRequestPermission()) {
return;
}
try {
this.angularFireMessaging.requestToken.subscribe({
next: (token) => {

View File

@ -111,7 +111,7 @@ body {
}
:root {
--main-color: #00b26b;
--main-color: #7F2061;
--main-border-radius: 35px;
--background-color: #ffffff;
@ -208,5 +208,21 @@ input::-webkit-date-and-time-value {
text-align: left;
}
.p-toast-message-custom {
background-color: var(--background-color);
border: solid var(--main-color);
border-width: 0 0 0 6px;
color: var(--text-color);
.p-toast-icon-close {
color: var(--main-color);
}
}
.p-toast.p-component.p-toast-top-center {
max-width: 96vw;
}
html, body { height: 100%; }
body { margin: 0; }