diff --git a/src/app/api/payments/countries.service.ts b/src/app/api/payments/countries.service.ts index 8fe7b1e4..88df91bc 100644 --- a/src/app/api/payments/countries.service.ts +++ b/src/app/api/payments/countries.service.ts @@ -5,7 +5,6 @@ import { Observable, of } from 'rxjs'; import { catchError, map, shareReplay } from 'rxjs/operators'; import { SHARE_REPLAY_CONF } from '@dsh/app/custom-operators'; -import { ErrorService } from '@dsh/app/shared/services'; import { createApi } from '../utils'; @@ -15,16 +14,13 @@ import { createApi } from '../utils'; export class CountriesService extends createApi(ApiCountriesService) { countries$: Observable = this.getCountries().pipe( catchError((error) => { - this.errorService.error(error, false); + console.error(error); return of([]); }), shareReplay(SHARE_REPLAY_CONF), ); - constructor( - injector: Injector, - private errorService: ErrorService, - ) { + constructor(injector: Injector) { super(injector); this.getCountries = () => { return this.getCountries().pipe(map((countries) => sortBy(countries, 'id'))); diff --git a/src/app/auth/app-auth-guard.service.ts b/src/app/auth/app-auth-guard.service.ts index 060d6461..b6ca757f 100644 --- a/src/app/auth/app-auth-guard.service.ts +++ b/src/app/auth/app-auth-guard.service.ts @@ -2,8 +2,6 @@ import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router'; import { firstValueFrom } from 'rxjs'; -import { ErrorService } from '@dsh/app/shared'; - import { KeycloakAuthGuard, KeycloakService } from './keycloak'; import { RoleAccessService } from './role-access.service'; import { RoleAccessName } from './types/role-access-name'; @@ -13,7 +11,6 @@ export class AppAuthGuardService extends KeycloakAuthGuard { constructor( protected router: Router, protected keycloakAngular: KeycloakService, - private errorService: ErrorService, private roleAccessService: RoleAccessService, ) { super(router, keycloakAngular); @@ -24,7 +21,7 @@ export class AppAuthGuardService extends KeycloakAuthGuard { this.roleAccessService.isAccessAllowed(route.data.roles as RoleAccessName[]), ); if (!isAccessAllowed) { - this.errorService.error('Access is denied', false); + console.error('Access is denied'); return this.router.createUrlTree(['404']); } return isAccessAllowed; diff --git a/src/app/humanize-duration/humanize-duration.service.ts b/src/app/humanize-duration/humanize-duration.service.ts index a213c258..8d60681a 100644 --- a/src/app/humanize-duration/humanize-duration.service.ts +++ b/src/app/humanize-duration/humanize-duration.service.ts @@ -1,8 +1,10 @@ import { Injectable } from '@angular/core'; import { TranslocoService } from '@ngneat/transloco'; import * as humanizeDuration from 'humanize-duration'; +import { UnitTranslationOptions } from 'humanize-duration'; import moment from 'moment'; -import { Observable, of } from 'rxjs'; +import { Observable, of, switchMap } from 'rxjs'; +import { first, map, withLatestFrom } from 'rxjs/operators'; import { LanguageService } from '../language'; @@ -31,25 +33,15 @@ export class HumanizeDurationService { }); } - get shortEnglishHumanizer(): humanizeDuration.HumanizerOptions { - const getLocalizedUnitFn = - (unit: keyof ReturnType) => () => - this.getUnitLabels()[unit]; - return { - language: 'short', - languages: { - short: { - y: getLocalizedUnitFn('year'), - mo: getLocalizedUnitFn('month'), - w: getLocalizedUnitFn('week'), - d: getLocalizedUnitFn('day'), - h: getLocalizedUnitFn('hour'), - m: getLocalizedUnitFn('minute'), - s: getLocalizedUnitFn('second'), - ms: getLocalizedUnitFn('millisecond'), + get shortEnglishHumanizer(): Observable { + return this.getUnitLabels().pipe( + map((unitLabels) => ({ + language: 'short', + languages: { + short: unitLabels, }, - }, - }; + })), + ); } constructor( @@ -63,29 +55,29 @@ export class HumanizeDurationService { getDuration(value: Value, config: HumanizeConfig = {}): Observable { const diffMs = this.getDiffMs(value); - let duration = this.duration(diffMs, config); - if (isNaN(diffMs)) { - return null; - } else if (diffMs < HumanizeDurationService.LESS_THAN_FEW_SECONDS) { + if (isNaN(diffMs)) return null; + if (diffMs < HumanizeDurationService.LESS_THAN_FEW_SECONDS) return this.transloco.selectTranslate( 'humanizeDuration.justNow', null, 'core-components', ); - } else if (config.isShort) { - duration = this.duration(diffMs, { ...config, ...this.shortEnglishHumanizer }); - } else if (config.largest === 1) { - duration = moment.duration(diffMs).humanize(); - } - duration = duration === 'минута' ? 'минуту' : duration; - return of( - config.hasAgoEnding - ? `${duration} ${this.transloco.translate( - 'humanizeDuration.ago', - null, - 'core-components', - )}` - : duration, + return of(this.duration(diffMs, config)).pipe( + switchMap((duration) => { + if (config.isShort) + return this.shortEnglishHumanizer.pipe( + map((shortEnglishHumanizer) => + this.duration(diffMs, { ...config, ...shortEnglishHumanizer }), + ), + ); + if (config.largest === 1) return of(moment.duration(diffMs).humanize()); + return of(duration); + }), + map((duration) => (duration === 'минута' ? 'минуту' : duration)), + withLatestFrom( + this.transloco.selectTranslate('humanizeDuration.ago', null, 'core-components'), + ), + map(([duration, ago]) => (config.hasAgoEnding ? `${duration} ${ago}` : duration)), ); } @@ -107,48 +99,59 @@ export class HumanizeDurationService { return typeof value === 'number'; } - private getUnitLabels() { - return { - day: this.transloco.translate( - 'humanizeDuration.shortUnit.day', - null, - 'core-components', - ), - hour: this.transloco.translate( - 'humanizeDuration.shortUnit.hour', - null, - 'core-components', - ), - millisecond: this.transloco.translate( - 'humanizeDuration.shortUnit.millisecond', - null, - 'core-components', - ), - minute: this.transloco.translate( - 'humanizeDuration.shortUnit.minute', - null, - 'core-components', - ), - month: this.transloco.translate( - 'humanizeDuration.shortUnit.month', - null, - 'core-components', - ), - second: this.transloco.translate( - 'humanizeDuration.shortUnit.second', - null, - 'core-components', - ), - week: this.transloco.translate( - 'humanizeDuration.shortUnit.week', - null, - 'core-components', - ), - year: this.transloco.translate( - 'humanizeDuration.shortUnit.year', - null, - 'core-components', - ), - }; + private getUnitLabels(): Observable { + return this.transloco.selectTranslation('core-components').pipe( + first(), + map(() => ({ + d: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.day', + null, + 'core-components', + ), + h: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.hour', + null, + 'core-components', + ), + ms: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.millisecond', + null, + 'core-components', + ), + m: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.minute', + null, + 'core-components', + ), + mo: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.month', + null, + 'core-components', + ), + s: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.second', + null, + 'core-components', + ), + w: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.week', + null, + 'core-components', + ), + y: () => + this.transloco.translate( + 'humanizeDuration.shortUnit.year', + null, + 'core-components', + ), + })), + ); } } diff --git a/src/app/sections/claim-section/claims/services/fetch-claims/fetch-claims.service.ts b/src/app/sections/claim-section/claims/services/fetch-claims/fetch-claims.service.ts index a9ad16e2..cbdee6c9 100644 --- a/src/app/sections/claim-section/claims/services/fetch-claims/fetch-claims.service.ts +++ b/src/app/sections/claim-section/claims/services/fetch-claims/fetch-claims.service.ts @@ -3,6 +3,7 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { Claim } from '@vality/swag-claim-management'; import { Observable } from 'rxjs'; +import { withLatestFrom } from 'rxjs/operators'; import { ClaimsService } from '@dsh/app/api/claim-management'; import { mapToTimestamp } from '@dsh/app/custom-operators'; @@ -22,13 +23,16 @@ export class FetchClaimsService extends PartialFetcher { - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', - ); - return []; - }); + this.errors$ + .pipe( + withLatestFrom( + this.transloco.selectTranslate('shared.httpError', null, 'components'), + ), + ) + .subscribe(([, message]) => { + this.snackBar.open(message, 'OK'); + return []; + }); } protected fetch( diff --git a/src/app/sections/organization-section/accept-invitation/accept-invitation.component.ts b/src/app/sections/organization-section/accept-invitation/accept-invitation.component.ts index 15297dca..b17b7eed 100644 --- a/src/app/sections/organization-section/accept-invitation/accept-invitation.component.ts +++ b/src/app/sections/organization-section/accept-invitation/accept-invitation.component.ts @@ -5,7 +5,6 @@ import { BehaviorSubject, Subscription } from 'rxjs'; import { first, pluck, switchMap } from 'rxjs/operators'; import { OrgsService } from '@dsh/app/api/organizations'; -import { ErrorService } from '@dsh/app/shared'; import { inProgressTo } from '@dsh/utils'; @UntilDestroy() @@ -23,7 +22,6 @@ export class AcceptInvitationComponent { constructor( private route: ActivatedRoute, private organizationsService: OrgsService, - private errorService: ErrorService, ) {} @inProgressTo('isLoading$') @@ -39,7 +37,7 @@ export class AcceptInvitationComponent { ) .subscribe({ error: (err) => { - this.errorService.error(err, false); + console.error(err); this.hasError = true; }, }); diff --git a/src/app/sections/payment-section/integrations/api-keys/api-keys.component.ts b/src/app/sections/payment-section/integrations/api-keys/api-keys.component.ts index 6969d52e..cc7f346b 100644 --- a/src/app/sections/payment-section/integrations/api-keys/api-keys.component.ts +++ b/src/app/sections/payment-section/integrations/api-keys/api-keys.component.ts @@ -5,11 +5,16 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { DialogService } from '@vality/ng-core'; import { ApiKeyStatus } from '@vality/swag-api-keys-v2'; import { ApiKey } from '@vality/swag-api-keys-v2/lib/model/api-key'; +import { map } from 'rxjs/operators'; import { ApiKeysDictionaryService } from '@dsh/app/api/api-keys'; import { mapToTimestamp } from '@dsh/app/custom-operators'; import { QueryParamsService } from '@dsh/app/shared'; -import { ExpandedFragment, Column } from '@dsh/app/shared/components/accordion-table'; +import { + ExpandedFragment, + Column, + ContentHeader, +} from '@dsh/app/shared/components/accordion-table'; import { ApiKeyCreateDialogComponent } from './components/api-key-create-dialog/api-key-create-dialog.component'; import { FetchApiKeysService } from './fetch-api-keys.service'; @@ -34,16 +39,16 @@ export class ApiKeysComponent { ); columns: Column[] = [ { - label: this.transloco.translate('apiKeys.table.name', {}, 'payment-section'), + label: this.transloco.selectTranslate('apiKeys.table.name', {}, 'payment-section'), field: (r) => r.name, }, { - label: this.transloco.translate('apiKeys.table.createdAt', {}, 'payment-section'), + label: this.transloco.selectTranslate('apiKeys.table.createdAt', {}, 'payment-section'), field: (r) => r.createdAt, type: 'datetime', }, { - label: this.transloco.translate('apiKeys.table.status', {}, 'payment-section'), + label: this.transloco.selectTranslate('apiKeys.table.status', {}, 'payment-section'), field: (d) => d.status, type: 'tag', typeParameters: { @@ -53,10 +58,12 @@ export class ApiKeysComponent { hide: Breakpoints.Small, }, ]; - contentHeader = [ + contentHeader: ContentHeader[] = [ { label: (r) => - `${this.transloco.translate('apiKeys.apiKey', {}, 'payment-section')} #${r.id}`, + this.transloco + .selectTranslate('apiKeys.apiKey', {}, 'payment-section') + .pipe(map((apiKey) => `${apiKey} #${r.id}`)), }, ]; diff --git a/src/app/sections/payment-section/integrations/api-keys/components/api-key-create-dialog/api-key-create-dialog.component.ts b/src/app/sections/payment-section/integrations/api-keys/components/api-key-create-dialog/api-key-create-dialog.component.ts index 8ffa06ec..ee4d16ce 100644 --- a/src/app/sections/payment-section/integrations/api-keys/components/api-key-create-dialog/api-key-create-dialog.component.ts +++ b/src/app/sections/payment-section/integrations/api-keys/components/api-key-create-dialog/api-key-create-dialog.component.ts @@ -6,12 +6,12 @@ import { ReactiveFormsModule, NonNullableFormBuilder } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { TranslocoModule, TranslocoService } from '@ngneat/transloco'; import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; -import { DialogSuperclass, progressTo } from '@vality/ng-core'; +import { DialogSuperclass, progressTo, NotifyLogService } from '@vality/ng-core'; import { BehaviorSubject } from 'rxjs'; import { ApiKeysService } from '@dsh/app/api/api-keys'; import { BaseDialogModule } from '@dsh/app/shared/components/dialog/base-dialog'; -import { ErrorService, NotificationService } from '@dsh/app/shared/services'; +import { ErrorService } from '@dsh/app/shared/services'; import { ButtonModule } from '@dsh/components/buttons'; import { SpinnerModule } from '@dsh/components/indicators'; @@ -42,7 +42,7 @@ export class ApiKeyCreateDialogComponent extends DialogSuperclass { constructor( private apiKeysService: ApiKeysService, - private logService: NotifyLogService, + private log: NotifyLogService, private transloco: TranslocoService, ) { super(); @@ -37,9 +37,13 @@ export class FetchApiKeysService extends FetchSuperclass< continuationToken: res.continuationToken, })), catchError((err) => { - this.logService.error( + this.log.error( err, - this.transloco.translate('apiKeys.fetch.error', {}, 'payment-section'), + this.transloco.selectTranslate( + 'apiKeys.fetch.error', + {}, + 'payment-section', + ), ); return of({ result: [], diff --git a/src/app/sections/payment-section/integrations/payment-link/create-invoice-template/create-invoice-template.component.ts b/src/app/sections/payment-section/integrations/payment-link/create-invoice-template/create-invoice-template.component.ts index 97685d92..18e65a68 100644 --- a/src/app/sections/payment-section/integrations/payment-link/create-invoice-template/create-invoice-template.component.ts +++ b/src/app/sections/payment-section/integrations/payment-link/create-invoice-template/create-invoice-template.component.ts @@ -7,9 +7,9 @@ import { Output, } from '@angular/core'; import { UntypedFormArray } from '@angular/forms'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; -import { createControlProviders, FormGroupSuperclass } from '@vality/ng-core'; +import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { createControlProviders, FormGroupSuperclass, NotifyLogService } from '@vality/ng-core'; import { InvoiceLineTaxVAT, InvoiceTemplateAndToken, Shop } from '@vality/swag-payments'; import moment from 'moment'; @@ -17,6 +17,7 @@ import { InvoiceTemplateType, InvoiceTemplateLineCostType } from '@dsh/app/api/p import { CreateInvoiceTemplateService, WITHOUT_VAT } from './create-invoice-template.service'; +@UntilDestroy() @Component({ selector: 'dsh-create-invoice-template', templateUrl: 'create-invoice-template.component.html', @@ -59,7 +60,7 @@ export class CreateInvoiceTemplateComponent extends FormGroupSuperclass constructor( private invoiceTemplateFormService: CreateInvoiceTemplateService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) { super(); @@ -67,15 +68,17 @@ export class CreateInvoiceTemplateComponent extends FormGroupSuperclass ngOnInit(): void { super.ngOnInit(); - this.invoiceTemplateFormService.errors$.subscribe(() => - this.snackBar.open( - this.transloco.translate('shared.commonError', null, 'components'), - 'OK', - ), - ); - this.invoiceTemplateFormService.nextInvoiceTemplateAndToken$.subscribe((template) => - this.next.emit(template), - ); + this.invoiceTemplateFormService.errors$ + .pipe(untilDestroyed(this)) + .subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate('shared.commonError', null, 'components'), + ), + ); + this.invoiceTemplateFormService.nextInvoiceTemplateAndToken$ + .pipe(untilDestroyed(this)) + .subscribe((template) => this.next.emit(template)); } nextStep(): void { diff --git a/src/app/sections/payment-section/integrations/payment-link/payment-link.component.ts b/src/app/sections/payment-section/integrations/payment-link/payment-link.component.ts index 4eac2259..595fc775 100644 --- a/src/app/sections/payment-section/integrations/payment-link/payment-link.component.ts +++ b/src/app/sections/payment-section/integrations/payment-link/payment-link.component.ts @@ -1,21 +1,12 @@ import { Component } from '@angular/core'; import { FormControl } from '@angular/forms'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { PaymentMethod } from '@vality/swag-payments'; -import { - BehaviorSubject, - defer, - merge, - ReplaySubject, - Subject, - Subscription, - tap, - EMPTY, -} from 'rxjs'; -import { mapTo, shareReplay, switchMap, catchError, switchMapTo } from 'rxjs/operators'; +import { BehaviorSubject, defer, merge, ReplaySubject, Subject, Subscription, EMPTY } from 'rxjs'; +import { mapTo, shareReplay, switchMap, catchError } from 'rxjs/operators'; import { InvoicesService, InvoiceTemplatesService } from '@dsh/app/api/payments'; -import { NotificationService, ErrorService } from '@dsh/app/shared'; import { CreatePaymentLinkService } from '@dsh/app/shared/services/create-payment-link'; import { progressTo } from '@dsh/utils'; @@ -58,17 +49,15 @@ export class PaymentLinkComponent { ).pipe( progressTo(() => this.progress$), catchError((err) => { - this.errorService.error(err, false); - return this.transloco - .selectTranslate( + this.log.error( + err, + this.transloco.selectTranslate( 'paymentLink.errors.createPaymentLinkError', null, 'payment-section', - ) - .pipe( - tap((message) => this.notificationService.error(message)), - switchMapTo(EMPTY), - ); + ), + ); + return EMPTY; }), ), ), @@ -83,8 +72,7 @@ export class PaymentLinkComponent { private invoicesService: InvoicesService, private invoiceTemplatesService: InvoiceTemplatesService, private createPaymentLinkService: CreatePaymentLinkService, - private notificationService: NotificationService, - private errorService: ErrorService, + private log: NotifyLogService, private transloco: TranslocoService, ) {} diff --git a/src/app/sections/payment-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts b/src/app/sections/payment-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts index 18af48f9..aa4b443c 100644 --- a/src/app/sections/payment-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts +++ b/src/app/sections/payment-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { MatDialogRef } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { filter } from 'rxjs/operators'; import { CreateWebhookDialogService } from './create-webhook-dialog.service'; @@ -19,7 +19,7 @@ export class CreateWebhookDialogComponent implements OnInit { private dialogRef: MatDialogRef, private createWebhookDialogService: CreateWebhookDialogService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) { this.createWebhookDialogService.webhookCreated$.pipe(filter((r) => !!r)).subscribe((r) => { this.dialogRef.close(r); @@ -30,10 +30,14 @@ export class CreateWebhookDialogComponent implements OnInit { this.createWebhookDialogService.webhookCreated$.subscribe(() => this.dialogRef.close('created'), ); - this.createWebhookDialogService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate('webhook.errors.createError', null, 'payment-section'), - 'OK', + this.createWebhookDialogService.errorOccurred$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate( + 'webhook.errors.createError', + null, + 'payment-section', + ), ), ); } diff --git a/src/app/sections/payment-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts b/src/app/sections/payment-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts index 6ff0bb64..667d8187 100644 --- a/src/app/sections/payment-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts +++ b/src/app/sections/payment-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { combineLatest, Observable, of, Subject } from 'rxjs'; import { catchError, filter, switchMap, takeUntil } from 'rxjs/operators'; @@ -21,7 +21,7 @@ export class DeleteWebhookService { private dialog: MatDialog, private webhooksService: WebhooksService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} deleteWebhook(id: string) { @@ -44,14 +44,13 @@ export class DeleteWebhookService { switchMap(([webhookID]) => this.webhooksService.deleteWebhookByID({ webhookID }).pipe( catchError((e) => { - console.error(e); - this.snackBar.open( - this.transloco.translate( + this.log.error( + e, + this.transloco.selectTranslate( 'webhook.errors.deleteError', null, 'payment-section', ), - 'OK', ); return of('error'); }), diff --git a/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts b/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts index 08908922..b4d162b9 100644 --- a/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts +++ b/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Webhook } from '@vality/swag-payments'; import sortBy from 'lodash-es/sortBy'; -import { BehaviorSubject, Observable, of, Subject } from 'rxjs'; +import { BehaviorSubject, Observable, Subject, of } from 'rxjs'; import { catchError, filter, map, shareReplay, switchMap } from 'rxjs/operators'; import { WebhooksService } from '@dsh/app/api/payments'; @@ -31,7 +31,7 @@ export class ReceiveWebhooksService { constructor( private webhooksService: WebhooksService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) { this.isLoading$.subscribe(); @@ -41,10 +41,13 @@ export class ReceiveWebhooksService { switchMap(() => this.webhooksService.getWebhooksForParty().pipe( catchError((err) => { - console.error(err); - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + this.log.error( + err, + this.transloco.selectTranslate( + 'shared.httpError', + null, + 'components', + ), ); return of([]); }), diff --git a/src/app/sections/payment-section/integrations/webhooks/webhook-list/webhook-list.component.ts b/src/app/sections/payment-section/integrations/webhooks/webhook-list/webhook-list.component.ts index 76841fbf..45572693 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhook-list/webhook-list.component.ts +++ b/src/app/sections/payment-section/integrations/webhooks/webhook-list/webhook-list.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Webhook, WebhookScope } from '@vality/swag-payments'; import { DeleteWebhookService } from '../delete-webhook'; @@ -19,19 +19,19 @@ export class WebhookListComponent implements OnInit, OnDestroy { constructor( private deleteWebhookService: DeleteWebhookService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} ngOnInit() { this.deleteWebhookService.init(); this.deleteWebhookService.webhookDeleted$.subscribe(() => { - this.snackBar.open( - this.transloco.translate('webhook.actions.delete.success', null, 'payment-section'), - 'OK', - { - duration: 2000, - }, + this.log.success( + this.transloco.selectTranslate( + 'webhook.actions.delete.success', + null, + 'payment-section', + ), ); this.refreshData.emit(); }); diff --git a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts index 835292a2..0b94ffbb 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts +++ b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { CreateWebhookService } from './create-webhook'; import { ReceiveWebhooksService } from './receive-webhooks.service'; @@ -21,23 +21,19 @@ export class WebhooksComponent implements OnInit, OnDestroy { private createWebhookService: CreateWebhookService, private webhooksExpandedIdManager: WebhooksExpandedIdManager, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} ngOnInit() { this.createWebhookService.init(); this.receiveWebhooksService.receiveWebhooks(); this.createWebhookService.webhookCreated$.subscribe(() => { - this.snackBar.open( - this.transloco.translate( + this.log.success( + this.transloco.selectTranslate( 'webhook.createWebhook.successfullyCreated', null, 'payment-section', ), - 'OK', - { - duration: 2000, - }, ); this.receiveWebhooks(); }); diff --git a/src/app/sections/payment-section/operations/invoices/create-invoice/create-invoice.service.ts b/src/app/sections/payment-section/operations/invoices/create-invoice/create-invoice.service.ts index 4bb435c4..0df26e98 100644 --- a/src/app/sections/payment-section/operations/invoices/create-invoice/create-invoice.service.ts +++ b/src/app/sections/payment-section/operations/invoices/create-invoice/create-invoice.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { PaymentInstitution, Shop } from '@vality/swag-payments'; import { Observable, of, ReplaySubject } from 'rxjs'; import { filter, pluck, switchMap, take } from 'rxjs/operators'; @@ -20,7 +20,7 @@ export class CreateInvoiceService { private shopsDataService: ShopsDataService, private dialog: MatDialog, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} createInvoice(realm: RealmEnum): Observable { @@ -42,16 +42,12 @@ export class CreateInvoiceService { ) .subscribe((id) => { invoiceCreated$.next(id); - this.snackBar.open( - this.transloco.translate( + this.log.success( + this.transloco.selectTranslate( 'operations.invoices.actions.invoiceCreated', null, 'payment-section', ), - 'OK', - { - duration: 2000, - }, ); }); return invoiceCreated$; diff --git a/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/cancel-invoice/cancel-invoice.service.ts b/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/cancel-invoice/cancel-invoice.service.ts index c03f0725..bdfe754b 100644 --- a/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/cancel-invoice/cancel-invoice.service.ts +++ b/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/cancel-invoice/cancel-invoice.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Observable, ReplaySubject } from 'rxjs'; import { filter, switchMap, take } from 'rxjs/operators'; @@ -14,7 +14,7 @@ export class CancelInvoiceService { constructor( private invoicesService: InvoicesService, private dialog: MatDialog, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} @@ -34,14 +34,12 @@ export class CancelInvoiceService { ) .subscribe(() => { invoiceCancelled$.next(); - this.snackBar.open( - this.transloco.translate( + this.log.success( + this.transloco.selectTranslate( 'operations.invoices.actions.invoiceCancelled', null, 'payment-section', ), - 'OK', - { duration: 2000 }, ); }); return invoiceCancelled$; diff --git a/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/fulfill-invoice/fulfill-invoice.service.ts b/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/fulfill-invoice/fulfill-invoice.service.ts index f02a48f7..74aa229d 100644 --- a/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/fulfill-invoice/fulfill-invoice.service.ts +++ b/src/app/sections/payment-section/operations/invoices/invoices-list/invoice-details/fulfill-invoice/fulfill-invoice.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Observable, ReplaySubject } from 'rxjs'; import { filter, switchMap, take } from 'rxjs/operators'; @@ -14,7 +14,7 @@ export class FulfillInvoiceService { constructor( private invoicesService: InvoicesService, private dialog: MatDialog, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} @@ -34,14 +34,12 @@ export class FulfillInvoiceService { ) .subscribe(() => { invoiceFulfilled$.next(); - this.snackBar.open( - this.transloco.translate( + this.log.success( + this.transloco.selectTranslate( 'operations.invoices.actions.invoiceFulfilled', null, 'payment-section', ), - 'OK', - { duration: 2000 }, ); }); return invoiceFulfilled$; diff --git a/src/app/sections/payment-section/operations/invoices/invoices.component.ts b/src/app/sections/payment-section/operations/invoices/invoices.component.ts index 052074a7..90a5590d 100644 --- a/src/app/sections/payment-section/operations/invoices/invoices.component.ts +++ b/src/app/sections/payment-section/operations/invoices/invoices.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { NotifyLogService } from '@vality/ng-core'; import { take } from 'rxjs/operators'; import { QueryParamsService } from '@dsh/app/shared/services/query-params/query-params.service'; @@ -35,7 +35,7 @@ export class InvoicesComponent implements OnInit { private invoicesService: FetchInvoicesService, private createInvoiceService: CreateInvoiceService, private invoicesExpandedIdManager: InvoicesExpandedIdManager, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, private paymentInstitutionRealmService: PaymentInstitutionRealmService, private qp: QueryParamsService, @@ -45,10 +45,10 @@ export class InvoicesComponent implements OnInit { ngOnInit(): void { this.invoicesService.errors$ .pipe(untilDestroyed(this)) - .subscribe(() => - this.snackBar.open( - this.transloco.translate('shared.commonError', null, 'components'), - 'OK', + .subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate('shared.commonError', null, 'components'), ), ); this.realmMixService.mixedValue$ diff --git a/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/payment-main-info/payment-main-info.component.html b/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/payment-main-info/payment-main-info.component.html index 555cde72..a98e81b2 100644 --- a/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/payment-main-info/payment-main-info.component.html +++ b/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/payment-main-info/payment-main-info.component.html @@ -12,7 +12,7 @@ -
{{ payment.error | paymentErrorMessage }}
+
{{ payment.error | paymentErrorMessage | async }}
{ return this.formatErrors(error); } - private formatErrors(error: PaymentError): string { - let curError: PaymentError = error; - let translationPath = this.getErrorDict(); - let errorsMessage = ''; + private formatErrors(error: PaymentError) { + return this.t.selectTranslation('payment-section').pipe( + first(), + map(() => { + let curError: PaymentError = error; + let translationPath = this.getErrorDict(); + let errorsMessage = ''; - while (isObject(curError)) { - const { code, subError } = curError; - translationPath = translationPath?.[code]; + while (isObject(curError)) { + const { code, subError } = curError; + translationPath = translationPath?.[code]; - const currMessage = subError ? translationPath?.['message'] : translationPath; - const message: string = - currMessage && typeof currMessage !== 'object' - ? currMessage - : error.code === 'authorization_failed' - ? getErrorLabel(curError) - : this.t.translate('paymentErrorMessage.unknownError', null, 'payment-section'); - errorsMessage = renderSubErrorMessage(errorsMessage, message); + const currMessage = subError ? translationPath?.['message'] : translationPath; + const message: string = + currMessage && typeof currMessage !== 'object' + ? currMessage + : error.code === 'authorization_failed' + ? getErrorLabel(curError) + : this.t.translate( + 'paymentErrorMessage.unknownError', + null, + 'payment-section', + ); + errorsMessage = renderSubErrorMessage(errorsMessage, message); - curError = subError; - } + curError = subError; + } - return errorsMessage; + return errorsMessage; + }), + ); } private getErrorDict() { diff --git a/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/refunds/create-refund/components/create-refund-dialog/create-refund-dialog.component.ts b/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/refunds/create-refund/components/create-refund-dialog/create-refund-dialog.component.ts index 9308e6d0..299df9cd 100644 --- a/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/refunds/create-refund/components/create-refund-dialog/create-refund-dialog.component.ts +++ b/src/app/sections/payment-section/operations/payments/payments-panels/payments-details/refunds/create-refund/components/create-refund-dialog/create-refund-dialog.component.ts @@ -3,15 +3,13 @@ import { Component, Inject, OnInit } from '@angular/core'; import { Validators, FormBuilder } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { TranslocoService } from '@ngneat/transloco'; -import { FormGroupByValue } from '@vality/ng-core'; +import { FormGroupByValue, NotifyLogService } from '@vality/ng-core'; import { Refund, RefundParams } from '@vality/swag-payments'; import isEmpty from 'lodash-es/isEmpty'; import isNil from 'lodash-es/isNil'; import { Observable } from 'rxjs'; import { map, shareReplay, take, withLatestFrom } from 'rxjs/operators'; -import { ErrorService, NotificationService } from '@dsh/app/shared/services'; -import { CommonError } from '@dsh/app/shared/services/error/models/common-error'; import { amountValidator } from '@dsh/components/form-controls'; import { toMajor, toMinor } from '@dsh/utils'; @@ -50,8 +48,7 @@ export class CreateRefundDialogComponent implements OnInit { private fb: FormBuilder, private refundsService: RefundsService, private transloco: TranslocoService, - private notificationService: NotificationService, - private errorService: ErrorService, + private log: NotifyLogService, ) {} ngOnInit(): void { @@ -73,14 +70,14 @@ export class CreateRefundDialogComponent implements OnInit { }); return; } - this.notificationService.success( + this.log.success( refund.status === 'pending' - ? this.transloco.translate( + ? this.transloco.selectTranslate( `paymentDetails.refunds.createRefund.pending`, null, 'payment-section', ) - : this.transloco.translate( + : this.transloco.selectTranslate( `paymentDetails.refunds.createRefund.successful`, null, 'payment-section', @@ -167,24 +164,23 @@ export class CreateRefundDialogComponent implements OnInit { } private handleResponseError(err: Error): void { - let handledError: Error = err; + let message: Observable | undefined; if (err instanceof HttpErrorResponse && !isEmpty(err.error?.code)) { - handledError = new CommonError( + message = err.error.code === 'invalidRequest' - ? this.transloco.translate( + ? this.transloco.selectTranslate( `paymentDetails.refunds.errors.invalidRequest`, null, 'payment-section', ) : err.error.code === 'invoicePaymentAmountExceeded' - ? this.transloco.translate( + ? this.transloco.selectTranslate( `paymentDetails.refunds.errors.invoicePaymentAmountExceeded`, null, 'payment-section', ) - : err.error.code, - ); + : undefined; } - this.errorService.error(handledError); + this.log.error(err, message); } } diff --git a/src/app/sections/payment-section/operations/payments/services/fetch-payments/fetch-payments.service.ts b/src/app/sections/payment-section/operations/payments/services/fetch-payments/fetch-payments.service.ts index 16c9ab50..a206c1d1 100644 --- a/src/app/sections/payment-section/operations/payments/services/fetch-payments/fetch-payments.service.ts +++ b/src/app/sections/payment-section/operations/payments/services/fetch-payments/fetch-payments.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { PaymentSearchResult } from '@vality/swag-anapi-v2'; import { Observable, of } from 'rxjs'; import { catchError, shareReplay } from 'rxjs/operators'; @@ -24,7 +24,7 @@ export class FetchPaymentsService extends PartialFetcher< constructor( private searchService: SearchService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, @Inject(SEARCH_LIMIT) private searchLimit: number, @@ -48,10 +48,10 @@ export class FetchPaymentsService extends PartialFetcher< continuationToken, }) .pipe( - catchError(() => { - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.httpError', null, 'components'), ); return of({ result: [] }); }), diff --git a/src/app/sections/payment-section/operations/refunds/refunds.component.ts b/src/app/sections/payment-section/operations/refunds/refunds.component.ts index 38bb6455..998104c1 100644 --- a/src/app/sections/payment-section/operations/refunds/refunds.component.ts +++ b/src/app/sections/payment-section/operations/refunds/refunds.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { NotifyLogService } from '@vality/ng-core'; import { QueryParamsService } from '@dsh/app/shared/services/query-params'; @@ -30,7 +30,7 @@ export class RefundsComponent implements OnInit { constructor( private fetchRefundsService: FetchRefundsService, private refundsExpandedIdManager: RefundsExpandedIdManager, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, private qp: QueryParamsService, private realmShopsService: RealmShopsService, @@ -38,10 +38,14 @@ export class RefundsComponent implements OnInit { ) {} ngOnInit(): void { - this.fetchRefundsService.errors$.subscribe(() => - this.snackBar.open( - this.transloco.translate('operations.refunds.fetchError', null, 'payment-section'), - 'OK', + this.fetchRefundsService.errors$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate( + 'operations.refunds.fetchError', + null, + 'payment-section', + ), ), ); this.realmMixinService.mixedValue$ diff --git a/src/app/sections/payment-section/payouts/create-payout-report/create-payout-report-dialog.component.ts b/src/app/sections/payment-section/payouts/create-payout-report/create-payout-report-dialog.component.ts index 2a11ed6e..f05e7b9d 100644 --- a/src/app/sections/payment-section/payouts/create-payout-report/create-payout-report-dialog.component.ts +++ b/src/app/sections/payment-section/payouts/create-payout-report/create-payout-report-dialog.component.ts @@ -1,8 +1,8 @@ import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Payout } from '@vality/swag-anapi-v2'; import { CreatePayoutReportDialogService } from './create-payout-report-dialog.service'; @@ -21,19 +21,19 @@ export class CreatePayoutReportDialogComponent implements OnInit { private router: Router, private createPayoutReportDialogService: CreatePayoutReportDialogService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, @Inject(MAT_DIALOG_DATA) private data: { payout: Payout }, ) {} ngOnInit() { - this.createPayoutReportDialogService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate( + this.createPayoutReportDialogService.errorOccurred$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate( 'payouts.errors.createReportError', null, 'payment-section', ), - 'OK', ), ); } diff --git a/src/app/sections/payment-section/payouts/create-payout/create-payout-dialog.component.ts b/src/app/sections/payment-section/payouts/create-payout/create-payout-dialog.component.ts index c0d4b677..44ec4edd 100644 --- a/src/app/sections/payment-section/payouts/create-payout/create-payout-dialog.component.ts +++ b/src/app/sections/payment-section/payouts/create-payout/create-payout-dialog.component.ts @@ -1,8 +1,8 @@ import { Component, Inject, OnInit } from '@angular/core'; import { UntypedFormBuilder, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { of } from 'rxjs'; import { ShopsDataService } from '@dsh/app/shared'; @@ -39,7 +39,7 @@ export class CreatePayoutDialogComponent implements OnInit { private dialogRef: MatDialogRef, private fb: UntypedFormBuilder, private createPayoutDialogService: CreatePayoutDialogService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, private shopsDataService: ShopsDataService, @Inject(MAT_DIALOG_DATA) private data: { realm: string }, @@ -49,10 +49,14 @@ export class CreatePayoutDialogComponent implements OnInit { this.createPayoutDialogService.payoutCreated$.subscribe(() => this.dialogRef.close('created'), ); - this.createPayoutDialogService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate('payouts.errors.createError', null, 'payment-section'), - 'OK', + this.createPayoutDialogService.errorOccurred$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate( + 'payouts.errors.createError', + null, + 'payment-section', + ), ), ); } diff --git a/src/app/sections/payment-section/payouts/payouts.component.ts b/src/app/sections/payment-section/payouts/payouts.component.ts index 0ee9909b..0d03d137 100644 --- a/src/app/sections/payment-section/payouts/payouts.component.ts +++ b/src/app/sections/payment-section/payouts/payouts.component.ts @@ -1,8 +1,8 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { NotifyLogService } from '@vality/ng-core'; import { Subject } from 'rxjs'; import { filter, first, switchMap, switchMapTo } from 'rxjs/operators'; @@ -38,7 +38,7 @@ export class PayoutsComponent implements OnInit { constructor( private fetchPayoutsService: FetchPayoutsService, private payoutsExpandedIdManager: PayoutsExpandedIdManager, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, private realmService: PaymentInstitutionRealmService, private qp: QueryParamsService, @@ -50,10 +50,10 @@ export class PayoutsComponent implements OnInit { ngOnInit(): void { this.fetchPayoutsService.errors$ .pipe(untilDestroyed(this)) - .subscribe(() => - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + .subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate('shared.httpError', null, 'components'), ), ); this.realmMixService.mixedValue$ @@ -71,12 +71,12 @@ export class PayoutsComponent implements OnInit { untilDestroyed(this), ) .subscribe(() => { - this.snackBar.open( - this.transloco.translate('payouts.payouts.created', null, 'payment-section'), - 'OK', - { - duration: 2000, - }, + this.log.success( + this.transloco.selectTranslate( + 'payouts.payouts.created', + null, + 'payment-section', + ), ); this.refresh(); }); diff --git a/src/app/sections/payment-section/reports/cancel-report/cancel-report.service.ts b/src/app/sections/payment-section/reports/cancel-report/cancel-report.service.ts index dbc8cd59..e02dd20b 100644 --- a/src/app/sections/payment-section/reports/cancel-report/cancel-report.service.ts +++ b/src/app/sections/payment-section/reports/cancel-report/cancel-report.service.ts @@ -3,7 +3,7 @@ import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { combineLatest, Observable, of, Subject } from 'rxjs'; -import { catchError, filter, switchMap, takeUntil } from 'rxjs/operators'; +import { catchError, filter, switchMap, takeUntil, tap, map, first } from 'rxjs/operators'; import { ReportsService } from '@dsh/app/api/anapi'; import { ConfirmActionDialogComponent } from '@dsh/components/popups'; @@ -45,15 +45,17 @@ export class CancelReportService { this.reportsService.cancelReport({ reportID }).pipe( catchError((e) => { console.error(e); - this.snackBar.open( - this.transloco.translate( + return this.transloco + .selectTranslate( 'reports.errors.cancelError', null, 'payment-section', - ), - 'OK', - ); - return of('error'); + ) + .pipe( + first(), + tap((message) => this.snackBar.open(message, 'OK')), + map(() => 'error'), + ); }), ), ), diff --git a/src/app/sections/payment-section/reports/create-report/create-report-dialog.component.ts b/src/app/sections/payment-section/reports/create-report/create-report-dialog.component.ts index 2a3b06b1..6ce2a7d7 100644 --- a/src/app/sections/payment-section/reports/create-report/create-report-dialog.component.ts +++ b/src/app/sections/payment-section/reports/create-report/create-report-dialog.component.ts @@ -3,8 +3,10 @@ import { UntypedFormBuilder, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; import moment from 'moment'; -import { of } from 'rxjs'; +import { of, switchMap } from 'rxjs'; +import { first } from 'rxjs/operators'; import { ShopsDataService } from '@dsh/app/shared'; @@ -14,6 +16,7 @@ import { CreateReportDialogService } from './create-report-dialog.service'; const TIME_PATTERN = /^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/; +@UntilDestroy() @Component({ templateUrl: 'create-report-dialog.component.html', styleUrls: ['create-report-dialog.component.scss'], @@ -48,12 +51,16 @@ export class CreateReportDialogComponent implements OnInit { this.createReportDialogService.reportCreated$.subscribe(() => this.dialogRef.close('created'), ); - this.createReportDialogService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate('reports.errors.createError', null, 'payment-section'), - 'OK', - ), - ); + this.createReportDialogService.errorOccurred$ + .pipe( + switchMap(() => + this.transloco + .selectTranslate('reports.errors.createError', null, 'payment-section') + .pipe(first()), + ), + untilDestroyed(this), + ) + .subscribe((message) => this.snackBar.open(message, 'OK')); } create(formValue: unknown) { diff --git a/src/app/sections/payment-section/reports/report-files/report-files.component.ts b/src/app/sections/payment-section/reports/report-files/report-files.component.ts index 8d7d5826..4c074372 100644 --- a/src/app/sections/payment-section/reports/report-files/report-files.component.ts +++ b/src/app/sections/payment-section/reports/report-files/report-files.component.ts @@ -1,11 +1,13 @@ import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; import { FileMeta } from '@vality/swag-anapi-v2'; -import { Observable } from 'rxjs'; +import { Observable, combineLatest } from 'rxjs'; import { ReportFilesService } from './report-files.service'; +@UntilDestroy() @Component({ selector: 'dsh-report-files', templateUrl: 'report-files.component.html', @@ -25,19 +27,20 @@ export class ReportFilesComponent implements OnInit { ) {} ngOnInit() { - this.reportFilesService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate( - 'reports.errors.downloadReportError', - null, - 'payment-section', - ), - 'OK', - { - duration: 2000, - }, + combineLatest([ + this.transloco.selectTranslate( + 'reports.errors.downloadReportError', + null, + 'payment-section', ), - ); + this.reportFilesService.errorOccurred$, + ]) + .pipe(untilDestroyed(this)) + .subscribe(([message]) => + this.snackBar.open(message, 'OK', { + duration: 2000, + }), + ); } downloadAll() { diff --git a/src/app/sections/payment-section/reports/reports-list/reports-list.component.ts b/src/app/sections/payment-section/reports/reports-list/reports-list.component.ts index c93ca7db..dc86b8bd 100644 --- a/src/app/sections/payment-section/reports/reports-list/reports-list.component.ts +++ b/src/app/sections/payment-section/reports/reports-list/reports-list.component.ts @@ -1,10 +1,14 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; import { Report } from '@vality/swag-anapi-v2'; +import { switchMap } from 'rxjs'; +import { first } from 'rxjs/operators'; import { CancelReportService } from '../cancel-report'; +@UntilDestroy() @Component({ selector: 'dsh-reports-list', templateUrl: 'reports-list.component.html', @@ -28,20 +32,25 @@ export class ReportsListComponent implements OnInit, OnDestroy { ngOnInit() { this.cancelReportService.init(); - this.cancelReportService.reportCancelled$.subscribe(() => { - this.snackBar.open( - this.transloco.translate( - 'reports.cancelReport.successfullyCanceled', - null, - 'payment-section', + this.cancelReportService.reportCancelled$ + .pipe( + switchMap(() => + this.transloco + .selectTranslate( + 'reports.cancelReport.successfullyCanceled', + null, + 'payment-section', + ) + .pipe(first()), ), - 'OK', - { + untilDestroyed(this), + ) + .subscribe((message) => { + this.snackBar.open(message, 'OK', { duration: 2000, - }, - ); - this.refreshData.emit(); - }); + }); + this.refreshData.emit(); + }); } ngOnDestroy(): void { diff --git a/src/app/sections/payment-section/reports/reports.component.ts b/src/app/sections/payment-section/reports/reports.component.ts index ab32a039..77d1c9df 100644 --- a/src/app/sections/payment-section/reports/reports.component.ts +++ b/src/app/sections/payment-section/reports/reports.component.ts @@ -3,8 +3,8 @@ import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { Subject } from 'rxjs'; -import { filter, first, switchMap, switchMapTo } from 'rxjs/operators'; +import { Subject, combineLatest } from 'rxjs'; +import { filter, first, switchMap } from 'rxjs/operators'; import { QueryParamsService } from '@dsh/app/shared/services/query-params'; @@ -44,36 +44,35 @@ export class ReportsComponent implements OnInit { ) {} ngOnInit(): void { - this.fetchReportsService.errors$.subscribe(() => - this.snackBar.open( - this.transloco.translate('reports.errors.fetchError', null, 'payment-section'), - 'OK', - ), - ); + combineLatest([ + this.transloco.selectTranslate('reports.errors.fetchError', null, 'payment-section'), + this.fetchReportsService.errors$, + ]) + .pipe(untilDestroyed(this)) + .subscribe(([message]) => this.snackBar.open(message, 'OK')); this.realmMixinService.mixedValue$ .pipe(untilDestroyed(this)) .subscribe((v) => this.fetchReportsService.search(v)); this.createReport$ .pipe( - switchMapTo(this.realmService.realm$.pipe(first())), + switchMap(() => this.realmService.realm$.pipe(first())), switchMap((realm) => this.dialog .open(CreateReportDialogComponent, { data: { realm } }) .afterClosed() .pipe(filter((r) => r === 'created')), ), - untilDestroyed(this), - ) - .subscribe(() => { - this.snackBar.open( - this.transloco.translate( + switchMap(() => + this.transloco.selectTranslate( 'reports.createReport.successfullyCreated', null, 'payment-section', ), - 'OK', - { duration: 2000 }, - ); + ), + untilDestroyed(this), + ) + .subscribe((message) => { + this.snackBar.open(message, 'OK', { duration: 2000 }); this.refresh(); }); } diff --git a/src/app/sections/payment-section/shops/shops-list/shop-details/components/shop-id/shop-id.component.ts b/src/app/sections/payment-section/shops/shops-list/shop-details/components/shop-id/shop-id.component.ts index 37257f38..a919bc01 100644 --- a/src/app/sections/payment-section/shops/shops-list/shop-details/components/shop-id/shop-id.component.ts +++ b/src/app/sections/payment-section/shops/shops-list/shop-details/components/shop-id/shop-id.component.ts @@ -1,7 +1,6 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; import { TranslocoService } from '@ngneat/transloco'; - -import { NotificationService } from '@dsh/app/shared'; +import { NotifyLogService } from '@vality/ng-core'; @Component({ selector: 'dsh-shop-id', @@ -12,18 +11,16 @@ export class ShopIdComponent { @Input() id: string; constructor( - private notificationService: NotificationService, + private log: NotifyLogService, private transloco: TranslocoService, ) {} copied(isCopied: boolean): void { if (isCopied) - this.notificationService.success( - this.transloco.translate('shared.copied', null, 'components'), - ); + this.log.success(this.transloco.selectTranslate('shared.copied', null, 'components')); else - this.notificationService.success( - this.transloco.translate('shared.copyFailed', null, 'components'), + this.log.success( + this.transloco.selectTranslate('shared.copyFailed', null, 'components'), ); } } diff --git a/src/app/sections/payment-section/shops/shops-list/shop-details/services/shop-actions/shop-actions.service.ts b/src/app/sections/payment-section/shops/shops-list/shop-details/services/shop-actions/shop-actions.service.ts index 9ee05246..c45a2234 100644 --- a/src/app/sections/payment-section/shops/shops-list/shop-details/services/shop-actions/shop-actions.service.ts +++ b/src/app/sections/payment-section/shops/shops-list/shop-details/services/shop-actions/shop-actions.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Observable, of } from 'rxjs'; import { catchError, filter, map, switchMap } from 'rxjs/operators'; @@ -15,7 +15,7 @@ export class ShopActionsService { constructor( private shopsService: ShopsService, private dialog: MatDialog, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} @@ -27,19 +27,23 @@ export class ShopActionsService { filter((r) => r === 'confirm'), switchMap(() => this.shopsService.suspendShopForParty({ shopID })), map(() => { - this.snackBar.open( - this.transloco.translate('shops.suspend.success', null, 'payment-section'), - 'OK', - { - duration: 3000, - }, + this.log.success( + this.transloco.selectTranslate( + 'shops.suspend.success', + null, + 'payment-section', + ), ); return ShopActionResult.Success; }), - catchError(() => { - this.snackBar.open( - this.transloco.translate('shops.suspend.error', null, 'payment-section'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate( + 'shops.suspend.error', + null, + 'payment-section', + ), ); return of(ShopActionResult.Error); }), @@ -54,19 +58,23 @@ export class ShopActionsService { filter((r) => r === 'confirm'), switchMap(() => this.shopsService.activateShopForParty({ shopID })), map(() => { - this.snackBar.open( - this.transloco.translate('shops.activate.success', null, 'payment-section'), - 'OK', - { - duration: 3000, - }, + this.log.success( + this.transloco.selectTranslate( + 'shops.activate.success', + null, + 'payment-section', + ), ); return ShopActionResult.Success; }), - catchError(() => { - this.snackBar.open( - this.transloco.translate('shops.activate.error', null, 'payment-section'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate( + 'shops.activate.error', + null, + 'payment-section', + ), ); return of(ShopActionResult.Error); }), diff --git a/src/app/sections/wallet-section/deposits/deposit-panels/deposit-reverts/services/fetch-deposit-reverts.service.ts b/src/app/sections/wallet-section/deposits/deposit-panels/deposit-reverts/services/fetch-deposit-reverts.service.ts index acdc66db..da8b09ea 100644 --- a/src/app/sections/wallet-section/deposits/deposit-panels/deposit-reverts/services/fetch-deposit-reverts.service.ts +++ b/src/app/sections/wallet-section/deposits/deposit-panels/deposit-reverts/services/fetch-deposit-reverts.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { DepositRevert } from '@vality/swag-wallet'; import { ListDepositRevertsRequestParams } from '@vality/swag-wallet/lib/api/deposits.service'; import { Observable, of } from 'rxjs'; @@ -19,7 +19,7 @@ export class FetchDepositRevertsService extends PartialFetcher< constructor( private depositsService: DepositsService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, @Inject(SEARCH_LIMIT) private searchLimit: number, @@ -36,10 +36,10 @@ export class FetchDepositRevertsService extends PartialFetcher< return this.depositsService .listDepositReverts({ ...params, limit: this.searchLimit, continuationToken }) .pipe( - catchError(() => { - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.httpError', null, 'components'), ); return of({ result: [] }); }), diff --git a/src/app/sections/wallet-section/deposits/services/fetch-deposits/fetch-deposits.service.ts b/src/app/sections/wallet-section/deposits/services/fetch-deposits/fetch-deposits.service.ts index 065245fd..bde46e9f 100644 --- a/src/app/sections/wallet-section/deposits/services/fetch-deposits/fetch-deposits.service.ts +++ b/src/app/sections/wallet-section/deposits/services/fetch-deposits/fetch-deposits.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Deposit } from '@vality/swag-wallet'; import { ListDepositsRequestParams } from '@vality/swag-wallet/lib/api/deposits.service'; import { Observable, of } from 'rxjs'; @@ -22,7 +22,7 @@ export class FetchDepositsService extends PartialFetcher< constructor( private depositsService: DepositsService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, @Inject(SEARCH_LIMIT) private searchLimit: number, @@ -49,10 +49,10 @@ export class FetchDepositsService extends PartialFetcher< continuationToken, }) .pipe( - catchError(() => { - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.httpError', null, 'components'), ); return of({ result: [] }); }), diff --git a/src/app/sections/wallet-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts b/src/app/sections/wallet-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts index ba50ff08..c7b3bb2a 100644 --- a/src/app/sections/wallet-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts +++ b/src/app/sections/wallet-section/integrations/webhooks/create-webhook/create-webhook-dialog.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { MatDialogRef } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { filter } from 'rxjs/operators'; import { CreateWebhookDialogService } from './create-webhook-dialog.service'; @@ -19,7 +19,7 @@ export class CreateWebhookDialogComponent implements OnInit { private dialogRef: MatDialogRef, private createWebhookDialogService: CreateWebhookDialogService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) { this.createWebhookDialogService.webhookCreated$.pipe(filter((r) => !!r)).subscribe((r) => { this.dialogRef.close(r); @@ -30,10 +30,14 @@ export class CreateWebhookDialogComponent implements OnInit { this.createWebhookDialogService.webhookCreated$.subscribe(() => this.dialogRef.close('created'), ); - this.createWebhookDialogService.errorOccurred$.subscribe(() => - this.snackBar.open( - this.transloco.translate('reports.errors.createError', null, 'payment-section'), - 'OK', + this.createWebhookDialogService.errorOccurred$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate( + 'reports.errors.createError', + null, + 'payment-section', + ), ), ); } diff --git a/src/app/sections/wallet-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts b/src/app/sections/wallet-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts index 89ecf032..58b91e88 100644 --- a/src/app/sections/wallet-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts +++ b/src/app/sections/wallet-section/integrations/webhooks/delete-webhook/delete-webhook.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { combineLatest, Observable, of, Subject } from 'rxjs'; import { catchError, filter, switchMap, takeUntil } from 'rxjs/operators'; @@ -23,7 +23,7 @@ export class DeleteWebhookService { private dialog: MatDialog, private walletWebhooksService: WebhooksService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} deleteWebhook(params: DeleteWebhookParams) { @@ -46,14 +46,13 @@ export class DeleteWebhookService { switchMap(([{ webhookID, identityID }]) => this.walletWebhooksService.deleteWebhookByID({ webhookID, identityID }).pipe( catchError((e) => { - console.error(e); - this.snackBar.open( - this.transloco.translate( + this.log.error( + e, + this.transloco.selectTranslate( 'webhooks.errors.deleteError', null, 'wallet-section', ), - 'OK', ); return of('error'); }), diff --git a/src/app/sections/wallet-section/integrations/webhooks/receive-webhooks.service.ts b/src/app/sections/wallet-section/integrations/webhooks/receive-webhooks.service.ts index 82d0cca5..032efa17 100644 --- a/src/app/sections/wallet-section/integrations/webhooks/receive-webhooks.service.ts +++ b/src/app/sections/wallet-section/integrations/webhooks/receive-webhooks.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Webhook } from '@vality/swag-wallet'; import sortBy from 'lodash-es/sortBy'; import { BehaviorSubject, forkJoin, Observable, of, Subject } from 'rxjs'; @@ -33,7 +33,7 @@ export class ReceiveWebhooksService { constructor( private walletWebhooksService: WebhooksService, private identitiesService: IdentitiesService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) { this.receiveWebhooks$ @@ -47,10 +47,13 @@ export class ReceiveWebhooksService { ), ).pipe( catchError((err) => { - console.error(err); - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + this.log.error( + err, + this.transloco.selectTranslate( + 'shared.httpError', + null, + 'components', + ), ); return of([]); }), diff --git a/src/app/sections/wallet-section/integrations/webhooks/webhook-list/webhook-list.component.ts b/src/app/sections/wallet-section/integrations/webhooks/webhook-list/webhook-list.component.ts index 409f7a39..4c533a99 100644 --- a/src/app/sections/wallet-section/integrations/webhooks/webhook-list/webhook-list.component.ts +++ b/src/app/sections/wallet-section/integrations/webhooks/webhook-list/webhook-list.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { Webhook } from '@vality/swag-wallet'; import { DeleteWebhookService } from '../delete-webhook'; @@ -19,19 +19,19 @@ export class WebhookListComponent implements OnInit, OnDestroy { constructor( private deleteWebhookService: DeleteWebhookService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} ngOnInit() { this.deleteWebhookService.init(); this.deleteWebhookService.webhookDeleted$.subscribe(() => { - this.snackBar.open( - this.transloco.translate('webhooks.actions.webhookDeleted', null, 'wallet-section'), - 'OK', - { - duration: 2000, - }, + this.log.success( + this.transloco.selectTranslate( + 'webhooks.actions.webhookDeleted', + null, + 'wallet-section', + ), ); this.refreshData.emit(); }); diff --git a/src/app/sections/wallet-section/integrations/webhooks/webhooks.component.ts b/src/app/sections/wallet-section/integrations/webhooks/webhooks.component.ts index dae213ce..740f2b67 100644 --- a/src/app/sections/wallet-section/integrations/webhooks/webhooks.component.ts +++ b/src/app/sections/wallet-section/integrations/webhooks/webhooks.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { CreateWebhookService } from './create-webhook'; import { ReceiveWebhooksService } from './receive-webhooks.service'; @@ -21,21 +21,19 @@ export class WebhooksComponent implements OnInit, OnDestroy { private createWebhookService: CreateWebhookService, private webhooksExpandedIdManager: WebhooksExpandedIdManager, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} ngOnInit() { this.createWebhookService.init(); this.receiveWebhooksService.receiveWebhooks(); this.createWebhookService.webhookCreated$.subscribe(() => { - this.snackBar.open( - this.transloco.translate( + this.log.success( + this.transloco.selectTranslate( 'webhooks.createWebhook.successfullyCreated', null, 'wallet-section', ), - 'OK', - { duration: 2000 }, ); this.receiveWebhooks(); }); diff --git a/src/app/sections/wallet-section/reports/components/create-report-dialog/create-report-dialog.component.ts b/src/app/sections/wallet-section/reports/components/create-report-dialog/create-report-dialog.component.ts index df037314..a45b1ff4 100644 --- a/src/app/sections/wallet-section/reports/components/create-report-dialog/create-report-dialog.component.ts +++ b/src/app/sections/wallet-section/reports/components/create-report-dialog/create-report-dialog.component.ts @@ -53,7 +53,7 @@ export class CreateReportDialogComponent { .subscribe({ next: () => { this.log.success( - this.transloco.translate( + this.transloco.selectTranslate( 'reports.createReportDialog.success', {}, 'wallet-section', @@ -64,7 +64,7 @@ export class CreateReportDialogComponent { error: (err) => { this.log.error( err, - this.transloco.translate( + this.transloco.selectTranslate( 'reports.createReportDialog.error', {}, 'wallet-section', diff --git a/src/app/sections/wallet-section/reports/components/files/files.component.ts b/src/app/sections/wallet-section/reports/components/files/files.component.ts index e343c117..46872f4d 100644 --- a/src/app/sections/wallet-section/reports/components/files/files.component.ts +++ b/src/app/sections/wallet-section/reports/components/files/files.component.ts @@ -34,7 +34,7 @@ export class FilesComponent { catchError((err) => { this.log.error( err, - this.transloco.translate( + this.transloco.selectTranslate( 'reports.errors.downloadReportError', null, 'wallet-section', diff --git a/src/app/sections/wallet-section/reports/reports.component.ts b/src/app/sections/wallet-section/reports/reports.component.ts index 7bf415e3..08bbe604 100644 --- a/src/app/sections/wallet-section/reports/reports.component.ts +++ b/src/app/sections/wallet-section/reports/reports.component.ts @@ -7,7 +7,7 @@ import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; import { Report } from '@vality/swag-wallet'; import isEqual from 'lodash-es/isEqual'; import moment from 'moment'; -import { startWith, distinctUntilChanged, filter, first } from 'rxjs/operators'; +import { startWith, distinctUntilChanged, filter, first, map } from 'rxjs/operators'; import { WalletDictionaryService, IdentitiesService } from '@dsh/app/api/wallet'; import { mapToTimestamp } from '@dsh/app/custom-operators'; @@ -74,7 +74,9 @@ export class ReportsComponent implements OnInit { contentHeader = [ { label: (r) => - `${this.transloco.translate('reports.report', {}, 'wallet-section')} #${r.id}`, + this.transloco + .selectTranslate('reports.report', {}, 'wallet-section') + .pipe(map((reportText) => `${reportText} #${r.id}`)), }, ]; defaultDateRange = createDateRangeWithPreset(Preset.Last90days); diff --git a/src/app/sections/wallet-section/wallets/wallets-list/wallet-account-info/services/fetch-wallet-account/fetch-wallet-account.service.ts b/src/app/sections/wallet-section/wallets/wallets-list/wallet-account-info/services/fetch-wallet-account/fetch-wallet-account.service.ts index 79781c6e..63cb7f8e 100644 --- a/src/app/sections/wallet-section/wallets/wallets-list/wallet-account-info/services/fetch-wallet-account/fetch-wallet-account.service.ts +++ b/src/app/sections/wallet-section/wallets/wallets-list/wallet-account-info/services/fetch-wallet-account/fetch-wallet-account.service.ts @@ -6,7 +6,6 @@ import { catchError, map, switchMap } from 'rxjs/operators'; import { WalletsService } from '@dsh/app/api/wallet'; import { shareReplayUntilDestroyed } from '@dsh/app/custom-operators'; -import { ErrorService } from '@dsh/app/shared'; import { errorTo, progressTo } from '@dsh/utils'; @UntilDestroy() @@ -18,7 +17,7 @@ export class FetchWalletAccountService { progressTo(this.progress$), errorTo(this.error$, true), catchError((err) => { - this.errorService.error(err, false); + console.error(err); return EMPTY; }), ), @@ -34,10 +33,7 @@ export class FetchWalletAccountService { private fetchWalletAccount$ = new ReplaySubject(); - constructor( - private walletService: WalletsService, - private errorService: ErrorService, - ) {} + constructor(private walletService: WalletsService) {} fetchWalletAccount(walletID: string): void { this.fetchWalletAccount$.next(walletID); diff --git a/src/app/sections/wallet-section/withdrawals/services/fetch-withdrawals/fetch-withdrawals.service.ts b/src/app/sections/wallet-section/withdrawals/services/fetch-withdrawals/fetch-withdrawals.service.ts index ae36dab3..8d5debb4 100644 --- a/src/app/sections/wallet-section/withdrawals/services/fetch-withdrawals/fetch-withdrawals.service.ts +++ b/src/app/sections/wallet-section/withdrawals/services/fetch-withdrawals/fetch-withdrawals.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { InlineResponse2007, Withdrawal } from '@vality/swag-wallet'; import { ListWithdrawalsRequestParams } from '@vality/swag-wallet/lib/api/withdrawals.service'; import { Observable, of } from 'rxjs'; @@ -23,7 +23,7 @@ export class FetchWithdrawalsService extends PartialFetcher< constructor( private withdrawalsService: WithdrawalsService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, @Inject(SEARCH_LIMIT) private searchLimit: number, @@ -40,10 +40,10 @@ export class FetchWithdrawalsService extends PartialFetcher< return this.withdrawalsService .listWithdrawals({ ...params, limit: this.searchLimit, continuationToken }) .pipe( - catchError(() => { - this.snackBar.open( - this.transloco.translate('shared.httpError', null, 'components'), - 'OK', + catchError((err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.httpError', null, 'components'), ); return of({ result: [] }); }), diff --git a/src/app/sections/wallet-section/withdrawals/withdrawals.component.ts b/src/app/sections/wallet-section/withdrawals/withdrawals.component.ts index de0d3777..705aaa19 100644 --- a/src/app/sections/wallet-section/withdrawals/withdrawals.component.ts +++ b/src/app/sections/wallet-section/withdrawals/withdrawals.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { shareReplayRefCount } from '@dsh/app/custom-operators'; import { QueryParamsService } from '@dsh/app/shared/services/query-params'; @@ -23,17 +23,17 @@ export class WithdrawalsComponent implements OnInit { constructor( private fetchWithdrawalsService: FetchWithdrawalsService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, private withdrawalsExpandedIdManager: WithdrawalsExpandedIdManager, private qp: QueryParamsService, ) {} ngOnInit(): void { - this.fetchWithdrawalsService.errors$.subscribe(() => - this.snackBar.open( - this.transloco.translate('withdrawals.fetchError', null, 'wallet-section'), - 'OK', + this.fetchWithdrawalsService.errors$.subscribe((err) => + this.log.error( + err, + this.transloco.selectTranslate('withdrawals.fetchError', null, 'wallet-section'), ), ); } diff --git a/src/app/shared/components/accordion-table/accordion-table.component.html b/src/app/shared/components/accordion-table/accordion-table.component.html index e8c95b22..d0991198 100644 --- a/src/app/shared/components/accordion-table/accordion-table.component.html +++ b/src/app/shared/components/accordion-table/accordion-table.component.html @@ -57,7 +57,7 @@ >
- {{ header.label(item) }} + {{ header.label(item) | vPossiblyAsync }}
diff --git a/src/app/shared/components/accordion-table/accordion-table.component.ts b/src/app/shared/components/accordion-table/accordion-table.component.ts index daf6daec..c8d89060 100644 --- a/src/app/shared/components/accordion-table/accordion-table.component.ts +++ b/src/app/shared/components/accordion-table/accordion-table.component.ts @@ -29,7 +29,7 @@ export interface Column { } export interface ContentHeader { - label: (row: T) => unknown; + label: (row: T) => PossiblyAsync; } @Component({ diff --git a/src/app/shared/components/api-model-details/webhook-api-key/webhook-api-key.component.ts b/src/app/shared/components/api-model-details/webhook-api-key/webhook-api-key.component.ts index 0b360153..2bb7e3ee 100644 --- a/src/app/shared/components/api-model-details/webhook-api-key/webhook-api-key.component.ts +++ b/src/app/shared/components/api-model-details/webhook-api-key/webhook-api-key.component.ts @@ -1,7 +1,6 @@ import { Component, Input } from '@angular/core'; import { TranslocoService } from '@ngneat/transloco'; - -import { NotificationService } from '@dsh/app/shared'; +import { NotifyLogService } from '@vality/ng-core'; @Component({ selector: 'dsh-webhook-api-key', @@ -13,18 +12,16 @@ export class WebhookApiKeyComponent { key: string; constructor( - private notificationService: NotificationService, + private log: NotifyLogService, private transloco: TranslocoService, ) {} copied(isCopied: boolean): void { if (isCopied) - this.notificationService.success( - this.transloco.translate('shared.copied', null, 'components'), - ); + this.log.success(this.transloco.selectTranslate('shared.copied', null, 'components')); else - this.notificationService.success( - this.transloco.translate('shared.copyFailed', null, 'components'), + this.log.success( + this.transloco.selectTranslate('shared.copyFailed', null, 'components'), ); } } diff --git a/src/app/shared/components/create-payment-link-form/create-payment-link-form.component.ts b/src/app/shared/components/create-payment-link-form/create-payment-link-form.component.ts index ef94c71d..7b77e65b 100644 --- a/src/app/shared/components/create-payment-link-form/create-payment-link-form.component.ts +++ b/src/app/shared/components/create-payment-link-form/create-payment-link-form.component.ts @@ -2,12 +2,11 @@ import { Component, Input, OnChanges, ChangeDetectionStrategy } from '@angular/c import { Validators, FormGroup, FormBuilder } from '@angular/forms'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy } from '@ngneat/until-destroy'; -import { createControlProviders, FormGroupSuperclass } from '@vality/ng-core'; +import { createControlProviders, FormGroupSuperclass, NotifyLogService } from '@vality/ng-core'; import { BankCard, PaymentMethod, PaymentTerminal, DigitalWallet } from '@vality/swag-payments'; import { Observable } from 'rxjs'; import { TokenProvider, TerminalProvider } from '@dsh/app/api/payments'; -import { NotificationService } from '@dsh/app/shared'; import { PaymentLinkParams } from '@dsh/app/shared/services/create-payment-link/types/payment-link-params'; import { ComponentChanges } from '@dsh/type-utils'; @@ -50,7 +49,7 @@ export class CreatePaymentLinkFormComponent }) as FormGroup; constructor( - private notificationService: NotificationService, + private log: NotifyLogService, private transloco: TranslocoService, private fb: FormBuilder, ) { @@ -66,12 +65,10 @@ export class CreatePaymentLinkFormComponent copied(isCopied: boolean): void { if (isCopied) - this.notificationService.success( - this.transloco.translate('shared.copied', null, 'components'), - ); + this.log.success(this.transloco.selectTranslate('shared.copied', null, 'components')); else - this.notificationService.success( - this.transloco.translate('shared.copyFailed', null, 'components'), + this.log.success( + this.transloco.selectTranslate('shared.copyFailed', null, 'components'), ); } diff --git a/src/app/shared/components/shop-creation/create-international-shop-entity/create-international-shop-entity.component.ts b/src/app/shared/components/shop-creation/create-international-shop-entity/create-international-shop-entity.component.ts index 50294a9a..55e0b535 100644 --- a/src/app/shared/components/shop-creation/create-international-shop-entity/create-international-shop-entity.component.ts +++ b/src/app/shared/components/shop-creation/create-international-shop-entity/create-international-shop-entity.component.ts @@ -1,10 +1,9 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core'; import { FormControl } from '@angular/forms'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { progressTo } from '@vality/ng-core'; +import { progressTo, NotifyLogService } from '@vality/ng-core'; import { BehaviorSubject, first } from 'rxjs'; import { CreateInternationalShopEntityService } from './services/create-international-shop-entity/create-international-shop-entity.service'; @@ -27,7 +26,7 @@ export class CreateInternationalShopEntityComponent { constructor( private createShopInternationalLegalEntityService: CreateInternationalShopEntityService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private router: Router, ) {} @@ -35,19 +34,18 @@ export class CreateInternationalShopEntityComponent { this.createShopInternationalLegalEntityService .createShop(this.form.value) .pipe(progressTo(this.progress$), first(), untilDestroyed(this)) - .subscribe( - () => { + .subscribe({ + next: () => { this.send.emit(); void this.router.navigate(['claim-section', 'claims']); }, - (err) => { - console.error(err); - this.snackBar.open( - this.transloco.translate('shared.commonError', null, 'components'), - 'OK', + error: (err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.commonError', null, 'components'), ); }, - ); + }); } cancelCreation(): void { diff --git a/src/app/shared/components/shop-creation/create-russian-shop-entity/create-russian-shop-entity.component.ts b/src/app/shared/components/shop-creation/create-russian-shop-entity/create-russian-shop-entity.component.ts index b15bcb54..eedf78a7 100644 --- a/src/app/shared/components/shop-creation/create-russian-shop-entity/create-russian-shop-entity.component.ts +++ b/src/app/shared/components/shop-creation/create-russian-shop-entity/create-russian-shop-entity.component.ts @@ -1,9 +1,9 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core'; import { FormControl } from '@angular/forms'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { NotifyLogService } from '@vality/ng-core'; import { CreateRussianShopEntityService } from './services/create-russian-shop-entity/create-russian-shop-entity.service'; @@ -24,7 +24,7 @@ export class CreateRussianShopEntityComponent { constructor( private createShopRussianLegalEntityService: CreateRussianShopEntityService, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, private router: Router, ) {} @@ -36,18 +36,17 @@ export class CreateRussianShopEntityComponent { this.createShopRussianLegalEntityService .createShop(this.form.value) .pipe(untilDestroyed(this)) - .subscribe( - ({ id }) => { + .subscribe({ + next: ({ id }) => { this.send.emit(); void this.router.navigate(['claim-section', 'claims', id]); }, - (err) => { - console.error(err); - this.snackBar.open( - this.transloco.translate('shared.commonError', null, 'components'), - 'OK', + error: (err) => { + this.log.error( + err, + this.transloco.selectTranslate('shared.commonError', null, 'components'), ); }, - ); + }); } } diff --git a/src/app/shared/components/shop-creation/existing-bank-account/existing-bank-account.component.html b/src/app/shared/components/shop-creation/existing-bank-account/existing-bank-account.component.html index 7270b5a0..b209e76e 100644 --- a/src/app/shared/components/shop-creation/existing-bank-account/existing-bank-account.component.html +++ b/src/app/shared/components/shop-creation/existing-bank-account/existing-bank-account.component.html @@ -9,7 +9,7 @@ {{ t('loading') }} -
{{ error$ | async | errorMessage }}
+
{{ error$ | async | errorMessage | async }}
(this.errorService.error(err, false), EMPTY)), + catchError((err) => (console.error(err), EMPTY)), ), ), tap((payoutTool) => (this.payoutTool = payoutTool)), diff --git a/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.html b/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.html index 3f650c6e..22b64d21 100644 --- a/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.html +++ b/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.html @@ -15,7 +15,7 @@ {{ t('loading') }} -
{{ error$ | async | errorMessage }}
+
{{ error$ | async | errorMessage | async }}
diff --git a/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.ts b/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.ts index d17ff000..fd22ea74 100644 --- a/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.ts +++ b/src/app/shared/components/shop-creation/existing-contract-form/existing-contract-form.component.ts @@ -1,5 +1,4 @@ import { Component, Input } from '@angular/core'; -import { FormBuilder } from '@angular/forms'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy } from '@ngneat/until-destroy'; import { createControlProviders, FormControlSuperclass } from '@vality/ng-core'; @@ -15,7 +14,7 @@ import { switchMap, catchError, share, tap } from 'rxjs/operators'; import { Overwrite } from 'utility-types'; import { ContractsService } from '@dsh/app/api/payments'; -import { CommonError, ErrorService } from '@dsh/app/shared'; +import { CommonError } from '@dsh/app/shared'; import { progressTo, errorTo } from '@dsh/utils'; import EntityTypeEnum = LegalEntityAllOf.EntityTypeEnum; @@ -47,9 +46,7 @@ export class ExistingContractFormComponent extends FormControlSuperclass< constructor( private contractsService: ContractsService, - private fb: FormBuilder, private transloco: TranslocoService, - private errorService: ErrorService, ) { super(); } @@ -64,7 +61,7 @@ export class ExistingContractFormComponent extends FormControlSuperclass< (shop ? this.getContract(shop.contractID) : of(null)).pipe( progressTo(this.progress$), errorTo(this.error$, true), - catchError((err) => (this.errorService.error(err, false), EMPTY)), + catchError((err) => (console.error(err), EMPTY)), ), ), tap((contract) => (this.contract = contract)), diff --git a/src/app/shared/components/shop-creation/shop-creation.service.ts b/src/app/shared/components/shop-creation/shop-creation.service.ts index f2d08107..70210177 100644 --- a/src/app/shared/components/shop-creation/shop-creation.service.ts +++ b/src/app/shared/components/shop-creation/shop-creation.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; +import { NotifyLogService } from '@vality/ng-core'; import { filter } from 'rxjs/operators'; import { BaseDialogResponseStatus } from '@dsh/app/shared/components/dialog/base-dialog'; @@ -18,7 +18,7 @@ export class ShopCreationService { constructor( private dialog: MatDialog, private transloco: TranslocoService, - private snackBar: MatSnackBar, + private log: NotifyLogService, ) {} createShop(data: CreateShopDialogData = {}): void { @@ -30,9 +30,8 @@ export class ShopCreationService { .afterClosed() .pipe(filter((response) => response === BaseDialogResponseStatus.Success)) .subscribe(() => { - this.snackBar.open( - this.transloco.translate('shopCreation.created', null, 'components'), - 'OK', + this.log.success( + this.transloco.selectTranslate('shopCreation.created', null, 'components'), ); }); } diff --git a/src/app/shared/pipes/error-message/error-message.pipe.ts b/src/app/shared/pipes/error-message/error-message.pipe.ts index d6e37215..a23bda8f 100644 --- a/src/app/shared/pipes/error-message/error-message.pipe.ts +++ b/src/app/shared/pipes/error-message/error-message.pipe.ts @@ -1,15 +1,19 @@ import { Pipe, PipeTransform } from '@angular/core'; import { TranslocoService } from '@ngneat/transloco'; +import { Observable, of } from 'rxjs'; import { CommonError } from '@dsh/app/shared'; @Pipe({ name: 'errorMessage' }) +/** + * @deprecated + */ export class ErrorMessagePipe implements PipeTransform { constructor(private transloco: TranslocoService) {} - transform(err: unknown): string { - if (!err) return ''; - if (err instanceof CommonError) return err.message; - return this.transloco.translate('errorMessage.errorOccurred', null, 'pipes'); + transform(err: unknown): Observable { + if (!err) return of(''); + if (err instanceof CommonError) return of(err.message); + return this.transloco.selectTranslate('errorMessage.errorOccurred', null, 'pipes'); } } diff --git a/src/app/shared/services/error/error.service.ts b/src/app/shared/services/error/error.service.ts index b4f9d418..2cc91b3e 100644 --- a/src/app/shared/services/error/error.service.ts +++ b/src/app/shared/services/error/error.service.ts @@ -1,42 +1,26 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { TranslocoService } from '@ngneat/transloco'; -import * as Sentry from '@sentry/angular-ivy'; - -import { ErrorResult } from '@dsh/app/shared/services/error/models/error-result'; -import { extractError } from '@dsh/utils'; - -import { NotificationService } from '../notification'; - -import { CommonError } from './models/common-error'; +import { NotifyLogService } from '@vality/ng-core'; +import { Observable } from 'rxjs'; @Injectable() +/** + * @deprecated + */ export class ErrorService { constructor( - private notificationService: NotificationService, + private log: NotifyLogService, private transloco: TranslocoService, ) {} - // TODO: collect and dev log error information - error(error: unknown, notify = true): ErrorResult { - const errorResult: ErrorResult = { error: this.parse(error) }; - if (notify) { - errorResult.notification = this.notificationService.error(errorResult.error.message); - } - Sentry.captureException(extractError(error)); - return errorResult; - } - - private parse(error: unknown): CommonError { - if (error instanceof CommonError) { - return error; - } - if (error instanceof TypeError) { - return new CommonError(this.transloco.translate('error.error', null, 'services')); - } + error(error: unknown) { + let resError: Observable; if (error instanceof HttpErrorResponse) { - return new CommonError(this.transloco.translate('error.httpError', null, 'services')); + resError = this.transloco.selectTranslate('error.httpError', null, 'services'); + } else { + resError = this.transloco.selectTranslate('error.error', null, 'services'); } - return new CommonError(this.transloco.translate('error.error', null, 'services')); + this.log.error(error, resError); } } diff --git a/src/app/shared/services/error/models/common-error.ts b/src/app/shared/services/error/models/common-error.ts index b3333c6f..cae1cfc9 100644 --- a/src/app/shared/services/error/models/common-error.ts +++ b/src/app/shared/services/error/models/common-error.ts @@ -2,6 +2,9 @@ import { CustomError } from './custom-error'; const DEFAULT_ERROR_CODE = 'common_error'; +/** + * @deprecated + */ export class CommonError extends CustomError { readonly message: string; readonly code: string; diff --git a/src/app/shared/services/error/models/component-input-error.ts b/src/app/shared/services/error/models/component-input-error.ts index 5cb9bc16..74facd4f 100644 --- a/src/app/shared/services/error/models/component-input-error.ts +++ b/src/app/shared/services/error/models/component-input-error.ts @@ -2,6 +2,9 @@ import { Type } from '@angular/core'; import { CustomError } from '@dsh/app/shared/services/error/models/custom-error'; +/** + * @deprecated + */ export class ComponentInputError extends CustomError { readonly classRef: Type; diff --git a/src/app/shared/services/error/models/custom-error.ts b/src/app/shared/services/error/models/custom-error.ts index b8a6893a..454cc418 100644 --- a/src/app/shared/services/error/models/custom-error.ts +++ b/src/app/shared/services/error/models/custom-error.ts @@ -1,4 +1,7 @@ // all custom errors in application should extend this class. It's a typescript known issue +/** + * @deprecated + */ export class CustomError extends Error { constructor(message?: string) { const trueProto = new.target.prototype; diff --git a/src/app/shared/services/error/models/error-result.ts b/src/app/shared/services/error/models/error-result.ts deleted file mode 100644 index 53676524..00000000 --- a/src/app/shared/services/error/models/error-result.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; - -import { CommonError } from '@dsh/app/shared'; - -export interface ErrorResult { - error: CommonError; - notification?: MatSnackBarRef; -} diff --git a/src/app/shared/services/notification/notification.service.ts b/src/app/shared/services/notification/notification.service.ts index db2f29b5..efc16b78 100644 --- a/src/app/shared/services/notification/notification.service.ts +++ b/src/app/shared/services/notification/notification.service.ts @@ -1,57 +1,25 @@ import { Injectable } from '@angular/core'; -import { - MatSnackBar, - MatSnackBarConfig, - MatSnackBarRef, - SimpleSnackBar, -} from '@angular/material/snack-bar'; import { TranslocoService } from '@ngneat/transloco'; -import { Observable, first, isObservable, timeout } from 'rxjs'; - -const DEFAULT_DURATION_MS = 3000; +import { NotifyLogService } from '@vality/ng-core'; +import { Observable } from 'rxjs'; @Injectable() +/** + * @deprecated + */ export class NotificationService { constructor( - private snackBar: MatSnackBar, + private log: NotifyLogService, private transloco: TranslocoService, ) {} success( - message: string | Observable = this.transloco.translate( + message: string | Observable = this.transloco.selectTranslate( 'notification.success', null, 'services', ), - ): MatSnackBarRef { - return this.openSnackBar(message); - } - - error( - message: string | Observable = this.transloco.translate( - 'notification.error', - null, - 'services', - ), - ): MatSnackBarRef { - return this.openSnackBar(message); - } - - private openSnackBar( - message: string | Observable, - config: MatSnackBarConfig = {}, - ): MatSnackBarRef { - const okMessage = this.transloco.translate('notification.ok', null, 'services'); - const resConfig = { - duration: DEFAULT_DURATION_MS, - ...config, - }; - if (isObservable(message)) { - message.pipe(first(), timeout(5000)).subscribe((m) => { - this.snackBar.open(m, okMessage, resConfig); - }); - return; - } - return this.snackBar.open(message, okMessage, resConfig); + ) { + this.log.success(message); } } diff --git a/src/assets/i18n/services/en.json b/src/assets/i18n/services/en.json index a9506264..171bba11 100644 --- a/src/assets/i18n/services/en.json +++ b/src/assets/i18n/services/en.json @@ -4,8 +4,6 @@ "httpError": "An error occurred in the process of transmitting/receiving data" }, "notification": { - "error": "Something's gone wrong", - "ok": "OK", "success": "Success" }, "sectionsLinks": { diff --git a/src/assets/i18n/services/ru.json b/src/assets/i18n/services/ru.json index 2e3dfd6c..56231f8b 100644 --- a/src/assets/i18n/services/ru.json +++ b/src/assets/i18n/services/ru.json @@ -4,8 +4,6 @@ "httpError": "Произошла ошибка в процессе передачи / получения данных" }, "notification": { - "error": "Что-то пошло не так", - "ok": "OK", "success": "Успешно" }, "sectionsLinks": {