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 8, 2024
1 parent c777b48 commit 10875fa
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
4 changes: 1 addition & 3 deletions resources/js/Pages/Time.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ async function startTimeEntry(
}
function deleteTimeEntries(timeEntries: TimeEntry[]) {
timeEntries.forEach((entry) => {
useTimeEntriesStore().deleteTimeEntry(entry.id);
});
useTimeEntriesStore().deleteTimeEntries(timeEntries);
fetchTimeEntries();
}
Expand Down
48 changes: 48 additions & 0 deletions resources/js/packages/api/src/openapi.json.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,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 @@ -142,7 +142,7 @@ const expanded = ref(false);
class="opacity-20 hidden sm:flex group-hover:opacity-100"></TimeTrackerStartStop>
<TimeEntryMoreOptionsDropdown
@delete="
deleteTimeEntries(timeEntry.timeEntries)
deleteTimeEntries(timeEntry?.timeEntries ?? [])
"></TimeEntryMoreOptionsDropdown>
</div>
</div>
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 @@ -168,6 +168,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 @@ -177,5 +198,6 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
fetchMoreTimeEntries,
allTimeEntriesLoaded,
updateTimeEntries,
deleteTimeEntries,
};
});

0 comments on commit 10875fa

Please sign in to comment.