feat(timesheet): add manual time entry action
This commit is contained in:
@@ -682,6 +682,7 @@ export const en = {
|
||||
description: (workspaceName: string) => `Track time inside ${workspaceName}`,
|
||||
selectWorkspace: "Please select a workspace first.",
|
||||
addEntry: "Add Entry",
|
||||
addManualEntry: "Add manual entry",
|
||||
startTimer: "Start Timer",
|
||||
stopTimer: "Stop Timer",
|
||||
timerRunning: "Timer Running",
|
||||
@@ -696,6 +697,7 @@ export const en = {
|
||||
noEntriesSearch: "Try adjusting your search query or filters.",
|
||||
emptyDescription: "No description",
|
||||
createTitle: "Add Time Entry",
|
||||
manualCreateTitle: "Add Manual Time Entry",
|
||||
startTitle: "Start Timer",
|
||||
editTitle: "Edit Time Entry",
|
||||
createSuccess: "Time entry created successfully.",
|
||||
|
||||
@@ -679,6 +679,7 @@ export const fa = {
|
||||
description: (workspaceName: string) => `ثبت زمان در ${workspaceName}`,
|
||||
selectWorkspace: "لطفاً ابتدا یک ورکاسپیس انتخاب کنید.",
|
||||
addEntry: "افزودن ورودی",
|
||||
addManualEntry: "افزودن دستی زمان",
|
||||
startTimer: "شروع تایمر",
|
||||
stopTimer: "توقف تایمر",
|
||||
timerRunning: "تایمر فعال است",
|
||||
@@ -693,6 +694,7 @@ export const fa = {
|
||||
emptyStateDescription: "برای شروع، تایمر را اجرا کنید یا یک ورودی دستی اضافه کنید.",
|
||||
noEntriesSearch: "عبارت جستوجو یا فیلترهای خود را تغییر دهید.",
|
||||
createTitle: "افزودن ورودی زمان",
|
||||
manualCreateTitle: "افزودن دستی زمان",
|
||||
startTitle: "شروع تایمر",
|
||||
editTitle: "ویرایش ورودی زمان",
|
||||
createSuccess: "ورودی زمان با موفقیت ایجاد شد.",
|
||||
|
||||
@@ -404,11 +404,17 @@ const updateGroupedHistoryEntry = (
|
||||
|
||||
const buildEntryFormState = (entry?: TimeEntry | null): EntryFormState => {
|
||||
if (!entry) {
|
||||
const now = getLocalDateParts(new Date().toISOString());
|
||||
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: now.date,
|
||||
startTime: now.time,
|
||||
startDate: start.date,
|
||||
startTime: start.time,
|
||||
endDate: end.date,
|
||||
endTime: 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.",
|
||||
@@ -475,6 +486,9 @@ const buildPayloadFromState = (
|
||||
|
||||
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,10 +2885,16 @@ 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 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
|
||||
@@ -3213,7 +3234,11 @@ export default function Timesheet() {
|
||||
<Modal
|
||||
isOpen={modalMode === "manual" || modalMode === "edit"}
|
||||
onClose={closeCreateModal}
|
||||
title={modalMode === "edit" ? (t.timesheet?.editTitle || "Edit Time Entry") : (t.timesheet?.createTitle || "Add Time Entry")}
|
||||
title={
|
||||
modalMode === "edit"
|
||||
? (t.timesheet?.editTitle || "Edit Time Entry")
|
||||
: (t.timesheet?.manualCreateTitle || t.timesheet?.createTitle || "Add Manual Time Entry")
|
||||
}
|
||||
maxWidth="max-w-2xl"
|
||||
footer={
|
||||
<>
|
||||
@@ -3221,7 +3246,7 @@ export default function Timesheet() {
|
||||
{t.actions?.cancel || "Cancel"}
|
||||
</Button>
|
||||
<Button type="submit" form="time-entry-modal-form" disabled={isSaving}>
|
||||
{isSaving ? "..." : (modalMode === "edit" ? (t.save || "Save") : (t.create || "Create"))}
|
||||
{isSaving ? "..." : (modalMode === "edit" ? (t.save || "Save") : (t.timesheet?.addManualEntry || t.create || "Add manual entry"))}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user