0% found this document useful (0 votes)
23 views2 pages

Ts

The LeaveApplicationComponent in Angular allows users to submit leave applications through a form. It initializes a reactive form with required fields and retrieves the username from storage on component initialization. Upon form submission, it displays a success message and sends the leave details to the LeaveService if the form is valid.

Uploaded by

Almost Viral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Ts

The LeaveApplicationComponent in Angular allows users to submit leave applications through a form. It initializes a reactive form with required fields and retrieves the username from storage on component initialization. Upon form submission, it displays a success message and sends the leave details to the LeaveService if the form is valid.

Uploaded by

Almost Viral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import { Component, OnInit } from '@angular/core';

import { FormBuilder, FormGroup, Validators } from '@angular/forms';


import { LeaveService } from '../_services/leave.service';
import { StorageService } from '../_services/storage.service';
import { UserService } from '../_services/user.service';
import { Router } from '@angular/router';
import Swal from 'sweetalert2';

@Component({
selector: 'app-leave-application',
templateUrl: './leave-application.component.html',
styleUrls: ['./leave-application.component.css']
})
export class LeaveApplicationComponent implements OnInit {

leaveForm: FormGroup;
content?: string;
username?: string;
leaveSubmitted: boolean = false;

constructor(private router: Router,private fb: FormBuilder, private userService:


UserService,private leaveService: LeaveService ,private storageService:
StorageService) {
this.leaveForm = this.fb.group({
date_debut: ['', Validators.required],
date_fin: ['', Validators.required],
leaveType: ['', Validators.required],
leaveMotive: ['', Validators.required],
});

}
ngOnInit(): void {
this.username = this.storageService.getUser().username; // Adjust this based on
your storage service
this.userService.getUserBoard().subscribe({
next: data => {
this.content = data;
},
error: err => {
console.error('Error:', err);
}
});
}

applyLeave() {

Swal.fire({
icon: 'success',
title: 'Leave Application Submitted',
text: 'Your leave application has been submitted successfully!',
});

if (this.leaveForm.valid && this.username) {


const leaveDetails = { username: this.username, ...this.leaveForm.value };
this.leaveService.applyLeave(this.username, leaveDetails).subscribe(
response => {

// Reset the form

// Set leaveSubmitted to true for your success message


//this.leaveSubmitted = true;

// Redirect to leave applications list

}
);
}
this.leaveForm.reset();
}

You might also like