TD-707: Switch to selectTranslate (#149)

This commit is contained in:
Rinat Arsaev 2023-09-07 12:10:34 +04:00 committed by GitHub
parent 452cc3b66d
commit e637f14ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 547 additions and 572 deletions

View File

@ -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<Country[]> = 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')));

View File

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

View File

@ -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<HumanizeDurationService['getUnitLabels']>) => () =>
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<humanizeDuration.HumanizerOptions> {
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<string> {
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<UnitTranslationOptions> {
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',
),
})),
);
}
}

View File

@ -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<Claim, ClaimsSearchFilter
private transloco: TranslocoService,
) {
super();
this.errors$.subscribe(() => {
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(

View File

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

View File

@ -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<ApiKey>[] = [
{
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<ApiKey>[] = [
{
label: (r) =>
`${this.transloco.translate('apiKeys.apiKey', {}, 'payment-section')} #${r.id}`,
this.transloco
.selectTranslate('apiKeys.apiKey', {}, 'payment-section')
.pipe(map((apiKey) => `${apiKey} #${r.id}`)),
},
];

View File

@ -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<ApiKeyCreateDi
injector: Injector,
private apiKeysService: ApiKeysService,
private errorService: ErrorService,
private notificationService: NotificationService,
private log: NotifyLogService,
private fb: NonNullableFormBuilder,
private clipboard: Clipboard,
private transloco: TranslocoService,
@ -66,11 +66,11 @@ export class ApiKeyCreateDialogComponent extends DialogSuperclass<ApiKeyCreateDi
copy() {
if (this.clipboard.copy(this.accessToken)) {
this.notificationService.success(
this.log.success(
this.transloco.selectTranslate('apiKeys.copy.success', null, 'payment-section'),
);
} else {
this.notificationService.error(
this.log.error(
this.transloco.selectTranslate('apiKeys.copy.error', null, 'payment-section'),
);
}

View File

@ -15,7 +15,7 @@ export class FetchApiKeysService extends FetchSuperclass<
> {
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: [],

View File

@ -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<unknown>
constructor(
private invoiceTemplateFormService: CreateInvoiceTemplateService,
private snackBar: MatSnackBar,
private log: NotifyLogService,
private transloco: TranslocoService,
) {
super();
@ -67,15 +68,17 @@ export class CreateInvoiceTemplateComponent extends FormGroupSuperclass<unknown>
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 {

View File

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

View File

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

View File

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

View File

@ -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([]);
}),

View File

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

View File

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

View File

@ -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<string> {
@ -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$;

View File

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

View File

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

View File

@ -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<Filters>,
@ -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$

View File

@ -12,7 +12,7 @@
<dsh-resource-payer *ngIf="resourcePayer" [payer]="resourcePayer"></dsh-resource-payer>
<dsh-shop-name [shopName]="payment.shopID | shopDetails" gdColumn="1/-1"></dsh-shop-name>
<dsh-details-item *ngIf="payment.error?.code" [title]="t('error')" gdColumn="1/-1">
<div class="mat-body-1">{{ payment.error | paymentErrorMessage }}</div>
<div class="mat-body-1">{{ payment.error | paymentErrorMessage | async }}</div>
</dsh-details-item>
<dsh-additional-info
*ngIf="additionalInfo as info"

View File

@ -4,6 +4,8 @@ import { PaymentError } from '@vality/swag-payments';
import isObject from 'lodash-es/isObject';
import lowerCase from 'lodash-es/lowerCase';
import upperFirst from 'lodash-es/upperFirst';
import { Observable } from 'rxjs';
import { first, map } from 'rxjs/operators';
function renderSubErrorMessage(error?: string, sub?: string) {
if (!error) return sub;
@ -22,32 +24,41 @@ function getErrorLabel(error: PaymentError) {
export class PaymentErrorMessagePipe implements PipeTransform {
constructor(private t: TranslocoService) {}
transform(error: PaymentError): string {
transform(error: PaymentError): Observable<string> {
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() {

View File

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

View File

@ -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: [] });
}),

View File

@ -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<Filters>,
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$

View File

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

View File

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

View File

@ -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<Filters>,
@ -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();
});

View File

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

View File

@ -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) {

View File

@ -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() {

View File

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

View File

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

View File

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

View File

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

View File

@ -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: [] });
}),

View File

@ -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: [] });
}),

View File

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

View File

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

View File

@ -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<Webhook[]>([]);
}),

View File

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

View File

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

View File

@ -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',

View File

@ -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',

View File

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

View File

@ -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<string>();
constructor(
private walletService: WalletsService,
private errorService: ErrorService,
) {}
constructor(private walletService: WalletsService) {}
fetchWalletAccount(walletID: string): void {
this.fetchWalletAccount$.next(walletID);

View File

@ -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: [] });
}),

View File

@ -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<WithdrawalsFilters>,
) {}
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'),
),
);
}

View File

@ -57,7 +57,7 @@
>
<div fxLayout fxLayoutAlign="space-between" fxLayoutGap="24px">
<div *ngFor="let header of contentHeader">
{{ header.label(item) }}
{{ header.label(item) | vPossiblyAsync }}
</div>
</div>
</dsh-accordion-item-content-header>

View File

@ -29,7 +29,7 @@ export interface Column<T extends object> {
}
export interface ContentHeader<T extends object> {
label: (row: T) => unknown;
label: (row: T) => PossiblyAsync<unknown>;
}
@Component({

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@
{{ t('loading') }}
</div>
<ng-template #error>
<div class="dsh-body-1">{{ error$ | async | errorMessage }}</div>
<div class="dsh-body-1">{{ error$ | async | errorMessage | async }}</div>
</ng-template>
<ng-template #loaded>
<dsh-payout-tool-details

View File

@ -13,7 +13,7 @@ import { switchMap, tap, share, catchError } from 'rxjs/operators';
import { Overwrite } from 'utility-types';
import { PayoutsService } from '@dsh/app/api/payments';
import { CommonError, ErrorService } from '@dsh/app/shared';
import { CommonError } from '@dsh/app/shared';
import { progressTo, errorTo } from '@dsh/utils';
type BankAccountType = 'PayoutToolDetailsInternationalBankAccount' | 'PayoutToolDetailsBankAccount';
@ -47,7 +47,6 @@ export class ExistingBankAccountComponent extends FormControlSuperclass<
constructor(
private payoutsService: PayoutsService,
private transloco: TranslocoService,
private errorService: ErrorService,
) {
super();
}
@ -61,7 +60,7 @@ export class ExistingBankAccountComponent extends FormControlSuperclass<
).pipe(
progressTo(this.progress$),
errorTo(this.error$, true),
catchError((err) => (this.errorService.error(err, false), EMPTY)),
catchError((err) => (console.error(err), EMPTY)),
),
),
tap((payoutTool) => (this.payoutTool = payoutTool)),

View File

@ -15,7 +15,7 @@
{{ t('loading') }}
</div>
<ng-template #error>
<div class="dsh-body-1">{{ error$ | async | errorMessage }}</div>
<div class="dsh-body-1">{{ error$ | async | errorMessage | async }}</div>
</ng-template>
<ng-template #loaded>
<dsh-contractor-details [contractor]="contract.contractor"></dsh-contractor-details>

View File

@ -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<ExistingContractForm>(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)),

View File

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

View File

@ -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<string> {
if (!err) return of('');
if (err instanceof CommonError) return of(err.message);
return this.transloco.selectTranslate('errorMessage.errorOccurred', null, 'pipes');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<string> = this.transloco.translate(
message: string | Observable<string> = this.transloco.selectTranslate(
'notification.success',
null,
'services',
),
): MatSnackBarRef<SimpleSnackBar> {
return this.openSnackBar(message);
}
error(
message: string | Observable<string> = this.transloco.translate(
'notification.error',
null,
'services',
),
): MatSnackBarRef<SimpleSnackBar> {
return this.openSnackBar(message);
}
private openSnackBar(
message: string | Observable<string>,
config: MatSnackBarConfig<unknown> = {},
): MatSnackBarRef<SimpleSnackBar> {
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);
}
}

View File

@ -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": {

View File

@ -4,8 +4,6 @@
"httpError": "Произошла ошибка в процессе передачи / получения данных"
},
"notification": {
"error": "Что-то пошло не так",
"ok": "OK",
"success": "Успешно"
},
"sectionsLinks": {