diff --git a/src/modules/timesheets/components/expense-dialog-form.vue b/src/modules/timesheets/components/expense-dialog-form.vue index 6ae8811..1dc7f97 100644 --- a/src/modules/timesheets/components/expense-dialog-form.vue +++ b/src/modules/timesheets/components/expense-dialog-form.vue @@ -33,6 +33,8 @@ const period_start_date = computed(() => timesheet_store.pay_period?.period_start.replaceAll('-', '/') ?? ''); const period_end_date = computed(() => timesheet_store.pay_period?.period_end.replaceAll('-', '/') ?? ''); + const expense = defineModel({ default: new Expense(new Date().toISOString().slice(0, 10)) }) + const expense_options: ExpenseOption[] = [ { label: t('timesheet.expense.types.PER_DIEM'), value: 'PER_DIEM', icon: getExpenseIcon('PER_DIEM') }, { label: t('timesheet.expense.types.EXPENSES'), value: 'EXPENSES', icon: getExpenseIcon('EXPENSES') }, @@ -55,7 +57,10 @@ } const requestExpenseCreationOrUpdate = async () => { - await expenses_api.upsertExpense(expenses_store.current_expense); + if (expenses_store.mode === 'update') + await expenses_api.upsertExpense(expenses_store.current_expense, timesheet_store.current_pay_period_overview?.email); + else + await expenses_api.upsertExpense(expenses_store.current_expense); expenses_store.is_showing_create_form = true; expenses_store.mode = 'create'; @@ -63,13 +68,18 @@ }; onMounted(() => { - expense_selected.value = expense_options.find(expense => expense.value === expenses_store.current_expense.type); + if (expense.value) + expense_selected.value = expense_options.find(expense_option => expense_option.value === expense.value.type); + else + expense_selected.value = expense_options[1]; + + console.log('expense mount triggered: current expense type is ', expenses_store.current_expense.type, ', matching option is: ', expense_selected.value); }) - + \ No newline at end of file diff --git a/src/modules/timesheets/composables/use-expense-api.ts b/src/modules/timesheets/composables/use-expense-api.ts index d5ea046..e4b3485 100644 --- a/src/modules/timesheets/composables/use-expense-api.ts +++ b/src/modules/timesheets/composables/use-expense-api.ts @@ -8,18 +8,19 @@ export const useExpensesApi = () => { const expenses_store = useExpensesStore(); const timesheet_store = useTimesheetStore(); - const upsertExpense = async (expense: Expense): Promise => { - const success = await expenses_store.upsertExpense(expense); + const upsertExpense = async (expense: Expense, employee_email?: string): Promise => { + const success = await expenses_store.upsertExpense(expense, employee_email); + if (success) { expenses_store.current_expense = new Expense(date.formatDate( new Date(), 'YYYY-MM-DD')); - timesheet_store.getTimesheetsByOptionalEmployeeEmail(); + timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email); } }; - const deleteExpenseById = async (expense_id: number): Promise => { + const deleteExpenseById = async (expense_id: number, employee_email?: string): Promise => { const success = await expenses_store.deleteExpenseById(expense_id); if (success) { - timesheet_store.getTimesheetsByOptionalEmployeeEmail(); + timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email); } }; diff --git a/src/modules/timesheets/composables/use-shift-api.ts b/src/modules/timesheets/composables/use-shift-api.ts index 6b6176e..2696836 100644 --- a/src/modules/timesheets/composables/use-shift-api.ts +++ b/src/modules/timesheets/composables/use-shift-api.ts @@ -1,18 +1,16 @@ -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 ?? ''); + await timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email); } timesheet_store.is_loading = false;