mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-18 05:02:14 +01:00
add context menus to calendar view + ui package
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
||||
type CreateClientBody,
|
||||
type CreateProjectBody,
|
||||
type Project,
|
||||
type TimeEntry,
|
||||
} from '@/packages/api/src';
|
||||
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
|
||||
import { TimeEntryCalendar } from '@/packages/ui/src';
|
||||
import { isAllowedToPerformPremiumAction } from '@/utils/billing';
|
||||
import { useTagsStore } from '@/utils/useTags';
|
||||
@@ -55,6 +57,39 @@ async function deleteTimeEntry(timeEntryId: string): Promise<void> {
|
||||
await deleteTimeEntryMutation(timeEntryId);
|
||||
}
|
||||
|
||||
async function duplicateTimeEntry(entry: TimeEntry): Promise<void> {
|
||||
await createTimeEntryMutation({
|
||||
start: entry.start,
|
||||
end: entry.end,
|
||||
billable: entry.billable,
|
||||
description: entry.description,
|
||||
project_id: entry.project_id,
|
||||
task_id: entry.task_id,
|
||||
tags: entry.tags,
|
||||
});
|
||||
}
|
||||
|
||||
async function splitTimeEntry(entry: TimeEntry): Promise<void> {
|
||||
if (!entry.end) return;
|
||||
const start = getDayJsInstance()(entry.start);
|
||||
const end = getDayJsInstance()(entry.end);
|
||||
const midpoint = start.add(end.diff(start) / 2, 'millisecond').startOf('minute');
|
||||
|
||||
// Update the original entry to end at the midpoint
|
||||
await updateTimeEntryMutation({ ...entry, end: midpoint.utc().format() });
|
||||
|
||||
// Create a new entry from midpoint to original end
|
||||
await createTimeEntryMutation({
|
||||
start: midpoint.utc().format(),
|
||||
end: entry.end,
|
||||
billable: entry.billable,
|
||||
description: entry.description,
|
||||
project_id: entry.project_id,
|
||||
task_id: entry.task_id,
|
||||
tags: entry.tags,
|
||||
});
|
||||
}
|
||||
|
||||
async function createTag(name: string) {
|
||||
return await useTagsStore().createTag(name);
|
||||
}
|
||||
@@ -101,6 +136,8 @@ function onRefresh() {
|
||||
:create-time-entry="createTimeEntry"
|
||||
:update-time-entry="updateTimeEntry"
|
||||
:delete-time-entry="deleteTimeEntry"
|
||||
:duplicate-time-entry="duplicateTimeEntry"
|
||||
:split-time-entry="splitTimeEntry"
|
||||
:create-client="createClient"
|
||||
:create-project="createProject"
|
||||
:create-tag="createTag"
|
||||
|
||||
Reference in New Issue
Block a user