fix: library account missing ready for pickup

Closes #330
This commit is contained in:
Jovan Krunić
2022-11-11 15:00:34 +00:00
committed by Rainer Killinger
parent 42b860e417
commit e504d8cf6d
12 changed files with 131 additions and 91 deletions

View File

@@ -0,0 +1,56 @@
import {Component} from '@angular/core';
import {DocumentAction, PAIADocument, PAIADocumentStatus} from '../../types';
import {LibraryAccountService} from '../library-account.service';
type Segment = 'orders' | 'reservations';
@Component({
selector: 'stapps-holds',
templateUrl: './holds-page.html',
styleUrls: ['./holds-page.scss'],
})
export class HoldsPageComponent {
paiaDocuments?: PAIADocument[];
paiaDocumentStatus = PAIADocumentStatus;
activeSegment: Segment = 'orders';
constructor(private readonly libraryAccountService: LibraryAccountService) {}
async ionViewWillEnter(): Promise<void> {
await this.fetchItems(this.activeSegment);
}
async fetchItems(segment: Segment) {
this.activeSegment = segment;
this.paiaDocuments = undefined;
const itemsStatus =
segment === 'reservations'
? [PAIADocumentStatus.Reserved]
: [PAIADocumentStatus.Ordered, PAIADocumentStatus.Provided];
try {
this.paiaDocuments = await this.libraryAccountService.getFilteredItems(
itemsStatus,
);
} catch {
await this.libraryAccountService.handleError();
this.paiaDocuments = [];
}
}
toNumber = Number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async segmentChanged(event: any) {
await this.fetchItems(event.detail.value);
}
async onDocumentAction(documentAction: DocumentAction) {
const answer = await this.libraryAccountService.handleDocumentAction(
documentAction,
);
if (answer) await this.fetchItems(this.activeSegment);
}
}