Change timesheet UI to better fit current app model and avoid adding extra clicks and interactions to add new shifts and expenses. Also refactoring calls to backend to be more efficient and use recently-finalized OIDC implementation and integration.
69 lines
3.0 KiB
TypeScript
69 lines
3.0 KiB
TypeScript
import { useTimesheetStore } from "src/stores/timesheet-store";
|
|
import { useAuthStore } from "src/stores/auth-store";
|
|
import type { TimesheetApprovalCSVReportFilters } from "src/modules/timesheet-approval/models/timesheet-approval-csv-report.models";
|
|
import { NavigatorConstants } from "src/modules/timesheet-approval/models/timesheet-overview.models";
|
|
|
|
export const useTimesheetApprovalApi = () => {
|
|
const timesheet_store = useTimesheetStore();
|
|
const auth_store = useAuthStore();
|
|
|
|
const getPayPeriodOverviewsByDateOrYearAndNumber = async (date_or_year: string | number, period_number?: number): Promise<void> => {
|
|
let success = false;
|
|
if (typeof date_or_year === 'string') success = await timesheet_store.getPayPeriodByDateOrYearAndNumber(date_or_year);
|
|
else if (typeof date_or_year === 'number' && period_number) success = await timesheet_store.getPayPeriodByDateOrYearAndNumber(date_or_year, period_number);
|
|
|
|
if (success) {
|
|
await timesheet_store.getTimesheetOverviewsByPayPeriod(
|
|
timesheet_store.pay_period?.pay_year ?? 1,
|
|
timesheet_store.pay_period?.pay_period_no ?? 1,
|
|
auth_store.user?.email
|
|
);
|
|
}
|
|
};
|
|
|
|
const getNextOrPreviousPayPeriodOverview = async (direction: number) => {
|
|
if (timesheet_store.pay_period === undefined) return;
|
|
|
|
let new_period_number = (timesheet_store.pay_period.pay_period_no) + direction;
|
|
let new_year = timesheet_store.pay_period.pay_year;
|
|
|
|
if ( new_period_number > 26 || new_period_number < 1) {
|
|
new_period_number = 1;
|
|
new_year += direction;
|
|
}
|
|
|
|
await getPayPeriodOverviewsByDateOrYearAndNumber(new_year, new_period_number);
|
|
};
|
|
|
|
const getNextPayPeriodOverview = async () => {
|
|
await getNextOrPreviousPayPeriodOverview(NavigatorConstants.NEXT_PERIOD);
|
|
};
|
|
|
|
const getPreviousPayPeriodOverview = async () => {
|
|
await getNextOrPreviousPayPeriodOverview(NavigatorConstants.PREVIOUS_PERIOD);
|
|
};
|
|
|
|
const getTimesheetApprovalCSVReport = async ( report_filter_company: boolean[], report_filter_type: boolean[], year?: number, period_number?: number ) => {
|
|
if (timesheet_store.pay_period === undefined) return;
|
|
|
|
const [ targo, solucom ] = report_filter_company;
|
|
const [ shifts, expenses, holiday, vacation ] = report_filter_type;
|
|
const options = {
|
|
types: { shifts, expenses, holiday, vacation },
|
|
companies: { targo, solucom },
|
|
} as TimesheetApprovalCSVReportFilters;
|
|
|
|
await timesheet_store.getPayPeriodReportByYearAndPeriodNumber(
|
|
year ?? timesheet_store.pay_period.pay_year,
|
|
period_number ?? timesheet_store.pay_period.pay_period_no,
|
|
options
|
|
);
|
|
};
|
|
|
|
return {
|
|
getPayPeriodOverviewsByDateOrYearAndNumber,
|
|
getTimesheetApprovalCSVReport,
|
|
getNextPayPeriodOverview,
|
|
getPreviousPayPeriodOverview,
|
|
}
|
|
}; |