From 011029b56785ec4fe7dcbec4933bc576ad45da13 Mon Sep 17 00:00:00 2001 From: Jakub Folta Date: Mon, 24 Jun 2024 14:28:51 +0200 Subject: [PATCH] feat: refactor to remove table and use css grid [gh-36] --- frontend/src/app/(app)/people/page.tsx | 106 ++++---- .../common/EmployeeCard/EmployeeCard.tsx | 241 +++++++++--------- 2 files changed, 176 insertions(+), 171 deletions(-) diff --git a/frontend/src/app/(app)/people/page.tsx b/frontend/src/app/(app)/people/page.tsx index 1a9bfa87..3aa9fc0d 100644 --- a/frontend/src/app/(app)/people/page.tsx +++ b/frontend/src/app/(app)/people/page.tsx @@ -128,32 +128,34 @@ export default function People() { const draftPeopleAmount = useMemo(() => people.filter((employee) => employee.draft).length, [people]); const deactivatedPeopleAmount = useMemo(() => people.filter((employee) => employee.deactivated).length, [people]); - const TABS = [ - { - title: tabs[0], - employees: activePeopleAmount, - }, - { - title: tabs[1], - employees: draftPeopleAmount, - }, - { - title: tabs[2], - employees: deactivatedPeopleAmount, - }, - ]; + const peopleTabs = useMemo(() => { + return [ + { + title: tabs[0], + employees: activePeopleAmount, + }, + { + title: tabs[1], + employees: draftPeopleAmount, + }, + { + title: tabs[2], + employees: deactivatedPeopleAmount, + }, + ]; + }, [activePeopleAmount, draftPeopleAmount, deactivatedPeopleAmount]); useEffect(() => { if (people) { - if (activeTab === TABS[0].title) { + if (activeTab === peopleTabs[0].title) { setSelectedTabPeople(people.filter((employee) => employee.active)); - } else if (activeTab === TABS[1].title) { + } else if (activeTab === peopleTabs[1].title) { setSelectedTabPeople(people.filter((employee) => employee.draft)); } else { setSelectedTabPeople(people.filter((employee) => employee.deactivated)); } } - }, [people, activeTab]); + }, [people, activeTab, peopleTabs]); const resetFilterHandler = (event: MouseEvent) => { event.stopPropagation(); @@ -183,7 +185,7 @@ export default function People() { setActiveTabHandler(tab)} - tabs={TABS} + tabs={peopleTabs} className="border-b border-navy-200" /> @@ -207,45 +209,35 @@ export default function People() { - - - *]:w-1/4': activeTab === TABS[2].title, - }, - )} - > - - - - {activeTab === TABS[0].title && ( - <> - - - - - )} - {activeTab === TABS[1].title && } - - - - - {filterPeople(selectedTabPeople)?.map((employee: Employee, index) => ( - - ))} - -
- Employee - LadderCurrent BandActive GoalGoal ProgressLatest ActivityAction -
+
+
+
Employee
+
Ladder
+
Current band
+ + {activeTab === peopleTabs[0].title && ( + <> +
Active goal
+
Goal progress
+
Latest activity
+ + )} + + {activeTab === peopleTabs[1].title &&
Action
} +
+
+ {filterPeople(selectedTabPeople)?.map((employee: Employee, index) => ( + + ))} +
); diff --git a/frontend/src/components/common/EmployeeCard/EmployeeCard.tsx b/frontend/src/components/common/EmployeeCard/EmployeeCard.tsx index 28179e63..3f9951f6 100644 --- a/frontend/src/components/common/EmployeeCard/EmployeeCard.tsx +++ b/frontend/src/components/common/EmployeeCard/EmployeeCard.tsx @@ -9,124 +9,137 @@ export const EmployeeCard = ({ employee, tabSelected }: EmployeeCardProps) => { const { name, title, laddersDetails } = employee; return ( - <> - - 1 && { className: 'flex h-16' })}> -
-
- User image -
-
-

{name}

-

{title}

-
-
- - - {laddersDetails.map((ladder, index) => ( - 1 && { - className: 'flex items-center h-16 [&:not(:first-of-type)]:-mt-[17px]', - })} - > - {ladder.ladderName} - - ))} - - - {laddersDetails.map((ladder, index) => ( - 1, - })} - > - {ladder.currentBand} - - ))} - - {tabSelected === tabs[0] && ( - <> - - {laddersDetails.map((ladder, index) => ( -
1, - })} - > - {ladder.activeGoal ? : null} -
- ))} - - - {laddersDetails.map( - (ladder, index) => - ladder.activeGoal && ( -
1, - })} - > -
-
-
- {ladder.goalProgress}% -
- ), - )} - - - {laddersDetails.map( - (ladder, index) => - ladder.activeGoal && ( -
1, - })} - > -
- {ladder.latestActivity} -
-
- ), - )} - - - )} - {tabSelected === tabs[1] && ( - - - - - )} - +
1, + })} + > +
1, })} > -
+ User image +
+
+

{name}

+

{title}

+
+
+
+
1 && { + className: 'flex-col [&]:items-start', + })} + > + {laddersDetails.map((ladder, index) => ( + 1 && { + className: 'flex items-center h-16 [&:not(:first-of-type)]:-mt-[17px]', })} > - + {ladder.ladderName} + + ))} +
+
1, + })} + > + {laddersDetails.map((ladder, index) => ( + 1 && { + className: 'flex items-center h-16 [&:not(:first-of-type)]:-mt-[17px]', + })} + > + {ladder.currentBand} + + ))} +
+ + {tabSelected === tabs[0] && ( + <> +
+ {laddersDetails.map((ladder, index) => ( + 1 && { + className: '[&:not(:first-of-type)]:-mt-[17px]', + })} + > + {ladder.activeGoal ? : null} + + ))} +
+
+ {laddersDetails.map( + (ladder, index) => + ladder.activeGoal && ( +
1, + })} + > +
+
+
+ {ladder.goalProgress}% +
+ ), + )} +
+
+ {laddersDetails.map( + (ladder, index) => + ladder.activeGoal && ( +
1 && { + className: '[&:not(:first-of-type)]:-mt-[17px]', + })} + > +
+ {ladder.latestActivity} +
+
+ ), + )}
- - - + + )} + + {tabSelected === tabs[1] && ( +
+ + +
+ )} + +
+
+ + + +
+
+
); };