From 4d7bf5f68b92fe64c62a7f106113562c75c27216 Mon Sep 17 00:00:00 2001
From: AKILIMAILI CIZUNGU Innocent
<51681130+Innocent-Akim@users.noreply.github.com>
Date: Sat, 7 Sep 2024 08:37:42 +0200
Subject: [PATCH] [Feat]: Adapt ManageOrMemberComponent to new design with
dynamic fields and combobox (#2988)
* feat: adapt ManageOrMemberComponent to new design with dynamic fields and comboboxes
* fix: cspell
---
apps/web/app/[locale]/calendar/page.tsx | 1 +
apps/web/lib/components/combobox/index.tsx | 33 ++---
.../manual-time/add-manual-time-modal.tsx | 119 +++++++++------
.../manual-time/manage-member-component.tsx | 139 ++++++++++++++++++
4 files changed, 227 insertions(+), 65 deletions(-)
create mode 100644 apps/web/lib/features/manual-time/manage-member-component.tsx
diff --git a/apps/web/app/[locale]/calendar/page.tsx b/apps/web/app/[locale]/calendar/page.tsx
index dadeaf474..5bf66af03 100644
--- a/apps/web/app/[locale]/calendar/page.tsx
+++ b/apps/web/app/[locale]/calendar/page.tsx
@@ -61,6 +61,7 @@ const CalendarPage = () => {
closeModal={closeManualTimeModal}
isOpen={isManualTimeModalOpen}
params='AddManuelTime'
+ timeSheetStatus='ManagerTimesheet'
/>
{
onChangeValue?: (value: T | null) => void
className?: string
popoverClassName?: string
+ selectedItem?: T | null
}
-/**
- *
- *
- * @export
- * @template T
- * @param {ComboboxProps
} {
- * items,
- * itemToString,
- * itemToValue,
- * placeholder = "Select item...",
- * buttonWidth = "w-[200px]",
- * commandInputHeight = "h-9",
- * noResultsText = "No item found.",
- * onChangeValue,
- * className,
- * popoverClassName
- * }
- * @return {*}
- */
+
export function CustomCombobox({
items,
itemToString,
@@ -59,10 +41,11 @@ export function CustomCombobox({
noResultsText = "No item found.",
onChangeValue,
className,
- popoverClassName
+ popoverClassName,
+ selectedItem = null
}: ComboboxProps) {
const [open, setOpen] = React.useState(false)
- const [value, setValue] = React.useState(null)
+ const [value, setValue] = React.useState(selectedItem)
const [popoverWidth, setPopoverWidth] = React.useState(null);
const triggerRef = React.useRef(null);
@@ -80,6 +63,12 @@ export function CustomCombobox({
setPopoverWidth(triggerRef.current.offsetWidth);
}
}, [triggerRef.current]);
+
+
+ React.useEffect(() => {
+ setValue(selectedItem);
+ }, [selectedItem]);
+
return (
diff --git a/apps/web/lib/features/manual-time/add-manual-time-modal.tsx b/apps/web/lib/features/manual-time/add-manual-time-modal.tsx
index c2b4ee861..faf7c9506 100644
--- a/apps/web/lib/features/manual-time/add-manual-time-modal.tsx
+++ b/apps/web/lib/features/manual-time/add-manual-time-modal.tsx
@@ -14,6 +14,7 @@ import { IAddManualTimeRequest } from '@app/interfaces/timer/ITimerLogs';
import { cn } from 'lib/utils';
import { CalendarDays } from 'lucide-react';
import { IoTime } from 'react-icons/io5';
+import { Item, ManageOrMemberComponent, getNestedValue } from './manage-member-component';
/**
* Interface for the properties of the `AddManualTimeModal` component.
@@ -29,11 +30,12 @@ import { IoTime } from 'react-icons/io5';
interface IAddManualTimeModalProps {
isOpen: boolean;
params: "AddManuelTime" | "AddTime";
+ timeSheetStatus?: "ManagerTimesheet" | "TeamMemberTimesheet",
closeModal: () => void;
}
export function AddManualTimeModal(props: IAddManualTimeModalProps) {
- const { closeModal, isOpen, params } = props;
+ const { closeModal, isOpen, params, timeSheetStatus } = props;
const t = useTranslations();
const [isBillable, setIsBillable] = useState(false);
const [description, setDescription] = useState('');
@@ -45,7 +47,6 @@ export function AddManualTimeModal(props: IAddManualTimeModalProps) {
const [team, setTeam] = useState();
const [taskId, setTaskId] = useState('');
const [timeDifference, setTimeDifference] = useState('');
- const [memberId, setMemberId] = useState('')
const { activeTeamTask, tasks, activeTeam } = useTeamTasks();
const { teams } = useOrganizationTeams();
@@ -141,6 +142,56 @@ export function AddManualTimeModal(props: IAddManualTimeModalProps) {
}
}, [addManualTimeLoading, closeModal, timeLog]);
+
+ const memberItemsLists = {
+ 'Project': activeTeam?.projects,
+ 'Employee': activeTeam?.members,
+ 'Task': tasks,
+ };
+ const selectedValues = {
+ 'Teams': null,
+ 'Members': null,
+ "Task": null
+ };
+ const fields = [
+ {
+ label: 'Project',
+ placeholder: 'Select a project',
+ isRequired: true,
+ valueKey: 'id',
+ displayKey: 'name',
+ element: 'Project'
+ },
+ ...(timeSheetStatus === 'ManagerTimesheet' ?
+ [{
+ label: t('manualTime.EMPLOYEE'),
+ placeholder: 'Select an employee',
+ isRequired: true,
+ valueKey: 'id',
+ displayKey: 'employee.fullName',
+ element: 'Employee'
+ }] : []),
+ {
+ label: t('manualTime.TASK'),
+ placeholder: 'Select a Task',
+ isRequired: true,
+ valueKey: 'id',
+ displayKey: 'title',
+ element: 'Task'
+ }
+ ];
+
+
+
+
+ const handleSelectedValuesChange = (values: { [key: string]: Item | null }) => {
+ console.log(values);
+ };
+
+ const handleChange = (field: string, selectedItem: Item | null) => {
+ console.log(`Field: ${field}, Selected Item:`, selectedItem);
+ };
+
return (
-
-
- setTeam(team)}
- itemId={(team) => (team ? team.id : '')}
- itemToString={(team) => (team ? team.name : '')}
- triggerClassName="border-gray-300 dark:border-slate-600"
- />
-
{
params === 'AddManuelTime' ? (
<>
-
-
-
- setMemberId(member ? member.id : memberId)}
- itemId={(member) => (member ? member.id : memberId)}
- itemToString={(member) => (member ? member.employee.fullName : '')}
- triggerClassName="border-gray-300 dark:border-slate-600"
- />
-
-
-
-
- t(`manualTime.reasons.${reason}`))}
- onValueChange={(reason) => setReason(reason)}
- itemId={(reason) => reason}
- defaultValue={t('manualTime.reasons.DEFAULT')}
- itemToString={(reason) => reason}
- triggerClassName="border-gray-300 dark:border-slate-600"
- />
-
+ getNestedValue(item, displayKey) || ''}
+ itemToValue={(item, valueKey) => getNestedValue(item, valueKey) || ''}
+ />
+
>
) : (
<>
-
+
+
+ setTeam(team)}
+ itemId={(team) => (team ? team.id : '')}
+ itemToString={(team) => (team ? team.name : '')}
+ triggerClassName="border-gray-300 dark:border-slate-600"
+ />
+