Skip to content

Commit 85d0d9e

Browse files
committed
Cancel booking
1 parent 58e8f87 commit 85d0d9e

24 files changed

+396
-22
lines changed

ng-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test": "ng test",
99
"lint": "ng lint",
1010
"e2e": "ng e2e",
11-
"graphql": "gql-gen --schema http://localhost:3000/graphql --template graphql-codegen-apollo-angular-template --out src/app/generated/graphql.ts src/app/graphql/*.graphql"
11+
"graphql": "gql-gen --schema http://localhost:3000/graphql --template graphql-codegen-apollo-angular-template --out src/app/graphql/generated/graphql.ts src/app/graphql/*.graphql"
1212
},
1313
"private": true,
1414
"dependencies": {

ng-app/src/app/app.module.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { EventsItemComponent } from './events/events-list/events-item/events-ite
1616
import { GraphQLModule } from './graphql/graphql.module';
1717
import { CreateEventDialogComponent } from './events/create-event-dialog/create-event-dialog.component';
1818
import { EventDetailDialogComponent } from './events/events-list/event-detail-dialog/event-detail-dialog.component';
19+
import { BookingItemComponent } from './bookings/booking-item/booking-item.component';
20+
import { CancelBookingDialogComponent } from './bookings/cancel-booking-dialog/cancel-booking-dialog.component';
1921

2022
@NgModule({
2123
declarations: [
@@ -26,7 +28,9 @@ import { EventDetailDialogComponent } from './events/events-list/event-detail-di
2628
EventsListComponent,
2729
EventsItemComponent,
2830
CreateEventDialogComponent,
29-
EventDetailDialogComponent
31+
EventDetailDialogComponent,
32+
BookingItemComponent,
33+
CancelBookingDialogComponent
3034
],
3135
imports: [
3236
BrowserModule,
@@ -38,6 +42,10 @@ import { EventDetailDialogComponent } from './events/events-list/event-detail-di
3842
],
3943
providers: [AuthService, EventsService],
4044
bootstrap: [AppComponent],
41-
entryComponents: [EventDetailDialogComponent, CreateEventDialogComponent]
45+
entryComponents: [
46+
EventDetailDialogComponent,
47+
CreateEventDialogComponent,
48+
CancelBookingDialogComponent,
49+
],
4250
})
43-
export class AppModule {}
51+
export class AppModule { }

ng-app/src/app/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
22
import { Observable, BehaviorSubject } from 'rxjs';
33
import { ApolloQueryResult } from 'apollo-client';
44
import { tap, map, shareReplay } from 'rxjs/operators';
5-
import { LoginGQL, Login, CreateUserGQL } from '../generated/graphql';
65
import { Apollo } from 'apollo-angular';
6+
import { CreateUserGQL, LoginGQL, Login } from '../graphql/generated/graphql';
77

88
export const AUTH_KEY = 'AUTH_KEY';
99

ng-app/src/app/bookings/booking-item/booking-item.component.css

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<mat-card>
2+
<mat-card-header>
3+
<mat-card-title>
4+
{{ booking.event.title }}
5+
</mat-card-title>
6+
<mat-card-subtitle>
7+
Booked at {{ booking.createdAt | date: 'medium' }}
8+
</mat-card-subtitle>
9+
</mat-card-header>
10+
<mat-card-actions>
11+
<button mat-button color="primary" (click)="clickCancel.emit(booking)">
12+
Cancel
13+
</button>
14+
</mat-card-actions>
15+
</mat-card>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { BookingItemComponent } from './booking-item.component';
4+
5+
describe('BookingItemComponent', () => {
6+
let component: BookingItemComponent;
7+
let fixture: ComponentFixture<BookingItemComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ BookingItemComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(BookingItemComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2+
import { Bookings } from 'src/app/graphql/generated/graphql';
3+
4+
@Component({
5+
selector: 'app-booking-item',
6+
templateUrl: './booking-item.component.html',
7+
styleUrls: ['./booking-item.component.css']
8+
})
9+
export class BookingItemComponent implements OnInit {
10+
@Input()
11+
booking: Bookings.Bookings;
12+
13+
@Output()
14+
clickCancel = new EventEmitter<Bookings.Bookings>();
15+
16+
constructor() { }
17+
18+
ngOnInit() {
19+
}
20+
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.bookings-list {
2+
padding: 0;
3+
max-width: 90%;
4+
width: 40rem;
5+
margin: 2rem auto;
6+
}
7+
8+
.progress {
9+
display: inline-block;
10+
}
11+
12+
.progress-wrapper {
13+
margin-top: 20px;
14+
text-align: center;
15+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<p>bookings works!</p>
1+
<div *ngIf="isLoading" class="progress-wrapper">
2+
<mat-spinner [diameter]="50" [color]="'accent'" class="progress">
3+
</mat-spinner>
4+
</div>
5+
6+
<div *ngIf="bookings$ | async as bookings">
7+
<div *ngFor="let booking of bookings" class="bookings-list">
8+
<app-booking-item [booking]="booking" (clickCancel)="showCancelBookingsDialog($event)"></app-booking-item>
9+
</div>
10+
</div>
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { Bookings } from '../graphql/generated/graphql';
3+
import { BookingsService } from './bookings.service';
4+
import { Observable, BehaviorSubject } from 'rxjs';
5+
import { tap } from 'rxjs/operators';
6+
import { MatDialog } from '@angular/material';
7+
import { CancelBookingDialogComponent } from './cancel-booking-dialog/cancel-booking-dialog.component';
28

39
@Component({
410
selector: 'app-bookings',
511
templateUrl: './bookings.component.html',
612
styleUrls: ['./bookings.component.css']
713
})
814
export class BookingsComponent implements OnInit {
15+
isLoading = true;
16+
bookings$: Observable<Bookings.Bookings[]>;
917

10-
constructor() { }
18+
constructor(
19+
private readonly bookingsService: BookingsService,
20+
private readonly dialog: MatDialog,
21+
) { }
1122

1223
ngOnInit() {
24+
console.log('[BOOKINGS_COMPONENT] onInit');
25+
this.bookings$ = this.bookingsService.getAllBookings$().pipe(
26+
tap(() => this.isLoading = false)
27+
);
1328
}
1429

30+
showCancelBookingsDialog(booking: Bookings.Bookings) {
31+
console.log(booking);
32+
const dialogRef = this.dialog.open(CancelBookingDialogComponent, {
33+
width: '30rem',
34+
data: booking
35+
});
36+
37+
dialogRef.afterClosed().subscribe(result => {
38+
console.log('The dialog was closed ', result);
39+
});
40+
}
1541
}

0 commit comments

Comments
 (0)