From a14b93501c742ad2e113f8c8acbe09f83e05e8bc Mon Sep 17 00:00:00 2001 From: Innocent-akim Date: Mon, 9 Dec 2024 13:48:44 +0200 Subject: [PATCH 1/2] fix: update timesheet functionality and load all projects --- .../[memberId]/components/AddTaskModal.tsx | 8 ++- .../[memberId]/components/CalendarView.tsx | 6 +- .../components/CompactTimesheetComponent.tsx | 4 +- .../[memberId]/components/EditTaskModal.tsx | 62 ++++++++++++++----- .../components/FilterWithStatus.tsx | 3 +- .../components/TimeSheetFilterPopover.tsx | 8 ++- .../[memberId]/components/TimesheetCard.tsx | 2 +- .../[locale]/timesheet/[memberId]/page.tsx | 8 ++- apps/web/app/hooks/features/useTimesheet.ts | 2 +- apps/web/lib/components/Kanban.tsx | 8 +-- 10 files changed, 73 insertions(+), 38 deletions(-) diff --git a/apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx b/apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx index ca450efd9..514305b6c 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { useTeamTasks, useTimelogFilterOptions } from '@/app/hooks'; +import { useOrganizationProjects, useTimelogFilterOptions } from '@/app/hooks'; import { ITaskIssue } from '@/app/interfaces'; import { clsxm } from '@/app/utils'; import { Modal } from '@/lib/components' @@ -17,20 +17,22 @@ export interface IAddTaskModalProps { } export function AddTaskModal({ closeModal, isOpen }: IAddTaskModalProps) { const { generateTimeOptions } = useTimelogFilterOptions(); + const { organizationProjects } = useOrganizationProjects(); + const timeOptions = generateTimeOptions(15); const t = useTranslations(); - const { activeTeam } = useTeamTasks(); const [notes, setNotes] = React.useState(''); const [task, setTasks] = React.useState('') const [isBillable, setIsBillable] = React.useState(true); const [dateRange, setDateRange] = React.useState<{ from: Date | null }>({ from: new Date(), }); + const handleFromChange = (fromDate: Date | null) => { setDateRange((prev) => ({ ...prev, from: fromDate })); }; const projectItemsLists = { - Project: activeTeam?.projects ?? [], + Project: organizationProjects ?? [], }; const handleSelectedValuesChange = (values: { [key: string]: Item | null }) => { diff --git a/apps/web/app/[locale]/timesheet/[memberId]/components/CalendarView.tsx b/apps/web/app/[locale]/timesheet/[memberId]/components/CalendarView.tsx index 686961708..6d31d52e8 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/components/CalendarView.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/components/CalendarView.tsx @@ -102,7 +102,7 @@ const CalendarDataView = ({ data, t }: { data?: GroupedTimesheet[], t: Translati
- + {status === 'DENIED' ? 'REJECTED' : status} ({rows.length}) @@ -141,7 +141,7 @@ const CalendarDataView = ({ data, t }: { data?: GroupedTimesheet[], t: Translati ( ); -const ImageWithLoader = ({ imageUrl, alt, className = "w-6 h-6 rounded-full" }: +const ImageWithLoader = ({ imageUrl, alt, className = "w-6 h-6 rounded-full font-bold" }: { imageUrl: string; alt: string; className?: string }) => { const [isLoading, setIsLoading] = React.useState(true); return (
{isLoading && (
- +
)} ({ date: dataTimesheet.timesheet?.startedAt ? new Date(dataTimesheet.timesheet.startedAt) : new Date(), @@ -45,13 +48,12 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo })); }; const [timesheetData, setTimesheetData] = useState({ - isBillable: dataTimesheet.isBillable, + isBillable: dataTimesheet.isBillable ?? true, projectId: dataTimesheet.project?.id || '', notes: dataTimesheet.description || '', }); - const memberItemsLists = { - Project: activeTeam?.projects as [], + Project: organizationProjects, }; const handleSelectedValuesChange = (values: { [key: string]: Item | null }) => { setTimesheetData((prev) => ({ @@ -60,7 +62,7 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo })); }; const selectedValues = { - Teams: null, + Project: dataTimesheet.project, }; const handleChange = (field: string, selectedItem: Item | null) => { // Handle field changes @@ -94,19 +96,40 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo ...timeRange.endTime.split(':').map(Number) ) ); - await updateTimesheet({ - id: dataTimesheet.timesheetId, + const payload = { + id: dataTimesheet.id, isBillable: timesheetData.isBillable, employeeId: dataTimesheet.employeeId, logType: dataTimesheet.logType, source: dataTimesheet.source, - startedAt: startedAt, - stoppedAt: stoppedAt, + startedAt, + stoppedAt, tenantId: dataTimesheet.tenantId, organizationId: dataTimesheet.organizationId, description: timesheetData.notes, projectId: timesheetData.projectId, - }); + organizationTeamId: dataTimesheet.organizationTeamId ?? null, + organizationContactId: dataTimesheet.organizationContactId ?? null, + } + updateTimesheet({ ...payload }) + .then(() => { + toast({ + title: 'Modification Confirmed', + description: "The timesheet has been successfully modified.", + variant: 'default', + className: 'bg-green-50 text-green-600 border-green-500 z-[10000px]', + action: Undo + }); + closeModal() + }).catch((error) => { + toast({ + title: 'Error during modification', + description: `An error occurred: ${error}. The timesheet could not be modified.`, + variant: 'destructive', + className: 'bg-red-50 text-red-600 border-red-500 z-[10000px]' + }); + closeModal() + }); }, [dateRange, timeRange, timesheetData, dataTimesheet, updateTimesheet]); const fields = [ @@ -137,8 +160,8 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo
* - getNestedValue(item, displayKey) || ''} @@ -278,16 +301,21 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo
diff --git a/apps/web/app/[locale]/timesheet/[memberId]/components/FilterWithStatus.tsx b/apps/web/app/[locale]/timesheet/[memberId]/components/FilterWithStatus.tsx index 8e4c98a06..48834ec8a 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/components/FilterWithStatus.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/components/FilterWithStatus.tsx @@ -51,8 +51,7 @@ export function FilterWithStatus({ className={clsxm( 'flex flex-nowrap h-[2.2rem] items-center bg-[#e2e8f0aa] dark:bg-gray-800 rounded-xl ', className - )} - > + )}> {buttonData.map(({ label, count, icon }, index) => (
{ const { toggleColumn } = useKanban(); const { isOpen, closeModal, openModal } = useModal(); - + const t = useTranslations() return ( <> {title && ( @@ -417,7 +417,7 @@ const KanbanDraggableHeader = ({ className="hover:font-medium p-1.5 text-sm cursor-pointer" onClick={() => createTask()} > - Create Task + {t('common.CREATE_TASK')}
Date: Mon, 9 Dec 2024 13:54:21 +0200 Subject: [PATCH 2/2] fix: cspell --- .../[locale]/timesheet/[memberId]/components/EditTaskModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx b/apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx index b0971fbc3..39c21ffcc 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx @@ -231,7 +231,7 @@ export function EditTaskModal({ isOpen, closeModal, dataTimesheet }: IEditTaskMo fields={fields} itemsLists={memberItemsLists} - selectedValues={selectedValues ?? []} + selectedValues={selectedValues} onSelectedValuesChange={handleSelectedValuesChange} handleChange={handleChange} itemToString={(item, displayKey) => getNestedValue(item, displayKey) || ''}