import { ChangeDetectorRef, Component } from '@angular/core'; import { ConfirmationService, MessageService } from 'primeng/api'; import { ListingType } from '../../../../../../bizmatch-server/src/models/main.model'; import { ListingsService } from '../../../services/listings.service'; import { SelectOptionsService } from '../../../services/select-options.service'; import { UserService } from '../../../services/user.service'; import { SharedModule } from '../../../shared/shared/shared.module'; import { getListingType, isBusinessListing, isCommercialPropertyListing } from '../../../utils/utils'; import { MenuAccountComponent } from '../../menu-account/menu-account.component'; @Component({ selector: 'app-my-listing', standalone: true, imports: [MenuAccountComponent, SharedModule], providers: [ConfirmationService, MessageService], templateUrl: './my-listing.component.html', styleUrl: './my-listing.component.scss', }) export class MyListingComponent { listings: Array = []; //dataListings as unknown as Array; myListings: Array; userId: string; isBusinessListing = isBusinessListing; isCommercialPropertyListing = isCommercialPropertyListing; constructor( public userService: UserService, private listingsService: ListingsService, private cdRef: ChangeDetectorRef, public selectOptions: SelectOptionsService, private confirmationService: ConfirmationService, private messageService: MessageService, ) {} async ngOnInit() { this.userId = await this.userService.getId(); this.myListings = await this.listingsService.getListingByUserId(this.userId); } async deleteListing(listing: ListingType) { await this.listingsService.deleteListing(listing.id, getListingType(listing)); this.myListings = await this.listingsService.getListingByUserId(this.userId); } confirm(event: Event, listing: ListingType) { this.confirmationService.confirm({ target: event.target as EventTarget, message: 'Are you sure you want to delet this listing?', icon: 'pi pi-exclamation-triangle', accept: () => { this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Listing has been deleted', life: 3000 }); this.deleteListing(listing); }, }); } }