mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 18:39:43 +00:00
re-add feature to patch event
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import {State} from './../index';
|
||||
import {ActionContext, Module} from 'vuex';
|
||||
import {CalendarRange, CalendarRangeEdit} from "../../../../types";
|
||||
import {CalendarRange, CalendarRangeCreate, CalendarRangeEdit} from "../../../../types";
|
||||
import {fetchCalendarRangeForUser} from '../../../Calendar/api';
|
||||
import {calendarRangeToFullCalendarEvent} from '../../../Calendar/store/utils';
|
||||
import {UserAssociatedInterface} from "../../../../../../../ChillMainBundle/Resources/public/types";
|
||||
import {EventInput} from '@fullcalendar/vue3';
|
||||
import {makeFetch} from "../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||
import {datetimeToISO} from "../../../../../../../ChillMainBundle/Resources/public/chill/js/date";
|
||||
@@ -91,6 +90,17 @@ export default <Module<CalendarRangesState, State>>{
|
||||
state.key = state.key + 1;
|
||||
}
|
||||
},
|
||||
updateRange(state, range: CalendarRange) {
|
||||
const found = state.ranges.find(r => r.calendarRangeId === range.id && r.is === "range");
|
||||
const newEvent = calendarRangeToFullCalendarEvent(range);
|
||||
|
||||
if (found !== undefined) {
|
||||
found.start = newEvent.start;
|
||||
found.end = newEvent.end;
|
||||
}
|
||||
|
||||
state.key = state.key + 1;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
fetchRanges(ctx: Context, payload: { start: Date, end: Date }): Promise<null> {
|
||||
@@ -141,9 +151,9 @@ export default <Module<CalendarRangesState, State>>{
|
||||
endDate: {
|
||||
datetime: datetimeToISO(end)
|
||||
},
|
||||
} as CalendarRangeEdit;
|
||||
} as CalendarRangeCreate;
|
||||
|
||||
return makeFetch<CalendarRangeEdit, CalendarRange>('POST', url, body)
|
||||
return makeFetch<CalendarRangeCreate, CalendarRange>('POST', url, body)
|
||||
.then((newRange) => {
|
||||
|
||||
ctx.commit('addRange', newRange);
|
||||
@@ -156,14 +166,33 @@ export default <Module<CalendarRangesState, State>>{
|
||||
throw error;
|
||||
})
|
||||
},
|
||||
deleteRange({commit}, calendarRangeId: number) {
|
||||
deleteRange(ctx, calendarRangeId: number) {
|
||||
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
|
||||
|
||||
makeFetch<undefined, never>('DELETE', url)
|
||||
.then((_) => {
|
||||
commit('removeRange', calendarRangeId);
|
||||
ctx.commit('removeRange', calendarRangeId);
|
||||
});
|
||||
},
|
||||
patchRangeTime(ctx, {calendarRangeId, start, end}: {calendarRangeId: number, start: Date, end: Date}): void {
|
||||
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
|
||||
const body = {
|
||||
startDate: {
|
||||
datetime: datetimeToISO(start)
|
||||
},
|
||||
endDate: {
|
||||
datetime: datetimeToISO(end)
|
||||
},
|
||||
} as CalendarRangeEdit;
|
||||
|
||||
makeFetch<CalendarRangeEdit, CalendarRange>('PATCH', url, body)
|
||||
.then((range) => {
|
||||
ctx.commit('updateRange', range);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user