Skip to content

Commit

Permalink
Improve modal naming and types
Browse files Browse the repository at this point in the history
  • Loading branch information
henrist committed Jul 17, 2024
1 parent 747d1aa commit 0d15d15
Show file tree
Hide file tree
Showing 33 changed files with 214 additions and 166 deletions.
2 changes: 1 addition & 1 deletion frontend/src/admin/event/admin-event.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AdminEventComponent implements OnInit {
}

previewTicketPrint(ticketgroup: ApiTicketgroupAdmin) {
this.adminPrinterService.printSelectModal({
this.adminPrinterService.openPrinterSelectModal({
handler: (printer) =>
this.adminPrinterService.printPreviewTicket(printer, ticketgroup).pipe(
tap(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/admin/index/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AdminIndexComponent implements OnInit {
private adminPrinterService = inject(AdminPrinterService)

printText() {
this.adminPrinterService.printTextModal()
this.adminPrinterService.openPrintTextModal()
}

ngOnInit(): void {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/admin/order/admin-order-create.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ export class AdminOrderCreateComponent implements OnInit {

addTickets() {
this.adminTicketgroupService
.addTicketsModal({
.openAddTicketsModal({
eventgroupId: this.eventgroup!.id,
getOrderId: () => this.getOrCreateOrder().then((order) => order.id!),
})
.subscribe((tickets) => {
.closed.subscribe((tickets) => {
if (!tickets) return
this.getOrCreateOrder(true).then(
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ import { FormsModule } from "@angular/forms"
import { ApiEventgroupAdmin, ApiOrderAdmin } from "../../apitypes"
import { AdminOrderService } from "./admin-order.service"

export interface AdminOrderEmailComponentInput {
export interface AdminOrderEmailModalInput {
order: ApiOrderAdmin & {
eventgroup: ApiEventgroupAdmin
}
}

export interface AdminOrderEmailModalResult {
completed: true
}

@Component({
selector: "billett-admin-order-email",
selector: "billett-admin-order-email-modal",
standalone: true,
imports: [FormsModule],
templateUrl: "./admin-order-email.component.html",
templateUrl: "./admin-order-email-modal.component.html",
})
export class AdminOrderEmailComponent {
export class AdminOrderEmailModal {
constructor(
@Inject(DIALOG_DATA)
public data: AdminOrderEmailComponentInput,
public data: AdminOrderEmailModalInput,
) {}

private dialogRef = inject(DialogRef)
private dialogRef = inject(DialogRef<AdminOrderEmailModalResult>)
private adminOrderService = inject(AdminOrderService)

sending = false
Expand All @@ -41,7 +45,9 @@ export class AdminOrderEmailComponent {
.subscribe({
next: () => {
this.sending = false
this.dialogRef.close(true)
this.dialogRef.close({
completed: true,
})
},
error: (err) => {
this.sending = false
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/admin/order/admin-order-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { AdminPaymentService } from "../payment/admin-payment.service"
import { AdminPaymentgroupService } from "../paymentgroup/admin-paymentgroup.service"
import { AdminPrinterService } from "../printer/admin-printer.service"
import { AdminTicketRevokeComponentInput } from "../ticket/admin-ticket-revoke.component"
import { AdminTicketRevokeModalInput } from "../ticket/admin-ticket-revoke-modal.component"
import { AdminTicketService } from "../ticket/admin-ticket.service"
import { AdminTicketgroupService } from "../ticketgroup/admin-ticketgroup.service"
import { AdminOrderGetData, AdminOrderService } from "./admin-order.service"
Expand Down Expand Up @@ -160,12 +160,12 @@ export class AdminOrderItemComponent implements OnInit {

completeOrder() {
this.adminPaymentgroupService
.selectModal({
.openSelectModal({
eventgroupId: this.order!.eventgroup.id,
actionText: "Marker som betalt",
amount: this.totalReserved,
})
.subscribe((paymentgroup) => {
.closed.subscribe((paymentgroup) => {
if (!paymentgroup) return

this.adminOrderService
Expand Down Expand Up @@ -201,23 +201,23 @@ export class AdminOrderItemComponent implements OnInit {

addTickets() {
this.adminTicketgroupService
.addTicketsModal({
.openAddTicketsModal({
eventgroupId: this.order!.eventgroup.id,
getOrderId: async () => this.order!.id,
})
.subscribe((tickets) => {
.closed.subscribe((tickets) => {
if (!tickets) return
this.refreshOrder()
})
}

revokeTicket(ticket: AdminTicketRevokeComponentInput["ticket"]) {
revokeTicket(ticket: AdminTicketRevokeModalInput["ticket"]) {
this.adminTicketService
.revokeModal({
.openRevokeModal({
order: this.order!,
ticket,
})
.subscribe((result) => {
.closed.subscribe((result) => {
if (!result) return
this.refreshOrder()
})
Expand All @@ -229,12 +229,12 @@ export class AdminOrderItemComponent implements OnInit {
},
) {
this.adminPaymentgroupService
.selectModal({
.openSelectModal({
eventgroupId: this.order!.eventgroup.id,
actionText: "Inntekstfør",
amount: ticket.ticketgroup.price + ticket.ticketgroup.fee,
})
.subscribe((paymentgroup) => {
.closed.subscribe((paymentgroup) => {
if (!paymentgroup) return

this.adminTicketService
Expand All @@ -258,27 +258,27 @@ export class AdminOrderItemComponent implements OnInit {

newPayment() {
this.adminPaymentService
.createModal({
.openCreateModal({
order: this.order!,
})
.subscribe(() => {
.closed.subscribe(() => {
this.refreshOrder()
})
}

sendEmail() {
this.adminOrderService
.emailModal({
.openEmailModal({
order: this.order!,
})
.subscribe((sent) => {
.closed.subscribe((sent) => {
if (!sent) return
this.pageService.toast("E-post ble sendt", { class: "success" })
})
}

printTickets() {
this.adminPrinterService.printSelectModal({
this.adminPrinterService.openPrinterSelectModal({
handler: (printer) =>
this.adminPrinterService.printTickets(printer, this.validTickets).pipe(
tap(() => {
Expand All @@ -297,7 +297,7 @@ export class AdminOrderItemComponent implements OnInit {
}

printTicket(ticket: ApiTicketAdmin) {
this.adminPrinterService.printSelectModal({
this.adminPrinterService.openPrinterSelectModal({
handler: (printer) => {
console.log("print!")
return this.adminPrinterService.printTicket(printer, ticket).pipe(
Expand Down
21 changes: 11 additions & 10 deletions frontend/src/admin/order/admin-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
Paginated,
} from "../../apitypes"
import {
AdminOrderEmailComponent,
AdminOrderEmailComponentInput,
} from "./admin-order-email.component"
AdminOrderEmailModal,
AdminOrderEmailModalInput,
AdminOrderEmailModalResult,
} from "./admin-order-email-modal.component"

export type AdminOrderData = Paginated<
ApiOrderAdmin & {
Expand Down Expand Up @@ -152,12 +153,12 @@ export class AdminOrderService {
)
}

emailModal(data: AdminOrderEmailComponentInput) {
return this.dialog.open<boolean, AdminOrderEmailComponentInput>(
AdminOrderEmailComponent,
{
data,
},
).closed
openEmailModal(data: AdminOrderEmailModalInput) {
return this.dialog.open<
AdminOrderEmailModalResult,
AdminOrderEmailModalInput
>(AdminOrderEmailModal, {
data,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import { FormsModule } from "@angular/forms"
import {
ApiEventgroupAdmin,
ApiOrderAdmin,
ApiPaymentAdmin,
ApiPaymentgroupAdmin,
} from "../../apitypes"
import { AdminPaymentgroupSelectboxComponent } from "../paymentgroup/admin-paymentgroup-selectbox.component"
import { AdminPaymentService } from "./admin-payment.service"

export interface AdminPaymentCreateComponentInput {
export interface AdminPaymentCreateModalInput {
order: ApiOrderAdmin & {
eventgroup: ApiEventgroupAdmin
}
}

export type AdminPaymentCreateModalResult = ApiPaymentAdmin

@Component({
selector: "billett-admin-payment-create",
selector: "billett-admin-payment-create-modal",
standalone: true,
imports: [FormsModule, AdminPaymentgroupSelectboxComponent],
templateUrl: "./admin-payment-create.component.html",
templateUrl: "./admin-payment-create-modal.component.html",
})
export class AdminPaymentCreateComponent implements OnInit {
export class AdminPaymentCreateModal implements OnInit {
constructor(
@Inject(DIALOG_DATA)
public data: AdminPaymentCreateComponentInput,
public data: AdminPaymentCreateModalInput,
) {}

private dialogRef = inject(DialogRef)
private dialogRef = inject(DialogRef<AdminPaymentCreateModalResult>)
private adminPaymentService = inject(AdminPaymentService)

sending = false
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/admin/payment/admin-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
ApiPaymentgroupAdmin,
} from "../../apitypes"
import {
AdminPaymentCreateComponent,
AdminPaymentCreateComponentInput,
} from "./admin-payment-create.component"
AdminPaymentCreateModal,
AdminPaymentCreateModalInput,
AdminPaymentCreateModalResult,
} from "./admin-payment-create-modal.component"

@Injectable({
providedIn: "root",
Expand All @@ -31,12 +32,12 @@ export class AdminPaymentService {
})
}

createModal(data: AdminPaymentCreateComponentInput) {
openCreateModal(data: AdminPaymentCreateModalInput) {
return this.dialog.open<
ApiPaymentgroupAdmin,
AdminPaymentCreateComponentInput
>(AdminPaymentCreateComponent, {
AdminPaymentCreateModalResult,
AdminPaymentCreateModalInput
>(AdminPaymentCreateModal, {
data,
}).closed
})
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog"
import { Component, inject, Inject } from "@angular/core"
import { FormsModule } from "@angular/forms"
import { ApiPaymentgroupAdmin } from "../../apitypes"
import { PagePropertyComponent } from "../../common/page-property.component"
import { AdminPaymentgroupService } from "./admin-paymentgroup.service"

export interface AdminPaymentgroupCreateComponentInput {
export interface AdminPaymentgroupCreateModalInput {
eventgroupId: number
}

export type AdminPaymentgroupCreateModalResult = ApiPaymentgroupAdmin

@Component({
selector: "billett-admin-paymentgroup-create",
selector: "billett-admin-paymentgroup-create-modal",
standalone: true,
imports: [PagePropertyComponent, FormsModule],
templateUrl: "./admin-paymentgroup-create.component.html",
templateUrl: "./admin-paymentgroup-create-modal.component.html",
})
export class AdminPaymentgroupCreateComponent {
export class AdminPaymentgroupCreateModal {
constructor(
@Inject(DIALOG_DATA)
public data: AdminPaymentgroupCreateComponentInput,
public data: AdminPaymentgroupCreateModalInput,
) {}

private dialogRef = inject(DialogRef)
private dialogRef = inject(DialogRef<AdminPaymentgroupCreateModalResult>)
private adminPaymentgroupService = inject(AdminPaymentgroupService)

sending = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ <h1>
<h2>
Opptelling/kontroll
@if (!paymentgroup.time_end) {
<span class="pull-right btn btn-primary hidden-print" (click)="newPaymentsource()"
<span class="pull-right btn btn-primary hidden-print" (click)="openCreatePaymentsourceModal()"
>Registrer opptelling</span
>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import {
AdminPaymentgroupService,
} from "./admin-paymentgroup.service"
import {
AdminPaymentsourceCreateComponent,
AdminPaymentsourceCreateComponentInput,
} from "./admin-paymentsource-create.component"
AdminPaymentsourceCreateModal,
AdminPaymentsourceCreateModalInput,
AdminPaymentsourceCreateModalResult,
} from "./admin-paymentsource-create-modal.component"
import { AdminPaymentsourceService } from "./admin-paymentsource.service"

@Component({
Expand Down Expand Up @@ -338,17 +339,17 @@ export class AdminPaymentgroupItemComponent implements OnInit {
}
}

newPaymentsource() {
openCreatePaymentsourceModal() {
this.dialog
.open<ApiPaymentsourceAdmin, AdminPaymentsourceCreateComponentInput>(
AdminPaymentsourceCreateComponent,
{
data: {
eventgroup: this.paymentgroup!.eventgroup,
paymentgroup: this.paymentgroup!,
},
.open<
AdminPaymentsourceCreateModalResult,
AdminPaymentsourceCreateModalInput
>(AdminPaymentsourceCreateModal, {
data: {
eventgroup: this.paymentgroup!.eventgroup,
paymentgroup: this.paymentgroup!,
},
)
})
.closed.subscribe((paymentsource) => {
if (paymentsource) {
this.refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export class AdminPaymentgroupListComponent implements OnInit {

createNew() {
this.adminPaymentgroupService
.createModal(this.eventgroup!.id)
.subscribe((paymentgroup) => {
.openCreateModal({
eventgroupId: this.eventgroup!.id,
})
.closed.subscribe((paymentgroup) => {
if (paymentgroup) {
this.#loadPaymentGroups(this.eventgroup!.id)
}
Expand Down
Loading

0 comments on commit 0d15d15

Please sign in to comment.