Files
cbsnexora/src/app/groups/groups-view/group-actions/edit-group-meeting-schedule/edit-group-meeting-schedule.component.ts
T

122 lines
4.2 KiB
TypeScript

/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** Angular Imports */
import { Component, OnInit, inject } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder, Validators, FormControl, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { Dates } from 'app/core/utils/dates';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
import { DateFormatPipe } from '../../../../pipes/date-format.pipe';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Edit Group Meetings Schedule Component
*/
@Component({
selector: 'mifosx-edit-group-meeting-schedule',
templateUrl: './edit-group-meeting-schedule.component.html',
styleUrls: ['./edit-group-meeting-schedule.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
DateFormatPipe
]
})
export class EditGroupMeetingScheduleComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private groupsService = inject(GroupsService);
private dateUtils = inject(Dates);
private route = inject(ActivatedRoute);
private router = inject(Router);
private settingsService = inject(SettingsService);
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Group Meeting form. */
groupEditMeetingScheduleForm: UntypedFormGroup;
/** Calendar Template Data */
calendarTemplate: any;
/** Group Id */
groupId: any;
/** CalendarI ID */
calendarId: any;
/** Next meetings data */
nextMeetingDates: any;
/**
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {GroupsService} groupsService Shares Service
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor() {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData;
this.nextMeetingDates = this.calendarTemplate.nextTenRecurringDates;
});
this.calendarId = this.route.snapshot.queryParams['calendarId'];
this.groupId = this.route.parent.snapshot.params['groupId'];
}
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
this.createEditMeetingScheduleForm();
}
/**
* Creates the Edit Group Meeting Schedule form.
*/
createEditMeetingScheduleForm() {
this.groupEditMeetingScheduleForm = this.formBuilder.group({
presentMeetingDate: [
'',
Validators.required
],
newMeetingDate: [
'',
Validators.required
]
});
}
/**
* Submits the form and updates the meeting.
*/
submit() {
const groupEditMeetingScheduleFormData = this.groupEditMeetingScheduleForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const reschedulebasedOnMeetingDates = true;
const prevOldDate: Date = new Date(this.groupEditMeetingScheduleForm.value.presentMeetingDate);
const prevNewDate: Date = this.groupEditMeetingScheduleForm.value.newMeetingDate;
if (groupEditMeetingScheduleFormData.presentMeetingDate instanceof Date) {
groupEditMeetingScheduleFormData.presentMeetingDate = this.dateUtils.formatDate(prevOldDate, dateFormat);
}
if (groupEditMeetingScheduleFormData.newMeetingDate instanceof Date) {
groupEditMeetingScheduleFormData.newMeetingDate = this.dateUtils.formatDate(prevNewDate, dateFormat);
}
const data = {
...groupEditMeetingScheduleFormData,
reschedulebasedOnMeetingDates,
dateFormat,
locale
};
this.groupsService.updateGroupMeeting(this.groupId, data, this.calendarId).subscribe((response: any) => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}