-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng-client): add simple ticket update modal
- Loading branch information
Showing
4 changed files
with
136 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/ng-client/src/app/tickets/update-ticket-modal/update-ticket-modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<div *ngIf="ticket$ | async as ticket; else loading"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title">Update Ticket</h4> | ||
<button type="button" class="close" aria-label="Close" (click)="cancel()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
<div class="form-row"> | ||
<div class="form-group col"> | ||
<label for="title">Title</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
name="title" | ||
[placeholder]="ticket.title" | ||
[(ngModel)]="ticketTitle" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
<div class="form-row"> | ||
<div class="form-group col"> | ||
<label for="price">Price</label> | ||
<input | ||
type="number" | ||
class="form-control" | ||
name="price" | ||
[placeholder]="ticket.price" | ||
[(ngModel)]="ticketPrice" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-primary" (click)="update()"> | ||
Update Ticket | ||
</button> | ||
<button type="button" class="btn btn-secondary" (click)="cancel()"> | ||
Cancel | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<ng-template #loading> | ||
<div>Loading Ticket...</div> | ||
</ng-template> |
62 changes: 62 additions & 0 deletions
62
apps/ng-client/src/app/tickets/update-ticket-modal/update-ticket-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ActionsSubject, Store } from '@ngrx/store'; | ||
import { UpdateTicketDto } from '@ticketing/ng/open-api'; | ||
import { Ticket } from '@ticketing/shared/models'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { | ||
RootStoreState, | ||
TicketStoreActions, | ||
TicketStoreSelectors, | ||
} from '../../store'; | ||
|
||
@Component({ | ||
selector: 'ticketing-create-ticket-modal', | ||
templateUrl: './update-ticket-modal.component.html', | ||
}) | ||
export class UpdateTicketModalComponent implements OnInit { | ||
@Input() ticketId!: string | null; | ||
|
||
ticket$!: Observable<Ticket | undefined>; | ||
|
||
ticketPrice = 0; | ||
ticketTitle = ''; | ||
|
||
constructor( | ||
private store: Store<RootStoreState.RootState>, | ||
private activeModal: NgbActiveModal, | ||
private actionsSubj: ActionsSubject, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
if (this.ticketId) { | ||
this.store.dispatch( | ||
new TicketStoreActions.LoadTicketAction({ ticketId: this.ticketId }), | ||
); | ||
this.ticket$ = this.store.select( | ||
TicketStoreSelectors.selectTicketForId(this.ticketId), | ||
); | ||
} | ||
} | ||
|
||
update(): void { | ||
const ticket: UpdateTicketDto = { | ||
price: this.ticketPrice, | ||
title: this.ticketTitle, | ||
}; | ||
if (this.ticketId) { | ||
this.store.dispatch( | ||
new TicketStoreActions.UpdateTicketAction({ | ||
ticketId: this.ticketId, | ||
ticket, | ||
}), | ||
); | ||
this.activeModal.close(); | ||
} | ||
} | ||
|
||
cancel(): void { | ||
this.activeModal.close(); | ||
} | ||
} |