-
{{ days[index] }}
+
+
+
+ {{ days[index] }}
{
options-dense
map-options
hide-dropdown-icon
- >
-
-
-
-
+ />
{
{
:color="row.comment.length > 0 ? 'primary' : 'grey-8'"
:disable="row.is_approved"
flat
- @click="onClickComment(row)"
+ class="col-1"
+ @click="onClickComment(index)"
+ />
+
+
+
+ Sauvegarder
+
+
+
\ No newline at end of file
diff --git a/src/modules/timesheets/composables/use-timesheet-api.ts b/src/modules/timesheets/composables/use-timesheet-api.ts
index f04ecf4..8b5eefb 100644
--- a/src/modules/timesheets/composables/use-timesheet-api.ts
+++ b/src/modules/timesheets/composables/use-timesheet-api.ts
@@ -2,6 +2,7 @@ import { useAuthStore } from "src/stores/auth-store";
import { useTimesheetStore } from "src/stores/timesheet-store"
import { ref } from "vue";
import { timesheetTempService } from "../services/timesheet-services";
+import type { CreateShiftPayload } from "../types/timesheet-shift-interface";
export const useTimesheetApi = () => {
@@ -9,7 +10,7 @@ export const useTimesheetApi = () => {
const auth_store = useAuthStore();
const week_offset = ref(0);
- const fetch_week = async (offset = week_offset.value) => {
+ const fetchWeek = async (offset = week_offset.value) => {
const email = auth_store.user?.email;
if(!email) return;
try{
@@ -25,9 +26,35 @@ export const useTimesheetApi = () => {
}
};
- const this_week = async () => fetch_week(0);
- const next_week = async () => fetch_week(week_offset.value + 1);
- const previous_week = async () => fetch_week(week_offset.value - 1);
+ const this_week = async () => fetchWeek(0);
+ const next_week = async () => fetchWeek(week_offset.value + 1);
+ const previous_week = async () => fetchWeek(week_offset.value - 1);
- return { week_offset, this_week, next_week, previous_week, fetch_week};
-}
\ No newline at end of file
+ const saveTimesheetShifts = async (shifts: CreateShiftPayload[]) => {
+ const email = auth_store.user?.email;
+ if(!email || shifts.length === 0) return;
+ await timesheet_store.createTimesheetShifts(email, shifts, week_offset.value);
+ };
+
+ const weekStart = (date: Date) => {
+ const x = new Date(date);
+ x.setHours(0, 0, 0, 0);
+ x.setDate(x.getDate() - x.getDay());
+ return x;
+ };
+
+ const getCurrentWeekTimesheetOverview = async (when: Date = new Date()) => {
+ const off = Math.trunc((weekStart(when).getTime() - weekStart(new Date()).getTime()) / 604800000);
+ await fetchWeek(off);
+ }
+
+ return {
+ week_offset,
+ fetchWeek,
+ this_week,
+ next_week,
+ previous_week,
+ saveTimesheetShifts,
+ getCurrentWeekTimesheetOverview,
+ };
+};
\ No newline at end of file
diff --git a/src/modules/timesheets/pages/timesheet-temp-page.vue b/src/modules/timesheets/pages/timesheet-temp-page.vue
index 39d59b3..0e4d391 100644
--- a/src/modules/timesheets/pages/timesheet-temp-page.vue
+++ b/src/modules/timesheets/pages/timesheet-temp-page.vue
@@ -5,11 +5,12 @@ import { useTimesheetApi } from '../composables/use-timesheet-api';
import { computed, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import TimesheetShiftForm from '../components/timesheet/timesheet-shift-form.vue';
+import type { CreateShiftPayload } from '../types/timesheet-shift-interface';
const { locale } = useI18n();
const timesheet_store = useTimesheetStore();
- const { this_week } = useTimesheetApi();
+ const { this_week, saveTimesheetShifts } = useTimesheetApi();
onMounted(async () => {
await this_week();
@@ -23,7 +24,6 @@ import TimesheetShiftForm from '../components/timesheet/timesheet-shift-form.vue
const timesheet_label = computed(() => {
const dates = timesheet_store.current_timesheet.label.split('.');
- console.log(dates);
const start_date = new Intl.DateTimeFormat(locale.value, date_options).format(date.extractDate(dates[0] as string, 'YYYY-MM-DD'));
const end_date = new Intl.DateTimeFormat(locale.value, date_options).format(date.extractDate(dates[1] as string, 'YYYY-MM-DD'));
@@ -35,6 +35,10 @@ import TimesheetShiftForm from '../components/timesheet/timesheet-shift-form.vue
}
return { start_date, end_date };
});
+
+ const onSaveShifts = async (payload: CreateShiftPayload[]) => {
+ await saveTimesheetShifts(payload);
+ };
@@ -57,6 +61,9 @@ import TimesheetShiftForm from '../components/timesheet/timesheet-shift-form.vue
{{ timesheet_label.end_date }}
-