mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-16 04:02:15 +01:00
fix package build error dependencies
This commit is contained in:
@@ -81,7 +81,7 @@ export const useNotificationsStore = defineStore('notifications', () => {
|
|||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
} catch {
|
} catch {
|
||||||
router.get(route('login'));
|
router.get('/login');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addNotification('error', 'The action failed. Please try again later.');
|
addNotification('error', 'The action failed. Please try again later.');
|
||||||
|
|||||||
@@ -1,225 +1,246 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { getCurrentMembershipId, getCurrentOrganizationId } from '@/utils/useUser';
|
import { getCurrentMembershipId, getCurrentOrganizationId } from '@/utils/useUser';
|
||||||
|
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref, type Ref } from 'vue';
|
||||||
import {
|
import { api } from '@/packages/api/src';
|
||||||
api,
|
import type {
|
||||||
type CreateTimeEntryBody,
|
CreateTimeEntryBody,
|
||||||
type TimeEntriesQueryParams,
|
TimeEntriesQueryParams,
|
||||||
type TimeEntry,
|
TimeEntry,
|
||||||
|
UpdateMultipleTimeEntriesChangeset,
|
||||||
} from '@/packages/api/src';
|
} from '@/packages/api/src';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useNotificationsStore } from '@/utils/notification';
|
import { useNotificationsStore } from '@/utils/notification';
|
||||||
import type { UpdateMultipleTimeEntriesChangeset } from '@/packages/api/src';
|
import type {} from '@/packages/api/src';
|
||||||
import { useQueryClient } from '@tanstack/vue-query';
|
import { useQueryClient } from '@tanstack/vue-query';
|
||||||
|
|
||||||
export const useTimeEntriesStore = defineStore('timeEntries', () => {
|
export const useTimeEntriesStore = defineStore(
|
||||||
const timeEntries = ref<TimeEntry[]>(reactive([]));
|
'timeEntries',
|
||||||
|
(): {
|
||||||
|
timeEntries: Ref<TimeEntry[]>;
|
||||||
|
fetchTimeEntries: (queryParams?: TimeEntriesQueryParams) => Promise<void>;
|
||||||
|
updateTimeEntry: (timeEntry: TimeEntry) => Promise<void>;
|
||||||
|
createTimeEntry: (timeEntry: Omit<CreateTimeEntryBody, 'member_id'>) => Promise<void>;
|
||||||
|
deleteTimeEntry: (timeEntryId: string) => Promise<void>;
|
||||||
|
fetchMoreTimeEntries: () => Promise<void>;
|
||||||
|
allTimeEntriesLoaded: Ref<boolean>;
|
||||||
|
updateTimeEntries: (
|
||||||
|
ids: string[],
|
||||||
|
changes: UpdateMultipleTimeEntriesChangeset
|
||||||
|
) => Promise<void>;
|
||||||
|
deleteTimeEntries: (timeEntries: TimeEntry[]) => Promise<void>;
|
||||||
|
patchTimeEntries: (queryParams?: TimeEntriesQueryParams) => Promise<void>;
|
||||||
|
} => {
|
||||||
|
const timeEntries = ref<TimeEntry[]>(reactive([]));
|
||||||
|
|
||||||
const allTimeEntriesLoaded = ref(false);
|
const allTimeEntriesLoaded = ref(false);
|
||||||
const { handleApiRequestNotifications } = useNotificationsStore();
|
const { handleApiRequestNotifications } = useNotificationsStore();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
async function patchTimeEntries(
|
async function patchTimeEntries(
|
||||||
queryParams: TimeEntriesQueryParams = {
|
queryParams: TimeEntriesQueryParams = {
|
||||||
only_full_dates: 'true',
|
only_full_dates: 'true',
|
||||||
member_id: getCurrentMembershipId(),
|
member_id: getCurrentMembershipId(),
|
||||||
}
|
|
||||||
) {
|
|
||||||
const organizationId = getCurrentOrganizationId();
|
|
||||||
|
|
||||||
if (organizationId) {
|
|
||||||
const timeEntriesResponse = await handleApiRequestNotifications(
|
|
||||||
() =>
|
|
||||||
api.getTimeEntries({
|
|
||||||
params: {
|
|
||||||
organization: organizationId,
|
|
||||||
},
|
|
||||||
queries: queryParams,
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
'Failed to fetch time entries'
|
|
||||||
);
|
|
||||||
if (timeEntriesResponse?.data) {
|
|
||||||
// insert missing time entries
|
|
||||||
const missingTimeEntries = timeEntriesResponse.data.filter(
|
|
||||||
(entry) => !timeEntries.value.find((e) => e.id === entry.id)
|
|
||||||
);
|
|
||||||
timeEntries.value = [...missingTimeEntries, ...timeEntries.value];
|
|
||||||
}
|
}
|
||||||
}
|
) {
|
||||||
}
|
const organizationId = getCurrentOrganizationId();
|
||||||
|
|
||||||
async function fetchTimeEntries(
|
if (organizationId) {
|
||||||
queryParams: TimeEntriesQueryParams = {
|
const timeEntriesResponse = await handleApiRequestNotifications(
|
||||||
only_full_dates: 'true',
|
() =>
|
||||||
member_id: getCurrentMembershipId(),
|
api.getTimeEntries({
|
||||||
}
|
|
||||||
) {
|
|
||||||
const organizationId = getCurrentOrganizationId();
|
|
||||||
|
|
||||||
if (organizationId) {
|
|
||||||
const timeEntriesResponse = await handleApiRequestNotifications(
|
|
||||||
() =>
|
|
||||||
api.getTimeEntries({
|
|
||||||
params: {
|
|
||||||
organization: organizationId,
|
|
||||||
},
|
|
||||||
queries: queryParams,
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
'Failed to fetch time entries'
|
|
||||||
);
|
|
||||||
if (timeEntriesResponse?.data) {
|
|
||||||
timeEntries.value = timeEntriesResponse.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchMoreTimeEntries() {
|
|
||||||
const organizationId = getCurrentOrganizationId();
|
|
||||||
if (organizationId) {
|
|
||||||
const latestTimeEntry = timeEntries.value[timeEntries.value.length - 1];
|
|
||||||
dayjs(latestTimeEntry.start).utc().format('YYYY-MM-DD');
|
|
||||||
|
|
||||||
const timeEntriesResponse = await handleApiRequestNotifications(
|
|
||||||
() =>
|
|
||||||
api.getTimeEntries({
|
|
||||||
params: {
|
|
||||||
organization: organizationId,
|
|
||||||
},
|
|
||||||
queries: {
|
|
||||||
only_full_dates: 'true',
|
|
||||||
member_id: getCurrentMembershipId(),
|
|
||||||
end: dayjs(latestTimeEntry.start).utc().format(),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
'Failed to fetch time entries'
|
|
||||||
);
|
|
||||||
if (timeEntriesResponse?.data && timeEntriesResponse.data.length > 0) {
|
|
||||||
timeEntries.value = timeEntries.value.concat(timeEntriesResponse.data);
|
|
||||||
} else {
|
|
||||||
allTimeEntriesLoaded.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateTimeEntries(ids: string[], changes: UpdateMultipleTimeEntriesChangeset) {
|
|
||||||
const organizationId = getCurrentOrganizationId();
|
|
||||||
if (organizationId) {
|
|
||||||
await handleApiRequestNotifications(
|
|
||||||
() =>
|
|
||||||
api.updateMultipleTimeEntries(
|
|
||||||
{
|
|
||||||
ids: ids,
|
|
||||||
changes: changes,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
params: {
|
params: {
|
||||||
organization: organizationId,
|
organization: organizationId,
|
||||||
},
|
},
|
||||||
}
|
queries: queryParams,
|
||||||
),
|
}),
|
||||||
'Time entries updated successfully',
|
undefined,
|
||||||
'Failed to update time entries'
|
'Failed to fetch time entries'
|
||||||
);
|
);
|
||||||
|
if (timeEntriesResponse?.data) {
|
||||||
|
// insert missing time entries
|
||||||
|
const missingTimeEntries = timeEntriesResponse.data.filter(
|
||||||
|
(entry) => !timeEntries.value.find((e) => e.id === entry.id)
|
||||||
|
);
|
||||||
|
timeEntries.value = [...missingTimeEntries, ...timeEntries.value];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function updateTimeEntry(timeEntry: TimeEntry) {
|
async function fetchTimeEntries(
|
||||||
const organizationId = getCurrentOrganizationId();
|
queryParams: TimeEntriesQueryParams = {
|
||||||
if (organizationId) {
|
only_full_dates: 'true',
|
||||||
const response = await handleApiRequestNotifications(
|
member_id: getCurrentMembershipId(),
|
||||||
() =>
|
}
|
||||||
api.updateTimeEntry(timeEntry, {
|
) {
|
||||||
params: {
|
const organizationId = getCurrentOrganizationId();
|
||||||
organization: organizationId,
|
|
||||||
timeEntry: timeEntry.id,
|
if (organizationId) {
|
||||||
},
|
const timeEntriesResponse = await handleApiRequestNotifications(
|
||||||
}),
|
() =>
|
||||||
'Time entry updated successfully',
|
api.getTimeEntries({
|
||||||
'Failed to update time entry'
|
params: {
|
||||||
);
|
organization: organizationId,
|
||||||
timeEntries.value = timeEntries.value.map((entry) =>
|
},
|
||||||
entry.id === timeEntry.id ? response.data : entry
|
queries: queryParams,
|
||||||
);
|
}),
|
||||||
queryClient.invalidateQueries({ queryKey: ['timeEntry'] });
|
undefined,
|
||||||
|
'Failed to fetch time entries'
|
||||||
|
);
|
||||||
|
if (timeEntriesResponse?.data) {
|
||||||
|
timeEntries.value = timeEntriesResponse.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function createTimeEntry(timeEntry: Omit<CreateTimeEntryBody, 'member_id'>) {
|
async function fetchMoreTimeEntries() {
|
||||||
const organizationId = getCurrentOrganizationId();
|
const organizationId = getCurrentOrganizationId();
|
||||||
const memberId = getCurrentMembershipId();
|
if (organizationId) {
|
||||||
if (organizationId && memberId !== undefined) {
|
const latestTimeEntry = timeEntries.value[timeEntries.value.length - 1];
|
||||||
const newTimeEntry = {
|
dayjs(latestTimeEntry.start).utc().format('YYYY-MM-DD');
|
||||||
...timeEntry,
|
|
||||||
member_id: memberId,
|
const timeEntriesResponse = await handleApiRequestNotifications(
|
||||||
} as CreateTimeEntryBody;
|
() =>
|
||||||
await handleApiRequestNotifications(
|
api.getTimeEntries({
|
||||||
() =>
|
params: {
|
||||||
api.createTimeEntry(newTimeEntry, {
|
organization: organizationId,
|
||||||
params: {
|
},
|
||||||
organization: organizationId,
|
queries: {
|
||||||
},
|
only_full_dates: 'true',
|
||||||
}),
|
member_id: getCurrentMembershipId(),
|
||||||
'Time entry created successfully',
|
end: dayjs(latestTimeEntry.start).utc().format(),
|
||||||
'Failed to create time entry'
|
},
|
||||||
);
|
}),
|
||||||
await fetchTimeEntries();
|
undefined,
|
||||||
|
'Failed to fetch time entries'
|
||||||
|
);
|
||||||
|
if (timeEntriesResponse?.data && timeEntriesResponse.data.length > 0) {
|
||||||
|
timeEntries.value = timeEntries.value.concat(timeEntriesResponse.data);
|
||||||
|
} else {
|
||||||
|
allTimeEntriesLoaded.value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteTimeEntry(timeEntryId: string) {
|
async function updateTimeEntries(
|
||||||
const organizationId = getCurrentOrganizationId();
|
ids: string[],
|
||||||
if (organizationId) {
|
changes: UpdateMultipleTimeEntriesChangeset
|
||||||
await handleApiRequestNotifications(
|
) {
|
||||||
() =>
|
const organizationId = getCurrentOrganizationId();
|
||||||
api.deleteTimeEntry(undefined, {
|
if (organizationId) {
|
||||||
params: {
|
await handleApiRequestNotifications(
|
||||||
organization: organizationId,
|
() =>
|
||||||
timeEntry: timeEntryId,
|
api.updateMultipleTimeEntries(
|
||||||
},
|
{
|
||||||
}),
|
ids: ids,
|
||||||
'Time entry deleted successfully',
|
changes: changes,
|
||||||
'Failed to delete time entry'
|
},
|
||||||
);
|
{
|
||||||
await fetchTimeEntries();
|
params: {
|
||||||
|
organization: organizationId,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
'Time entries updated successfully',
|
||||||
|
'Failed to update time entries'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteTimeEntries(timeEntries: TimeEntry[]) {
|
async function updateTimeEntry(timeEntry: TimeEntry) {
|
||||||
const organizationId = getCurrentOrganizationId();
|
const organizationId = getCurrentOrganizationId();
|
||||||
const timeEntryIds = timeEntries.map((entry) => entry.id);
|
if (organizationId) {
|
||||||
if (organizationId) {
|
const response = await handleApiRequestNotifications(
|
||||||
await handleApiRequestNotifications(
|
() =>
|
||||||
() =>
|
api.updateTimeEntry(timeEntry, {
|
||||||
api.deleteTimeEntries(undefined, {
|
params: {
|
||||||
queries: {
|
organization: organizationId,
|
||||||
ids: timeEntryIds,
|
timeEntry: timeEntry.id,
|
||||||
},
|
},
|
||||||
params: {
|
}),
|
||||||
organization: organizationId,
|
'Time entry updated successfully',
|
||||||
},
|
'Failed to update time entry'
|
||||||
}),
|
);
|
||||||
'Time entries deleted successfully',
|
timeEntries.value = timeEntries.value.map((entry) =>
|
||||||
'Failed to delete time entries'
|
entry.id === timeEntry.id ? response.data : entry
|
||||||
);
|
);
|
||||||
await fetchTimeEntries();
|
queryClient.invalidateQueries({ queryKey: ['timeEntry'] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
async function createTimeEntry(timeEntry: Omit<CreateTimeEntryBody, 'member_id'>) {
|
||||||
timeEntries,
|
const organizationId = getCurrentOrganizationId();
|
||||||
fetchTimeEntries,
|
const memberId = getCurrentMembershipId();
|
||||||
updateTimeEntry,
|
if (organizationId && memberId !== undefined) {
|
||||||
createTimeEntry,
|
const newTimeEntry = {
|
||||||
deleteTimeEntry,
|
...timeEntry,
|
||||||
fetchMoreTimeEntries,
|
member_id: memberId,
|
||||||
allTimeEntriesLoaded,
|
} as CreateTimeEntryBody;
|
||||||
updateTimeEntries,
|
await handleApiRequestNotifications(
|
||||||
deleteTimeEntries,
|
() =>
|
||||||
patchTimeEntries,
|
api.createTimeEntry(newTimeEntry, {
|
||||||
};
|
params: {
|
||||||
});
|
organization: organizationId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
'Time entry created successfully',
|
||||||
|
'Failed to create time entry'
|
||||||
|
);
|
||||||
|
await fetchTimeEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteTimeEntry(timeEntryId: string) {
|
||||||
|
const organizationId = getCurrentOrganizationId();
|
||||||
|
if (organizationId) {
|
||||||
|
await handleApiRequestNotifications(
|
||||||
|
() =>
|
||||||
|
api.deleteTimeEntry(undefined, {
|
||||||
|
params: {
|
||||||
|
organization: organizationId,
|
||||||
|
timeEntry: timeEntryId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
'Time entry deleted successfully',
|
||||||
|
'Failed to delete time entry'
|
||||||
|
);
|
||||||
|
await fetchTimeEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteTimeEntries(timeEntries: TimeEntry[]) {
|
||||||
|
const organizationId = getCurrentOrganizationId();
|
||||||
|
const timeEntryIds = timeEntries.map((entry) => entry.id);
|
||||||
|
if (organizationId) {
|
||||||
|
await handleApiRequestNotifications(
|
||||||
|
() =>
|
||||||
|
api.deleteTimeEntries(undefined, {
|
||||||
|
queries: {
|
||||||
|
ids: timeEntryIds,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
organization: organizationId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
'Time entries deleted successfully',
|
||||||
|
'Failed to delete time entries'
|
||||||
|
);
|
||||||
|
await fetchTimeEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timeEntries,
|
||||||
|
fetchTimeEntries,
|
||||||
|
updateTimeEntry,
|
||||||
|
createTimeEntry,
|
||||||
|
deleteTimeEntry,
|
||||||
|
fetchMoreTimeEntries,
|
||||||
|
allTimeEntriesLoaded,
|
||||||
|
updateTimeEntries,
|
||||||
|
deleteTimeEntries,
|
||||||
|
patchTimeEntries,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user