Skip to content

Commit

Permalink
Fix create invoice params into dialog (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeinAsylum authored Jul 18, 2024
1 parent 906b647 commit a3486bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { FormControl } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Shop } from '@vality/swag-payments';
import pick from 'lodash-es/pick';
import moment from 'moment';

import { InvoicesService } from '@dsh/app/api/payments';

Expand All @@ -30,15 +28,9 @@ export class CreateInvoiceDialogComponent {
}

create(): void {
const { value } = this.formControl;
this.invoicesService
.createInvoice({
invoiceParams: {
...pick(value, ['product', 'description', 'amount', 'shopID']),
dueDate: moment(value.dueDate).utc().endOf('d').format(),
currency: this.shops.find((s) => s.id === value.shopID)?.currency,
metadata: {},
},
invoiceParams: this.formControl.value,
})
.pipe(untilDestroyed(this))
.subscribe(({ invoice }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ng-container *ngIf="'CreateInvoice' | isAccessAllowed">
<button
*transloco="let i; scope: 'payment-section'; read: 'paymentSection.invoices'"
[disabled]="(shops$ | async).length === 0"
color="accent"
dsh-button
(click)="create()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { NotifyLogService, QueryParamsService } from '@vality/ng-core';
import { take } from 'rxjs/operators';

import { ShopsDataService } from '@dsh/app/shared';
import { SpinnerType } from '@dsh/components/indicators';

import { RealmMixService, PaymentInstitutionRealmService } from '../../services';
import { filterShopsByRealm } from '../operators';

import { CreateInvoiceService } from './create-invoice';
import { Filters, SearchFiltersParams } from './invoices-search-filters';
Expand All @@ -29,6 +31,9 @@ export class InvoicesComponent implements OnInit {
spinnerType = SpinnerType.FulfillingBouncingCircle;
realm$ = this.paymentInstitutionRealmService.realm$;
params$ = this.qp.params$;
shops$ = this.paymentInstitutionRealmService.realm$.pipe(
filterShopsByRealm(this.shopsDataService.shops$),
);

constructor(
private invoicesService: FetchInvoicesService,
Expand All @@ -39,6 +44,7 @@ export class InvoicesComponent implements OnInit {
private paymentInstitutionRealmService: PaymentInstitutionRealmService,
private qp: QueryParamsService<Filters>,
private realmMixService: RealmMixService<SearchFiltersParams>,
private shopsDataService: ShopsDataService,
) {}

ngOnInit(): void {
Expand Down

0 comments on commit a3486bf

Please sign in to comment.