WIP Сделала ошибку на измение события

This commit is contained in:
Daria Golova
2022-12-13 16:03:45 +03:00
parent 670db2809c
commit c0bb78beb9
4 changed files with 51 additions and 36 deletions

View File

@@ -75,7 +75,7 @@ export default {
showModal: false, showModal: false,
timeInformation: { timeInformation: {
dayStartTime: "08:00", dayStartTime: "08:00",
dayEndTime: "20:00", dayEndTime: "24:00",
}, },
eventsData: [], eventsData: [],
employeesData: [], employeesData: [],

View File

@@ -13,7 +13,7 @@
img.icon-wrapper.cursor-pointer(src="@/assets/icons/lock.svg") img.icon-wrapper.cursor-pointer(src="@/assets/icons/lock.svg")
column-header-checkbox column-header-checkbox
.body.pl-1 .body.pl-1
transition-group(name="card", tag="div") transition-group(name="card")
calendar-event-card( calendar-event-card(
v-for="event in dayEvents", v-for="event in dayEvents",
:key="event.id", :key="event.id",

View File

@@ -228,7 +228,7 @@ export default {
immediate: true, immediate: true,
handler(newValue) { handler(newValue) {
if (newValue === true) { if (newValue === true) {
this.setDefaultTheme(); this.isActive = false;
this.$emit("reset-change-form"); this.$emit("reset-change-form");
} }
}, },

View File

@@ -288,6 +288,13 @@ export default {
this.eventData = {}; this.eventData = {};
}, },
async updateEventData() { async updateEventData() {
if (
Object.keys(
this.findPerson(this.ownersData, this.employees, "employee")
).length > 0 &&
Object.keys(this.findPerson(this.membersData, this.members, "person"))
.length > 0
) {
this.eventData = { this.eventData = {
start: this.mergeDate(this.eventDate, this.startTime), start: this.mergeDate(this.eventDate, this.startTime),
end: this.mergeDate(this.eventDate, this.endTime), end: this.mergeDate(this.eventDate, this.endTime),
@@ -299,6 +306,11 @@ export default {
}; };
await this.postUpdateEvent(this.id, this.eventData); await this.postUpdateEvent(this.id, this.eventData);
this.eventData = {}; this.eventData = {};
} else
this.addErrorNotification(
"Событие не может быть изменено",
"Клиент был удален"
);
}, },
clearForm() { clearForm() {
if (this.selectedEventData.id) this.$emit("close-change-form"); if (this.selectedEventData.id) this.$emit("close-change-form");
@@ -310,6 +322,7 @@ export default {
}, },
findPerson(requestedList, object, field) { findPerson(requestedList, object, field) {
let foundPerson = requestedList.find(({ id }) => id === object[field].id); let foundPerson = requestedList.find(({ id }) => id === object[field].id);
if (foundPerson) {
let returnedData = { let returnedData = {
[field]: { [field]: {
id: foundPerson.id, id: foundPerson.id,
@@ -322,11 +335,16 @@ export default {
}; };
if (object.id) returnedData.id = object.id; if (object.id) returnedData.id = object.id;
return returnedData; return returnedData;
}
return {};
}, },
async postCreateEvent(event) { async postCreateEvent(event) {
const response = await fetchWrapper.post("registry/event/create/", event); const response = await fetchWrapper.post("registry/event/create/", event);
if (response.type && response.type === "validation_error") { if (response.type && response.type === "validation_error") {
this.addErrorNotification(response); this.addErrorNotification(
response.errors[0].code,
response.errors[0].detail
);
} else { } else {
this.addSuccessNotification("Событие успешно создано"); this.addSuccessNotification("Событие успешно создано");
this.clearForm(); this.clearForm();
@@ -338,7 +356,10 @@ export default {
event event
); );
if (response.type && response.type === "validation_error") { if (response.type && response.type === "validation_error") {
this.addErrorNotification(response); this.addErrorNotification(
response.errors[0].code,
response.errors[0].detail
);
} else { } else {
this.addSuccessNotification("Изменения успешно сохранены"); this.addSuccessNotification("Изменения успешно сохранены");
this.clearForm(); this.clearForm();
@@ -362,14 +383,8 @@ export default {
return id; return id;
} }
}, },
addErrorNotification(error) { addErrorNotification(title, message) {
addNotification( addNotification(new Date().getTime(), title, message, "error", 5000);
new Date().getTime(),
error.errors[0].code,
error.errors[0].detail,
"error",
5000
);
}, },
addSuccessNotification(message) { addSuccessNotification(message) {
addNotification(new Date().getTime(), message, "", "success", 5000); addNotification(new Date().getTime(), message, "", "success", 5000);