|
@@ -1,75 +0,0 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
|
|
-import { CommonModule } from '@angular/common';
|
|
|
|
|
-import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
|
|
|
-import { Router, RouterModule } from '@angular/router';
|
|
|
|
|
-import { ExtractionService } from '../../services/extraction.service';
|
|
|
|
|
-import { UserAccount } from '../../services/extraction';
|
|
|
|
|
-import { LucideAngularModule, UserPlus, ArrowLeft, Trash2 } from 'lucide-angular';
|
|
|
|
|
-
|
|
|
|
|
-@Component({
|
|
|
|
|
- selector: 'app-user-management',
|
|
|
|
|
- standalone: true,
|
|
|
|
|
- imports: [CommonModule, ReactiveFormsModule, RouterModule, LucideAngularModule],
|
|
|
|
|
- templateUrl: './user-management.component.html',
|
|
|
|
|
- styleUrls: ['./user-management.component.css']
|
|
|
|
|
-})
|
|
|
|
|
-export class UserManagementComponent implements OnInit {
|
|
|
|
|
- userForm: FormGroup;
|
|
|
|
|
- users: UserAccount[] = [];
|
|
|
|
|
- isLoading = false;
|
|
|
|
|
- readonly UserPlus = UserPlus;
|
|
|
|
|
- readonly ArrowLeft = ArrowLeft;
|
|
|
|
|
- readonly Trash2 = Trash2;
|
|
|
|
|
-
|
|
|
|
|
- constructor(
|
|
|
|
|
- private fb: FormBuilder,
|
|
|
|
|
- private extractionService: ExtractionService,
|
|
|
|
|
- private router: Router
|
|
|
|
|
- ) {
|
|
|
|
|
- this.userForm = this.fb.group({
|
|
|
|
|
- name: ['', Validators.required],
|
|
|
|
|
- department: ['', Validators.required],
|
|
|
|
|
- medical_allowance: [1000, [Validators.required, Validators.min(0)]]
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- ngOnInit(): void {
|
|
|
|
|
- this.loadUsers();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- loadUsers(): void {
|
|
|
|
|
- this.isLoading = true;
|
|
|
|
|
- this.extractionService.getUsers().subscribe({
|
|
|
|
|
- next: (data) => {
|
|
|
|
|
- this.users = data;
|
|
|
|
|
- this.isLoading = false;
|
|
|
|
|
- },
|
|
|
|
|
- error: (err) => {
|
|
|
|
|
- console.error('Error loading users:', err);
|
|
|
|
|
- this.isLoading = false;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- onSubmit(): void {
|
|
|
|
|
- if (this.userForm.invalid) return;
|
|
|
|
|
-
|
|
|
|
|
- this.isLoading = true;
|
|
|
|
|
- const newUser: UserAccount = {
|
|
|
|
|
- id: Math.random().toString(36).substr(2, 9),
|
|
|
|
|
- ...this.userForm.value
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- this.extractionService.createUser(newUser).subscribe({
|
|
|
|
|
- next: () => {
|
|
|
|
|
- this.loadUsers();
|
|
|
|
|
- this.userForm.reset({ medical_allowance: 1000 });
|
|
|
|
|
- this.isLoading = false;
|
|
|
|
|
- },
|
|
|
|
|
- error: (err) => {
|
|
|
|
|
- console.error('Error creating user:', err);
|
|
|
|
|
- this.isLoading = false;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|