2025-04-26 18:58:47 +00:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
|
|
|
|
import {FormsComponent} from '../forms.component';
|
2025-05-03 02:37:47 +00:00
|
|
|
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
2025-07-04 17:50:21 +00:00
|
|
|
import {AppealsService, MinecraftAppeal} from '@api';
|
2025-04-26 18:58:47 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-appeal',
|
|
|
|
|
imports: [
|
|
|
|
|
FormsComponent
|
|
|
|
|
],
|
|
|
|
|
templateUrl: './appeal.component.html',
|
|
|
|
|
styleUrl: './appeal.component.scss'
|
|
|
|
|
})
|
|
|
|
|
export class AppealComponent implements OnInit {
|
|
|
|
|
|
2025-05-03 02:37:47 +00:00
|
|
|
public form: FormGroup<Appeal>;
|
2025-04-26 18:58:47 +00:00
|
|
|
|
2025-05-03 02:37:47 +00:00
|
|
|
constructor(private appealApi: AppealsService) {
|
|
|
|
|
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)]})
|
|
|
|
|
});
|
2025-04-26 18:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onSubmit() {
|
|
|
|
|
if (this.form === undefined) {
|
|
|
|
|
console.error('Form is undefined');
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.form.valid) {
|
2025-05-03 02:37:47 +00:00
|
|
|
this.sendForm()
|
2025-04-26 18:58:47 +00:00
|
|
|
} else {
|
|
|
|
|
// Mark all fields as touched to trigger validation display
|
|
|
|
|
Object.keys(this.form.controls).forEach(field => {
|
|
|
|
|
const control = this.form!.get(field);
|
|
|
|
|
if (!(control instanceof FormGroup)) {
|
|
|
|
|
console.error('Control [' + control + '] is not a FormGroup');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
control.markAsTouched({onlySelf: true});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-03 02:37:47 +00:00
|
|
|
private sendForm() {
|
|
|
|
|
const rawValue = this.form.getRawValue();
|
|
|
|
|
const appeal: MinecraftAppeal = {
|
|
|
|
|
appeal: rawValue.appeal,
|
|
|
|
|
email: rawValue.email,
|
|
|
|
|
punishmentId: parseInt(rawValue.punishmentId),
|
|
|
|
|
username: rawValue.username,
|
|
|
|
|
uuid: ''//TODO
|
|
|
|
|
}
|
|
|
|
|
this.appealApi.submitMinecraftAppeal(appeal).subscribe()
|
2025-04-26 18:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-03 02:37:47 +00:00
|
|
|
}
|
2025-04-26 18:58:47 +00:00
|
|
|
|
2025-05-03 02:37:47 +00:00
|
|
|
interface Appeal {
|
|
|
|
|
username: FormControl<string>;
|
|
|
|
|
punishmentId: FormControl<string>;
|
|
|
|
|
email: FormControl<string>;
|
|
|
|
|
appeal: FormControl<string>;
|
2025-04-26 18:58:47 +00:00
|
|
|
}
|