improve exception saving
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { Component, inject, input } from '@angular/core';
|
||||
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
|
||||
import { CalendarEventDto, EventExceptionDto } from '../../../models/events-in-range-dto.model';
|
||||
import {
|
||||
SingleEventDashboardEventDetailsView
|
||||
SingleEventDashboardEventDetailsView,
|
||||
} from '../single-event-dashboard-event-details-view/single-event-dashboard-event-details-view';
|
||||
import { Button } from '@rschneider/ng-daisyui';
|
||||
import { SvgIcons } from '../../../../../svg-icons';
|
||||
import { SafeHtmlPipe } from '../../../../../pipes/safe-html-pipe';
|
||||
import { CalendarService } from '../../../services/calendar.service';
|
||||
import { CreateExceptionDto } from '../../../models/event-exception.model';
|
||||
|
||||
export type ACTIVATION_TYPE = 'cancel' | 'activate';
|
||||
|
||||
@@ -32,32 +33,49 @@ export class SingleEventDashboardEventActivation {
|
||||
|
||||
protected setEventOccurrenceActivation(activated: boolean) {
|
||||
|
||||
const eventId =this.event()?.id!;
|
||||
const event = this.event();
|
||||
console.info('setEventOccurrenceActivation', event);
|
||||
const eventId = this.event()?.id!;
|
||||
const startTime = this.event()?.startTime!;
|
||||
let payload: CreateExceptionDto | undefined = undefined;
|
||||
const eventException = event?.exceptions ? event.exceptions[0] : undefined;
|
||||
if (eventException) {
|
||||
payload = {
|
||||
...eventException,
|
||||
originalStartTime: new Date(eventException.originalStartTime),
|
||||
newStartTime: eventException.newStartTime ? new Date(eventException.newStartTime) : undefined,
|
||||
newEndTime: eventException.newEndTime ? new Date(eventException.newEndTime) :undefined,
|
||||
isCancelled: !activated,
|
||||
};
|
||||
} else {
|
||||
payload = {
|
||||
originalStartTime: new Date(startTime),
|
||||
isCancelled: !activated,
|
||||
};
|
||||
}
|
||||
|
||||
this.calendarService.applyException(eventId,{
|
||||
originalStartTime: new Date(startTime),
|
||||
isCancelled: !activated,
|
||||
}).subscribe(
|
||||
this.calendarService.applyException(eventId, payload ).subscribe(
|
||||
{
|
||||
next: () => {
|
||||
this.onAction()('close');
|
||||
},
|
||||
error: err => {
|
||||
alert("Failed to change event");
|
||||
}
|
||||
}
|
||||
)
|
||||
alert('Failed to change event');
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
protected cancelEventOccurrence() {
|
||||
this.setEventOccurrenceActivation(false);
|
||||
this.setEventOccurrenceActivation(false);
|
||||
}
|
||||
|
||||
protected activateEventOccurrence() {
|
||||
this.setEventOccurrenceActivation(true);
|
||||
}
|
||||
|
||||
protected closeDialog() {
|
||||
this.onAction()('close')
|
||||
this.onAction()('close');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,18 @@ export type BookingWithUserDto = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
export interface EventExceptionDto{
|
||||
id: number,
|
||||
description: string;
|
||||
eventId: number;
|
||||
isCancelled: boolean;
|
||||
newEndTime: string;
|
||||
newStartTime: string;
|
||||
originalStartTime: string;
|
||||
title: string;
|
||||
|
||||
}
|
||||
|
||||
// The final shape of a calendar event occurrence
|
||||
export type CalendarEventDto = {
|
||||
id: number;
|
||||
@@ -29,4 +41,5 @@ export type CalendarEventDto = {
|
||||
|
||||
isRecurring: boolean;
|
||||
eventType: EventType
|
||||
exceptions: EventExceptionDto[]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user