-
+
+
diff --git a/src/router/index.ts b/src/router/index.ts
index c1afbd1..71b125d 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -2,6 +2,7 @@ import { defineRouter } from '#q-app/wrappers';
import { createMemoryHistory, createRouter, createWebHashHistory, createWebHistory, } from 'vue-router';
import routes from './routes';
import { useAuthStore } from 'src/stores/auth-store';
+import { RouteNames } from 'src/router/router-constants';
/*
* If not building with SSR mode, you can
@@ -13,27 +14,29 @@ import { useAuthStore } from 'src/stores/auth-store';
*/
export default defineRouter(function (/* { store, ssrContext } */) {
- const createHistory = process.env.SERVER
- ? createMemoryHistory
- : (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory);
+ const createHistory = process.env.SERVER
+ ? createMemoryHistory
+ : (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory);
- const Router = createRouter({
- scrollBehavior: () => ({ left: 0, top: 0 }),
- routes,
+ const Router = createRouter({
+ scrollBehavior: () => ({ left: 0, top: 0 }),
+ routes,
- // Leave this as is and make changes in quasar.conf.js instead!
- // quasar.conf.js -> build -> vueRouterMode
- // quasar.conf.js -> build -> publicPath
- history: createHistory(process.env.VUE_ROUTER_BASE),
- });
+ // Leave this as is and make changes in quasar.conf.js instead!
+ // quasar.conf.js -> build -> vueRouterMode
+ // quasar.conf.js -> build -> publicPath
+ history: createHistory(process.env.VUE_ROUTER_BASE),
+ });
- Router.beforeEach((destinationPage) => {
- const authStore = useAuthStore();
+ Router.beforeEach(async (destinationPage) => {
+ const authStore = useAuthStore();
+ const result = await authStore.getProfile() ?? { status: 400, message: 'unknown error occured' };
- if (destinationPage.meta.requiresAuth && !authStore.isAuthorizedUser) {
- return { name: 'login' };
- }
- })
+ if ((destinationPage.meta.requiresAuth && !authStore.isAuthorizedUser) || (result.status >= 400 && destinationPage.name !== RouteNames.LOGIN)) {
+ console.log('no user account found');
+ return { name: 'login' };
+ }
+ })
- return Router;
+ return Router;
});
diff --git a/src/router/router-constants.ts b/src/router/router-constants.ts
index b24aa80..83c0364 100644
--- a/src/router/router-constants.ts
+++ b/src/router/router-constants.ts
@@ -6,5 +6,5 @@ export enum RouteNames {
TIMESHEET_APPROVALS = 'timesheet-approvals',
EMPLOYEE_LIST = 'employee-list',
PROFILE = 'user/profile',
- TIMESHEET_TEMP = 'timesheet-temp'
+ TIMESHEET = 'timesheet'
}
\ No newline at end of file
diff --git a/src/router/routes.ts b/src/router/routes.ts
index f852636..faf1ecb 100644
--- a/src/router/routes.ts
+++ b/src/router/routes.ts
@@ -10,7 +10,7 @@ const routes: RouteRecordRaw[] = [
{
path: '',
name: RouteNames.DASHBOARD,
- component: () => import('src/pages/test-page.vue'),
+ component: () => import('src/pages/dashboard-page.vue'),
},
{
path: 'timesheet-approvals',
@@ -23,8 +23,8 @@ const routes: RouteRecordRaw[] = [
component: () => import('src/pages/employee-list-page.vue'),
},
{
- path: 'timesheet-temp',
- name: RouteNames.TIMESHEET_TEMP,
+ path: 'timesheet',
+ name: RouteNames.TIMESHEET,
component: () => import('src/pages/timesheet-page.vue')
},
{
@@ -38,7 +38,7 @@ const routes: RouteRecordRaw[] = [
{
path: '/v1/login',
name: RouteNames.LOGIN,
- component: () => import('src/modules/auth/pages/auth-login.vue'),
+ component: () => import('src/pages/login-page.vue'),
meta: { requiresAuth: false },
},
diff --git a/src/stores/auth-store.ts b/src/stores/auth-store.ts
index 51002f9..3522e5e 100644
--- a/src/stores/auth-store.ts
+++ b/src/stores/auth-store.ts
@@ -15,19 +15,9 @@ export const useAuthStore = defineStore('auth', () => {
//TODO: manage customer login process
};
- const oidcLogin = async (): Promise
=> {
- window.addEventListener('message', async (event) => {
- if (event.data.type === 'authSuccess') {
- const new_user = await AuthService.getProfile();
- user.value = new_user;
- router.push('/');
- } else {
- Notify.create({
- message: "You have popups blocked on this website!",
- color: 'negative',
- textColor: 'white',
- });
- }
+ const oidcLogin = () => {
+ window.addEventListener('message', (event) => {
+ void handleAuthMessage(event);
});
const oidc_popup = window.open('http://localhost:3000/auth/v1/login', 'authPopup', 'width=600,height=800');
@@ -44,6 +34,34 @@ export const useAuthStore = defineStore('auth', () => {
user.value = undefined;
};
- return { user, authError, isAuthorizedUser, login, oidcLogin, logout };
+ const handleAuthMessage = async (event: MessageEvent) => {
+ if (event.data.type === 'authSuccess') {
+ try {
+ await getProfile();
+ await router.push('/');
+ } catch (error) {
+ console.error('failed to login: ', error);
+ }
+ } else {
+ Notify.create({
+ message: "You have popups blocked on this website!",
+ color: 'negative',
+ textColor: 'white',
+ });
+ }
+ };
+
+ const getProfile = async (): Promise<{ status: number, message: string }> => {
+ try {
+ const new_user = await AuthService.getProfile();
+ user.value = new_user;
+ return { status: 200, message: 'profile retrieved successfully' };
+ } catch (error) {
+ console.error('error while retrieving profile: ', error);
+ }
+ return { status: 400, message: 'unknown error occured' };
+ }
+
+ return { user, authError, isAuthorizedUser, login, oidcLogin, logout, getProfile };
});
diff --git a/src/stores/expense-store.ts b/src/stores/expense-store.ts
index 4348e7f..0396e05 100644
--- a/src/stores/expense-store.ts
+++ b/src/stores/expense-store.ts
@@ -1,21 +1,17 @@
import { ref } from "vue";
import { defineStore } from "pinia";
-import { useTimesheetStore } from "src/stores/timesheet-store";
-import { default_expense, default_pay_period_expenses, type UpsertExpense, type Expense, type PayPeriodExpenses } from "src/modules/timesheets/models/expense.models";
import { timesheetService } from "src/modules/timesheets/services/timesheet-service";
-import { ExpensesApiError, type GenericApiError } from "src/modules/timesheets/models/expense.validation";
-import type { CrudAction } from "src/modules/timesheets/models/shift.models";
+import { ExpensesApiError, type GenericApiError } from "src/modules/timesheets/models/expense-validation.models";
+import { empty_expense, test_expenses, type Expense } from "src/modules/timesheets/models/expense.models";
export const useExpensesStore = defineStore('expenses', () => {
- const timesheet_store = useTimesheetStore();
const is_open = ref(false);
const is_loading = ref(false);
- const mode = ref('create');
- const pay_period_expenses = ref(default_pay_period_expenses);
- const current_expense = ref(default_expense);
- const initial_expense = ref(default_expense);
+ const pay_period_expenses = ref(test_expenses);
+ const current_expense = ref(empty_expense);
+ const initial_expense = ref(empty_expense);
const error = ref(null);
// const setErrorFrom = (err: unknown) => {
@@ -23,14 +19,14 @@ export const useExpensesStore = defineStore('expenses', () => {
// error.value = e?.message || 'Unknown error';
// };
- const open = async (employee_email: string): Promise => {
+ const open = (): void => {
is_open.value = true;
is_loading.value = true;
error.value = null;
- current_expense.value = default_expense;
- initial_expense.value = default_expense;
+ current_expense.value = empty_expense;
+ initial_expense.value = empty_expense;
- await getPayPeriodExpensesByEmployeeEmail(employee_email);
+ // await getPayPeriodExpensesByTimesheetId(timesheet_id);
is_loading.value = false;
}
@@ -39,16 +35,12 @@ export const useExpensesStore = defineStore('expenses', () => {
is_open.value = false;
};
- const getPayPeriodExpensesByEmployeeEmail = async (employee_email: string): Promise => {
+ const getPayPeriodExpensesByTimesheetId = async (timesheet_id: number): Promise => {
is_loading.value = true;
error.value = null;
try {
- const expenses = await timesheetService.getExpensesByPayPeriodAndEmployeeEmail(
- encodeURIComponent(employee_email),
- encodeURIComponent(timesheet_store.pay_period.pay_year),
- encodeURIComponent(timesheet_store.pay_period.pay_period_no),
- );
+ const expenses = await timesheetService.getExpensesByTimesheetId(timesheet_id);
pay_period_expenses.value = expenses;
} catch (err: unknown) {
if (typeof err === 'object') {
@@ -70,21 +62,19 @@ export const useExpensesStore = defineStore('expenses', () => {
}
};
- const upsertOrDeleteExpensesByEmployeeEmail = async (employee_email: string, date: string, expense: UpsertExpense): Promise => {
+ const upsertOrDeleteExpensesById = async (employee_email: string, date: string, expense_id: number): Promise => {
is_loading.value = true;
error.value = null;
try {
- const updated_expenses = await timesheetService.upsertOrDeleteExpensesByPayPeriodAndEmployeeEmail(
+ await timesheetService.upsertOrDeleteExpenseByEmailAndExpenseId(
encodeURIComponent(employee_email),
- encodeURIComponent(date),
- expense,
+ expense_id,
);
- console.log('updated expenses received: ', updated_expenses)
- pay_period_expenses.value.expenses = updated_expenses;
+ // TODO: Save response data into proper ref
} catch (err) {
// setErrorFrom(err);
- console.log('error doing some expense thing: ', err)
+ console.error(err);
} finally {
is_loading.value = false;
}
@@ -93,14 +83,13 @@ export const useExpensesStore = defineStore('expenses', () => {
return {
is_open,
is_loading,
- mode,
pay_period_expenses,
current_expense,
initial_expense,
error,
open,
- getPayPeriodExpensesByEmployeeEmail,
- upsertOrDeleteExpensesByEmployeeEmail,
+ getPayPeriodExpensesByTimesheetId,
+ upsertOrDeleteExpensesById,
close,
};
});
\ No newline at end of file
diff --git a/src/stores/timesheet-store.ts b/src/stores/timesheet-store.ts
index 8b7fdba..583c19b 100644
--- a/src/stores/timesheet-store.ts
+++ b/src/stores/timesheet-store.ts
@@ -1,24 +1,24 @@
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { withLoading } from 'src/utils/store-helpers';
+import { useAuthStore } from 'src/stores/auth-store';
import { timesheetApprovalService } from 'src/modules/timesheet-approval/services/timesheet-approval-service';
import { timesheetService } from 'src/modules/timesheets/services/timesheet-service';
-import { default_pay_period_overview, type TimesheetOverview } from "src/modules/timesheet-approval/models/timesheet-overview.models";
-import { default_pay_period, type PayPeriod } from 'src/modules/shared/models/pay-period.models';
-import { default_pay_period_details, type PayPeriodDetails } from 'src/modules/timesheets/models/timesheet.models';
+import type { TimesheetOverview } from "src/modules/timesheet-approval/models/timesheet-overview.models";
+import type { PayPeriod } from 'src/modules/shared/models/pay-period.models';
+import { test_timesheets, type Timesheet } from 'src/modules/timesheets/models/timesheet.models';
import type { TimesheetApprovalCSVReportFilters } from 'src/modules/timesheet-approval/models/timesheet-approval-csv-report.models';
+const auth_store = useAuthStore();
+
export const useTimesheetStore = defineStore('timesheet', () => {
const is_loading = ref(false);
- const pay_period = ref(default_pay_period);
- const pay_period_overviews = ref([default_pay_period_overview,]);
- const current_pay_period_overview = ref(default_pay_period_overview);
- const pay_period_details = ref(default_pay_period_details);
+ const pay_period = ref();
+ const pay_period_overviews = ref([]);
+ const current_pay_period_overview = ref();
+ const timesheets = ref(test_timesheets);
const pay_period_report = ref();
- const is_calendar_limit = computed(() =>
- pay_period.value.pay_year === 2024 &&
- pay_period.value.pay_period_no <= 1
- );
+ const is_calendar_limit = computed(() => (pay_period.value?.pay_year === 2024 && pay_period.value?.pay_period_no <= 1) ?? false);
const getPayPeriodByDateOrYearAndNumber = async (date_or_year: string | number, period_number?: number): Promise => {
is_loading.value = true;
@@ -30,14 +30,14 @@ export const useTimesheetStore = defineStore('timesheet', () => {
else if (typeof date_or_year === 'number' && period_number) {
pay_period.value = await timesheetService.getPayPeriodByYearAndPeriodNumber(date_or_year, period_number);
}
- else pay_period.value = default_pay_period;
+ else pay_period.value = undefined;
is_loading.value = false;
return true;
} catch (error) {
console.error('Could not get current pay period: ', error);
- pay_period.value = default_pay_period;
- pay_period_overviews.value = [default_pay_period_overview,];
+ pay_period.value = undefined;
+ pay_period_overviews.value = [];
//TODO: More in-depth error-handling here
is_loading.value = false;
@@ -45,18 +45,18 @@ export const useTimesheetStore = defineStore('timesheet', () => {
}
};
- const getPayPeriodOverviewsBySupervisorEmail = async (pay_year: number, period_number: number, supervisor_email: string): Promise => {
+ const getTimesheetOverviewsByPayPeriod = async (pay_year: number, period_number: number, supervisor_email?: string): Promise => {
is_loading.value = true;
try {
- const response = await timesheetApprovalService.getPayPeriodOverviewsBySupervisorEmail(pay_year, period_number, supervisor_email);
+ const response = await timesheetApprovalService.getPayPeriodOverviewsBySupervisorEmail(pay_year, period_number, supervisor_email ?? auth_store.user?.email ?? '');
pay_period_overviews.value = response.employees_overview;
is_loading.value = false;
return true;
} catch (error) {
console.error('There was an error retrieving Employee Pay Period overviews: ', error);
- pay_period_overviews.value = [default_pay_period_overview,];
+ pay_period_overviews.value = [];
// TODO: More in-depth error-handling here
is_loading.value = false;
@@ -64,21 +64,17 @@ export const useTimesheetStore = defineStore('timesheet', () => {
}
};
- const getPayPeriodDetailsByEmployeeEmail = async (employee_email: string) => {
+ const getTimesheetsByEmployeeEmail = async (employee_email: string) => {
is_loading.value = true;
+ if (pay_period.value === undefined) return;
try {
- const response = await timesheetService.getPayPeriodDetailsByPayPeriodAndEmployeeEmail(
- pay_period.value.pay_year,
- pay_period.value.pay_period_no,
- employee_email
- );
- pay_period_details.value = response;
- console.log('pay period details: ', response, pay_period_details.value.employee_full_name)
+ const response = await timesheetService.getTimesheetsByPayPeriodAndEmployeeEmail(employee_email, pay_period.value.pay_year, pay_period.value.pay_period_no);
+ timesheets.value = response;
is_loading.value = false;
} catch (error) {
console.error('There was an error retrieving timesheet details for this employee: ', error);
// TODO: More in-depth error-handling here
- pay_period_details.value = default_pay_period_details;
+ timesheets.value = [];
is_loading.value = false;
}
};
@@ -109,10 +105,10 @@ export const useTimesheetStore = defineStore('timesheet', () => {
pay_period,
pay_period_overviews,
current_pay_period_overview,
- pay_period_details,
+ timesheets,
getPayPeriodByDateOrYearAndNumber,
- getPayPeriodOverviewsBySupervisorEmail,
- getPayPeriodDetailsByEmployeeEmail,
+ getTimesheetOverviewsByPayPeriod,
+ getTimesheetsByEmployeeEmail,
getPayPeriodReportByYearAndPeriodNumber,
};
});
\ No newline at end of file