Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display employee photos in cards #478

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions frontend/src/components/EmployeeCards/EmployeeCards.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';

Check warning on line 1 in frontend/src/components/EmployeeCards/EmployeeCards.tsx

View workflow job for this annotation

GitHub Actions / check

'useState' is defined but never used
import { Link, useParams } from 'react-router-dom';

Check warning on line 2 in frontend/src/components/EmployeeCards/EmployeeCards.tsx

View workflow job for this annotation

GitHub Actions / check

'useParams' is defined but never used
import Card, { CardInfo } from '../Card/Card';
import styles from './employeecards.module.css';
import { clock, phone, wheel, user } from '../../icons/userInfo/index';
Expand Down Expand Up @@ -156,27 +156,26 @@
const EmployeeCards = () => {
const { admins, drivers } = useEmployees();

const allEmployees = [...admins, ...drivers];
const adminIds = new Set(admins.map((admin) => admin.id));
const filteredEmployees = allEmployees.filter((employee: Employee) => {
// if not admin (means driver), check if another admin is representing this driver
if (employee['isDriver'] == undefined) return !adminIds.has(employee.id);
return true;
const employees: Record<string, DriverType | AdminType> = {};
[...admins, ...drivers].forEach((employee) => {
employees[employee.id] = { ...employees[employee.id], ...employee };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one potential concern with this array destructuring is that fields other than photolink could be overridden as well if they differ between the driver and the admin. I'm not sure how often this would occur though.

});

filteredEmployees.sort((a: Employee, b: Employee) => {
if (a.firstName < b.firstName) {
return -1;
const sortedEmployees = Object.values(employees).sort(
(a: Employee, b: Employee) => {
if (a.firstName < b.firstName) {
return -1;
}
if (a.firstName > b.firstName) {
return 1;
}
return 0;
}
if (a.firstName > b.firstName) {
return 1;
}
return 0;
});
);

return (
<div className={styles.cardsContainer}>
{filteredEmployees.map((employee) => (
{sortedEmployees.map((employee) => (
<EmployeeCard key={employee.id} id={employee.id} employee={employee} />
))}
</div>
Expand Down
Loading