From d20f97095843f5dbc682c554e1e818a9a0a372df Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Tue, 2 Sep 2025 14:30:46 -0400 Subject: [PATCH] feat(timesheet): added timesheet page, created timsheet-interface and setup store and api --- .../composables/use-timesheet-api.ts | 33 +++++++++++++++++++ .../timesheets/pages/timesheet-temp-page.vue | 24 +++++++++----- .../timesheets/services/timesheet-services.ts | 6 ++-- .../timesheets/types/timesheet-interface.ts | 23 +++++++++++-- src/stores/timesheet-store.ts | 24 +++++++------- 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/src/modules/timesheets/composables/use-timesheet-api.ts b/src/modules/timesheets/composables/use-timesheet-api.ts index e69de29..f04ecf4 100644 --- a/src/modules/timesheets/composables/use-timesheet-api.ts +++ b/src/modules/timesheets/composables/use-timesheet-api.ts @@ -0,0 +1,33 @@ +import { useAuthStore } from "src/stores/auth-store"; +import { useTimesheetStore } from "src/stores/timesheet-store" +import { ref } from "vue"; +import { timesheetTempService } from "../services/timesheet-services"; + + +export const useTimesheetApi = () => { + const timesheet_store = useTimesheetStore(); + const auth_store = useAuthStore(); + const week_offset = ref(0); + + const fetch_week = async (offset = week_offset.value) => { + const email = auth_store.user?.email; + if(!email) return; + try{ + timesheet_store.is_loading = true; + const timesheet = await timesheetTempService.getTimesheetsByEmail(email, offset); + timesheet_store.current_timesheet = timesheet; + week_offset.value = offset; + }catch (err) { + console.error('fetch week error', err); + timesheet_store.current_timesheet = { ...timesheet_store.current_timesheet, shifts: [], expenses: [] }; + } finally { + timesheet_store.is_loading = false; + } + }; + + 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); + + return { week_offset, this_week, next_week, previous_week, fetch_week}; +} \ 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 d030193..1b5d365 100644 --- a/src/modules/timesheets/pages/timesheet-temp-page.vue +++ b/src/modules/timesheets/pages/timesheet-temp-page.vue @@ -1,20 +1,28 @@