Implement appeal form flow with dynamic pages, integrate punishment selection, and add username retrieval logic. Update API schema and enhance auth.service for username handling.

This commit is contained in:
2025-08-05 23:11:38 +02:00
parent 737b26a6c7
commit ae1e972438
8 changed files with 229 additions and 40 deletions
@@ -1,10 +1,15 @@
import {AfterViewInit, Component, ElementRef, OnInit, Renderer2} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {AppealsService, MinecraftAppeal} from '@api';
import {AfterViewInit, Component, ElementRef, OnInit, Renderer2, signal} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
import {AppealsService, HistoryService, MinecraftAppeal, PunishmentHistory} from '@api';
import {HeaderComponent} from '@header/header.component';
import {NgOptimizedImage} from '@angular/common';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';
import {AuthService} from '@services/auth.service';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatSelectModule} from '@angular/material/select';
import {MatInputModule} from '@angular/material/input';
@Component({
selector: 'app-appeal',
@@ -12,7 +17,12 @@ import {MatIconModule} from '@angular/material/icon';
HeaderComponent,
NgOptimizedImage,
MatButtonModule,
MatIconModule
MatIconModule,
MatProgressSpinnerModule,
MatFormFieldModule,
MatSelectModule,
MatInputModule,
ReactiveFormsModule,
],
templateUrl: './appeal.component.html',
styleUrl: './appeal.component.scss'
@@ -22,21 +32,30 @@ export class AppealComponent implements OnInit, AfterViewInit {
public form: FormGroup<Appeal>;
private resizeObserver: ResizeObserver | null = null;
private boundHandleResize: any;
protected history = signal<PunishmentHistory[] | null>(null);
protected selectedPunishment = signal<PunishmentHistory | null>(null);
constructor(
private appealApi: AppealsService,
private historyApi: HistoryService,
protected authService: AuthService,
private elementRef: ElementRef,
private renderer: Renderer2
) {
this.form = new FormGroup({
username: new FormControl('', {nonNullable: true, validators: [Validators.required]}),
punishmentId: new FormControl('', {nonNullable: true, validators: [Validators.required]}),
email: new FormControl('', {nonNullable: true, validators: [Validators.required, Validators.email]}),
appeal: new FormControl('', {nonNullable: true, validators: [Validators.required, Validators.minLength(10)]})
});
}
ngOnInit() {
const uuid = this.authService.getUuid();
if (uuid === null) {
throw new Error('JWT subject is null, are you logged in?');
}
this.historyApi.getAllHistoryForUUID(uuid).subscribe(history => {
this.history.set(history);
})
}
ngAfterViewInit() {
@@ -116,18 +135,22 @@ export class AppealComponent implements OnInit, AfterViewInit {
private sendForm() {
const rawValue = this.form.getRawValue();
const uuid = this.authService.getUuid();
if (uuid === null) {
throw new Error('JWT subject is null, are you logged in?');
}
const appeal: MinecraftAppeal = {
appeal: rawValue.appeal,
email: rawValue.email,
punishmentId: parseInt(rawValue.punishmentId),
username: rawValue.username,
uuid: ''//TODO
punishmentId: this.selectedPunishment()!.id,
username: this.authService.username()!,
uuid: uuid
}
this.appealApi.submitMinecraftAppeal(appeal).subscribe()
}
public currentPageIndex: number = 0;
public totalPages: number[] = [0, 1, 2];
public totalPages: number[] = [0];
public goToPage(pageIndex: number): void {
if (pageIndex >= 0 && pageIndex < this.totalPages.length) {
@@ -140,6 +163,11 @@ export class AppealComponent implements OnInit, AfterViewInit {
}
public nextPage() {
if (this.currentPageIndex === this.totalPages.length - 1) {
console.log('Adding page');
this.totalPages.push(this.currentPageIndex + 1);
console.log(this.totalPages);
}
this.goToPage(this.currentPageIndex + 1);
}
@@ -150,11 +178,15 @@ export class AppealComponent implements OnInit, AfterViewInit {
public isLastPage(): boolean {
return this.currentPageIndex === this.totalPages.length - 1;
}
protected readonly length = length;
onPunishmentSelected($event: PunishmentHistory) {
this.selectedPunishment.set($event);
}
}
interface Appeal {
username: FormControl<string>;
punishmentId: FormControl<string>;
email: FormControl<string>;
appeal: FormControl<string>;
}