refactor timetracker to seperate data and ui logic

This commit is contained in:
Gregor Vostrak
2024-07-22 17:56:51 +02:00
parent a9c874e540
commit 06fef6e40f
41 changed files with 1984 additions and 961 deletions

View File

@@ -128,6 +128,13 @@ export type UpdateOrganizationBody = ZodiosBodyByAlias<
'updateOrganization'
>;
export type MyMemberships = ZodiosResponseByAlias<
SolidTimeApi,
'getMyMemberships'
>['data'];
export type MyMembership = MyMemberships[0];
export async function fetchToken() {
return new Promise((resolve) => {
router.reload({

View File

@@ -90,7 +90,7 @@ export const useNotificationsStore = defineStore('notifications', () => {
);
}
}
throw new Error('Failed to handle API request', { cause: error });
throw new Error('Failed to handle API request');
}
}

View File

@@ -76,15 +76,12 @@ export const useClientsStore = defineStore('clients', () => {
if (organization) {
await handleApiRequestNotifications(
() =>
api.deleteClient(
{},
{
params: {
organization: organization,
client: clientId,
},
}
),
api.deleteClient(undefined, {
params: {
organization: organization,
client: clientId,
},
}),
'Client deleted successfully',
'Failed to delete client'
);

View File

@@ -36,15 +36,12 @@ export const useMembersStore = defineStore('members', () => {
if (organization) {
await handleApiRequestNotifications(
() =>
api.removeMember(
{},
{
params: {
organization: organization,
member: membershipId,
},
}
),
api.removeMember(undefined, {
params: {
organization: organization,
member: membershipId,
},
}),
'Member deleted successfully',
'Failed to delete member'
);

View File

@@ -81,15 +81,12 @@ export const useProjectMembersStore = defineStore('project-members', () => {
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteProjectMember(
{},
{
params: {
organization: organizationId,
projectMember: projectMemberId,
},
}
),
api.deleteProjectMember(undefined, {
params: {
organization: organizationId,
projectMember: projectMemberId,
},
}),
'Project member removed successfully',
'Failed to remove project member'
);

View File

@@ -37,7 +37,7 @@ export const useProjectsStore = defineStore('projects', () => {
async function createProject(projectBody: CreateProjectBody) {
const organization = getCurrentOrganizationId();
if (organization) {
await handleApiRequestNotifications(
const response = await handleApiRequestNotifications(
() =>
api.createProject(projectBody, {
params: {
@@ -49,6 +49,7 @@ export const useProjectsStore = defineStore('projects', () => {
);
await fetchProjects();
return response['data'];
}
}
@@ -57,15 +58,12 @@ export const useProjectsStore = defineStore('projects', () => {
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteProject(
{},
{
params: {
organization: organizationId,
project: projectId,
},
}
),
api.deleteProject(undefined, {
params: {
organization: organizationId,
project: projectId,
},
}),
'Project deleted successfully',
'Failed to delete project'
);

View File

@@ -36,15 +36,12 @@ export const useTagsStore = defineStore('tags', () => {
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteTag(
{},
{
params: {
organization: organizationId,
tag: tagId,
},
}
),
api.deleteTag(undefined, {
params: {
organization: organizationId,
tag: tagId,
},
}),
'Tag deleted successfully',
'Failed to delete tag'
);

View File

@@ -68,15 +68,12 @@ export const useTasksStore = defineStore('tasks', () => {
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteTask(
{},
{
params: {
organization: organizationId,
task: taskId,
},
}
),
api.deleteTask(undefined, {
params: {
organization: organizationId,
task: taskId,
},
}),
'Task deleted successfully',
'Failed to delete task'
);

View File

@@ -9,8 +9,6 @@ import type { CreateTimeEntryBody, TimeEntry } from '@/utils/api';
import dayjs from 'dayjs';
import { useNotificationsStore } from '@/utils/notification';
export type TimeEntriesGroupedByType = TimeEntry & { timeEntries: TimeEntry[] };
export const useTimeEntriesStore = defineStore('timeEntries', () => {
const timeEntries = ref<TimeEntry[]>(reactive([]));
@@ -124,15 +122,12 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteTimeEntry(
{},
{
params: {
organization: organizationId,
timeEntry: timeEntryId,
},
}
),
api.deleteTimeEntry(undefined, {
params: {
organization: organizationId,
timeEntry: timeEntryId,
},
}),
'Time entry deleted successfully',
'Failed to delete time entry'
);