feat(timesheet): add manual time entry action
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled

This commit is contained in:
2026-06-18 22:59:04 +03:30
parent 55ba274346
commit c7ede31b68
3 changed files with 65 additions and 36 deletions

View File

@@ -402,15 +402,21 @@ const updateGroupedHistoryEntry = (
return merged;
};
const buildEntryFormState = (entry?: TimeEntry | null): EntryFormState => {
if (!entry) {
const now = getLocalDateParts(new Date().toISOString());
return {
...EMPTY_FORM,
startDate: now.date,
startTime: now.time,
};
}
const buildEntryFormState = (entry?: TimeEntry | null): EntryFormState => {
if (!entry) {
const endDate = new Date();
const startDate = new Date(endDate);
startDate.setHours(startDate.getHours() - 1);
const start = getLocalDateParts(startDate.toISOString());
const end = getLocalDateParts(endDate.toISOString());
return {
...EMPTY_FORM,
startDate: start.date,
startTime: start.time,
endDate: end.date,
endTime: end.time,
};
}
const start = getLocalDateParts(entry.start_time);
const end = getLocalDateParts(entry.end_time);
@@ -459,7 +465,12 @@ const toggleTagId = (currentTags: string[], tagId: string) =>
const buildPayloadFromState = (
state: EntryFormState,
options: { includeWorkspace: boolean; workspaceId?: string; messages?: Partial<Record<"startRequired" | "endRequired" | "invalidEndTime" | "endBeforeStart", string>> },
options: {
includeWorkspace: boolean;
workspaceId?: string;
requireEnd?: boolean;
messages?: Partial<Record<"startRequired" | "endRequired" | "invalidEndTime" | "endBeforeStart", string>>;
},
): { payload?: TimeEntryPayload; error?: string } => {
const messages = {
startRequired: "Start date and time are required.",
@@ -473,9 +484,12 @@ const buildPayloadFromState = (
return { error: messages.startRequired };
}
let endDateTime: string | null = null;
const hasEndValue = Boolean(state.endDate || state.endTime);
if (hasEndValue) {
let endDateTime: string | null = null;
const hasEndValue = Boolean(state.endDate || state.endTime);
if (options.requireEnd && !hasEndValue) {
return { error: messages.endRequired };
}
if (hasEndValue) {
if (!state.endDate || !state.endTime) {
return { error: messages.endRequired };
}
@@ -2587,6 +2601,7 @@ export default function Timesheet() {
const { payload, error } = buildPayloadFromState(formState, {
includeWorkspace: modalMode === "manual",
workspaceId: activeWorkspace?.id,
requireEnd: modalMode === "manual",
messages: entryValidationMessages,
});
@@ -2870,11 +2885,17 @@ export default function Timesheet() {
<h1 className="text-2xl font-bold text-slate-900 dark:text-white">{t.timesheet?.title || 'Timesheets'}</h1>
<p className="text-slate-500 dark:text-slate-400 mt-1">{t.timesheet?.description(activeWorkspace?.name || "-") || 'Manage your Timesheet'}</p>
</div>
<Button type="button" variant="secondary" onClick={() => void openRatesPanel()} className="gap-2">
<Banknote className="h-4 w-4" />
{t.rates?.myRatesTitle || "My rates"}
</Button>
</div>
<div className="flex flex-wrap gap-2">
<Button type="button" onClick={openCreateModal} className="gap-2">
<Plus className="h-4 w-4" />
{t.timesheet?.addManualEntry || t.timesheet?.addEntry || "Add manual entry"}
</Button>
<Button type="button" variant="secondary" onClick={() => void openRatesPanel()} className="gap-2">
<Banknote className="h-4 w-4" />
{t.rates?.myRatesTitle || "My rates"}
</Button>
</div>
</div>
<div
ref={desktopTimerRef}
@@ -3210,21 +3231,25 @@ export default function Timesheet() {
</InfiniteScroll>
)}
<Modal
isOpen={modalMode === "manual" || modalMode === "edit"}
onClose={closeCreateModal}
title={modalMode === "edit" ? (t.timesheet?.editTitle || "Edit Time Entry") : (t.timesheet?.createTitle || "Add Time Entry")}
maxWidth="max-w-2xl"
footer={
<Modal
isOpen={modalMode === "manual" || modalMode === "edit"}
onClose={closeCreateModal}
title={
modalMode === "edit"
? (t.timesheet?.editTitle || "Edit Time Entry")
: (t.timesheet?.manualCreateTitle || t.timesheet?.createTitle || "Add Manual Time Entry")
}
maxWidth="max-w-2xl"
footer={
<>
<Button variant="secondary" onClick={closeCreateModal}>
{t.actions?.cancel || "Cancel"}
</Button>
<Button type="submit" form="time-entry-modal-form" disabled={isSaving}>
{isSaving ? "..." : (modalMode === "edit" ? (t.save || "Save") : (t.create || "Create"))}
</Button>
</>
}
<Button type="submit" form="time-entry-modal-form" disabled={isSaving}>
{isSaving ? "..." : (modalMode === "edit" ? (t.save || "Save") : (t.timesheet?.addManualEntry || t.create || "Add manual entry"))}
</Button>
</>
}
>
<form id="time-entry-modal-form" onSubmit={handleSaveEntryModal}>
<EntryEditorFields