targo-frontend/src/modules/timesheets/composables/use-shift-api.ts
Nic D. 75060a2228 fix(timesheet-approval): minor fix to timesheet reload after changes to employee timesheet
was reloading users timesheets instead of employees after update or create
2026-01-26 10:41:24 -05:00

38 lines
1.3 KiB
TypeScript

import { useAuthStore } from "src/stores/auth-store";
import { useShiftStore } from "src/stores/shift-store";
import { useTimesheetStore } from "src/stores/timesheet-store";
export const useShiftApi = () => {
const timesheet_store = useTimesheetStore();
const shift_store = useShiftStore();
const auth_store = useAuthStore();
const deleteShiftById = async (shift_id: number, employee_email?: string) => {
timesheet_store.is_loading = true;
const success = await shift_store.deleteShiftById(shift_id, employee_email);
if (success) {
await timesheet_store.getTimesheetsByOptionalEmployeeEmail(auth_store.user?.email ?? '');
}
timesheet_store.is_loading = false;
};
const saveShiftChanges = async (employee_email?: string) => {
timesheet_store.is_loading = true;
const update_success = await shift_store.updateShifts(employee_email);
const create_success = await shift_store.createNewShifts(employee_email);
if (create_success || update_success){
await timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
}
timesheet_store.is_loading = false;
}
return {
deleteShiftById,
saveShiftChanges,
};
}