Skip to content

Commit

Permalink
add mass delete time entries frontend, closes ST-450
Browse files Browse the repository at this point in the history
  • Loading branch information
Onatcer committed Oct 7, 2024
1 parent e0f218e commit bfbcd3a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
48 changes: 48 additions & 0 deletions openapi.json.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,54 @@ Users with the permission `time-entries:view:own` can only use this en
},
],
},
{
method: 'delete',
path: '/v1/organizations/:organization/time-entries',
alias: 'deleteTimeEntries',
requestFormat: 'json',
parameters: [
{
name: 'organization',
type: 'Path',
schema: z.string(),
},
{
name: 'ids',
type: 'Query',
schema: z.array(z.string().uuid()),
},
],
response: z
.object({ success: z.string(), error: z.string() })
.passthrough(),
errors: [
{
status: 401,
description: `Unauthenticated`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 403,
description: `Authorization error`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 404,
description: `Not found`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 422,
description: `Validation error`,
schema: z
.object({
message: z.string(),
errors: z.record(z.array(z.string())),
})
.passthrough(),
},
],
},
{
method: 'put',
path: '/v1/organizations/:organization/time-entries/:timeEntry',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const expanded = ref(false);
class="opacity-20 hidden sm:flex group-hover:opacity-100"></TimeTrackerStartStop>
<TimeEntryMoreOptionsDropdown
@delete="
deleteTimeEntries([timeEntry])
deleteTimeEntries(timeEntry?.timeEntries ?? [])
"></TimeEntryMoreOptionsDropdown>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions resources/js/Pages/Time.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ async function startTimeEntry(
}
function deleteTimeEntries(timeEntries: TimeEntry[]) {
timeEntries.forEach((entry) => {
useTimeEntriesStore().deleteTimeEntry(entry.id);
});
useTimeEntriesStore().deleteTimeEntries(timeEntries);
fetchTimeEntries();
}
Expand Down
22 changes: 22 additions & 0 deletions resources/js/utils/useTimeEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
}
}

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,
Expand All @@ -143,5 +164,6 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
deleteTimeEntry,
fetchMoreTimeEntries,
allTimeEntriesLoaded,
deleteTimeEntries,
};
});

0 comments on commit bfbcd3a

Please sign in to comment.