diff --git a/src/pages/Worker/Card/WorkerCalendar.vue b/src/pages/Worker/Card/WorkerCalendar.vue
index e3c0edbf3..fdfb3f9f8 100644
--- a/src/pages/Worker/Card/WorkerCalendar.vue
+++ b/src/pages/Worker/Card/WorkerCalendar.vue
@@ -1,5 +1,5 @@
@@ -106,7 +161,6 @@ const onHandleRefresh = () => workerCalendarFilterRef.value.refreshData();
v-model:business-fk="businessFk"
v-model:year="year"
v-model:absence-type="absenceType"
- @on-absences-fetched="onFetchAbsences"
/>
@@ -142,7 +196,8 @@ const onHandleRefresh = () => workerCalendarFilterRef.value.refreshData();
:absence-type="absenceType"
:business-fk="businessFk"
:events="events"
- @refresh="onHandleRefresh"
+ @refresh="refreshData"
+ @on-deleted-event="onDeletedEvent"
/>
diff --git a/src/pages/Worker/Card/WorkerCalendarFilter.vue b/src/pages/Worker/Card/WorkerCalendarFilter.vue
index e83a0f1f3..c3fe65e19 100644
--- a/src/pages/Worker/Card/WorkerCalendarFilter.vue
+++ b/src/pages/Worker/Card/WorkerCalendarFilter.vue
@@ -4,9 +4,8 @@ import FetchData from 'components/FetchData.vue';
import { useI18n } from 'vue-i18n';
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
import { useRoute } from 'vue-router';
-import { computed, ref, watch, reactive } from 'vue';
+import { computed, ref } from 'vue';
import { toDateFormat } from '../../../filters/date';
-import axios from 'axios';
const { t } = useI18n();
const route = useRoute();
@@ -26,12 +25,7 @@ const props = defineProps({
},
});
-const emit = defineEmits([
- 'update:businessFk',
- 'update:year',
- 'update:absenceType',
- 'onAbsencesFetched',
-]);
+const emit = defineEmits(['update:businessFk', 'update:year', 'update:absenceType']);
const selectedBusinessFk = computed({
get: () => props.businessFk,
@@ -64,60 +58,6 @@ const generateYears = () => {
const absenceTypeList = ref([]);
const contractList = ref([]);
const yearList = ref(generateYears());
-
-const contractHolidays = ref(null);
-const yearHolidays = ref(null);
-
-const getHolidays = async (params) => {
- try {
- const { data } = await axios.get(`Workers/${route.params.id}/holidays`, {
- params,
- });
- return data;
- } catch (error) {
- console.error('Error fetching holidays:', error);
- return null;
- }
-};
-
-const updateContractHolidays = async () => {
- contractHolidays.value = await getHolidays({
- businessFk: selectedBusinessFk.value,
- year: selectedYear.value,
- });
-};
-
-const updateYearHolidays = async () => {
- yearHolidays.value = await getHolidays({ year: selectedYear.value });
-};
-
-const getAbsences = async () => {
- try {
- const params = {
- workerFk: route.params.id,
- businessFk: props.businessFk,
- year: props.year,
- };
- const { data } = await axios.get('Calendars/absences', { params });
- if (data) emit('onAbsencesFetched', data);
- return data;
- } catch (error) {
- console.error('Error fetching absences:', error);
- return null;
- }
-};
-
-const refreshData = () => {
- updateYearHolidays();
- updateContractHolidays();
- getAbsences();
-};
-
-watch([selectedYear, selectedBusinessFk], () => refreshData());
-
-defineExpose({
- refreshData,
-});
diff --git a/src/pages/Worker/Card/WorkerCalendarItem.vue b/src/pages/Worker/Card/WorkerCalendarItem.vue
index a853a95db..481d926c4 100644
--- a/src/pages/Worker/Card/WorkerCalendarItem.vue
+++ b/src/pages/Worker/Card/WorkerCalendarItem.vue
@@ -36,7 +36,7 @@ const props = defineProps({
},
});
-const emit = defineEmits(['refresh']);
+const emit = defineEmits(['refresh', 'onDeletedEvent']);
const route = useRoute();
const { t } = useI18n();
@@ -76,34 +76,30 @@ const createEvent = async (date) => {
const editEvent = async (event) => {
try {
- console.log('editEvent');
const absenceType = props.absenceType;
const params = {
absenceId: event.absenceId,
absenceTypeId: absenceType.id,
};
-
const { data } = await axios.patch(
`Workers/${route.params.id}/updateAbsence`,
params
);
- console.log('edit data:: ', data);
+
if (data) emit('refresh');
} catch (error) {
console.log('error editing event:: ', error);
}
};
-const deleteEvent = async (event) => {
+const deleteEvent = async (event, date) => {
console.log('deleteEvent:: ', event);
const params = { absenceId: event.absenceId };
- console.log('params:: ', params);
const { data } = await axios.delete(`Workers/${route.params.id}/deleteAbsence`, {
params,
});
- console.log('delete data:: ', data);
- if (data) emit('refresh');
+ if (data) emit('onDeletedEvent', date.getTime());
};
const handleDateSelected = (date) => {
@@ -121,10 +117,8 @@ const handleDateSelected = (date) => {
};
const handleEventSelected = (event, { year, month, day }) => {
- console.log('event:: ', event);
const date = new Date(year, month - 1, day);
- console.log('date:: ', date);
- if (event.type == props.absenceType.code) deleteEvent(event);
+ if (event.type == props.absenceType.code) deleteEvent(event, date);
else editEvent(event);
};