-project ux (ux for user role)
All checks were successful
Build Docker Image / Build Docker Image (push) Successful in 6m52s
Build Docker Image / Restart Docker Compose (push) Successful in 0s

This commit is contained in:
x2Skyz
2025-11-28 19:44:32 +07:00
parent b8c6512f8a
commit 4db7ddaba2
4 changed files with 106 additions and 144 deletions

View File

@@ -1,7 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { GeneralService } from '../../services/generalservice';
import { ToastrService } from 'ngx-toastr';
@Component({
@@ -11,17 +9,17 @@ import { ToastrService } from 'ngx-toastr';
styleUrl: './main-project-add.css',
})
export class MainProjectAdd implements OnInit {
currentStep: number = 1;
// ไม่ต้องใช้ @Input() แล้ว Parent จะเข้าถึงผ่าน ViewChild
isLoading: boolean = false;
@Output() save = new EventEmitter<any>();
@Output() cancel = new EventEmitter<void>();
currentStep: number = 1;
projectForm!: FormGroup;
attachedFiles: any[] = [];
constructor(
private generalService: GeneralService,
private router: Router,
private toastr: ToastrService
) {}
constructor(private toastr: ToastrService) {}
ngOnInit(): void {
this.setupFormControl();
@@ -34,9 +32,7 @@ export class MainProjectAdd implements OnInit {
});
}
// ฟังก์ชันเปลี่ยน Step (เรียกใช้จากปุ่มเท่านั้น)
goToStep(step: number): void {
// กรณีจะไป Step 2 ต้องผ่าน Validation Step 1 ก่อน
if (step === 2 && this.currentStep === 1) {
if (this.projectForm.invalid) {
this.projectForm.markAllAsTouched();
@@ -70,9 +66,7 @@ export class MainProjectAdd implements OnInit {
this.attachedFiles.splice(index, 1);
}
get f() {
return this.projectForm.controls;
}
get f() { return this.projectForm.controls; }
formatCurrency(amount: any): string {
if (!amount) return '0.00 บาท';
@@ -82,27 +76,15 @@ export class MainProjectAdd implements OnInit {
onSubmit(): void {
if (this.projectForm.invalid) return;
this.isLoading = true;
const uri = '/api/project/create';
const request = {
const body = {
...this.projectForm.value,
files: this.attachedFiles
};
this.generalService.postRequest(uri, request).subscribe({
next: (result: any) => {
this.isLoading = false;
this.generalService.trowApi(result);
this.save.emit(body);
}
if (result.code === '200') {
this.router.navigate(['/main']);
}
},
error: (error: any) => {
this.isLoading = false;
this.generalService.trowApi(error);
}
});
onCancel(): void {
this.cancel.emit();
}
}