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,
timeInformation: {
dayStartTime: "08:00",
dayEndTime: "20:00",
dayEndTime: "24:00",
},
eventsData: [],
employeesData: [],

View File

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

View File

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

View File

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