Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions client/src/pages/StaffDashboard/StaffDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import {

interface StaffMember {
id: string;
employeeId: string;
name: string;
position: string;
locationObjectId: string;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field name locationObjectId is misleading because it stores the location name (hubName) rather than the ObjectId. According to the codebase convention established in client/src/types/Survey.ts and client/src/hooks/useApi.tsx (line 339), this should be renamed to locationName for consistency.

Suggested change
locationObjectId: string;
locationName: string;

Copilot uses AI. Check for mistakes.
phone: string;
approvalStatus: string;
}

export default function StaffDashboard() {
const navigate = useNavigate();
const { userService } = useApi();
const { userService, locationService } = useApi();
const { userObjectId } = useAuthContext();
const [searchTerm, setSearchTerm] = useState('');
const [filterRole, setFilterRole] = useState('');
Expand All @@ -38,6 +39,7 @@ export default function StaffDashboard() {
});

const { data: users, mutate } = userService.useUsers() || {};
const { data: locations } = locationService.useLocations() || {};

// Handlers
const handleApproval = async (id: string, status: string) => {
Expand Down Expand Up @@ -75,8 +77,13 @@ export default function StaffDashboard() {
}
};

// Create location lookup map
const locationMap = new Map(
locations?.map(loc => [loc._id, loc.hubName]) ?? []
);

// Data processing pipeline
const staffMembers = transformUsersToStaff(users ?? []);
const staffMembers = transformUsersToStaff(users ?? [], locationMap);
const filteredStaff = filterStaff(staffMembers, searchTerm, filterRole);
const sortedStaff = sortStaff(filteredStaff, sortConfig);
const currentStaff = paginateStaff(sortedStaff, currentPage, itemsPerPage);
Expand Down
18 changes: 5 additions & 13 deletions client/src/pages/StaffDashboard/components/StaffDashboardRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
Stack,
TableCell,
TableRow,
Tooltip,
Typography
Tooltip
} from '@mui/material';

import { UserDocument } from '@/types/User';

interface StaffMember {
id: string;
employeeId: string;
name: string;
position: string;
locationObjectId: string;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field name locationObjectId is misleading because it stores the location name (hubName) rather than the ObjectId. According to the codebase convention established in client/src/types/Survey.ts and client/src/hooks/useApi.tsx (line 339), this should be renamed to locationName for consistency.

Suggested change
locationObjectId: string;
locationName: string;

Copilot uses AI. Check for mistakes.
phone: string;
approvalStatus: string;
}

Expand Down Expand Up @@ -73,18 +73,10 @@ export default function StaffDashboardRow({
'&:hover': { backgroundColor: '#f8f8f8' }
}}
>
<TableCell>
<Typography
variant="body2"
sx={{
fontSize: '0.85rem'
}}
>
{member.employeeId}
</Typography>
</TableCell>
<TableCell>{member.name}</TableCell>
<TableCell>{member.position}</TableCell>
<TableCell>{member.locationObjectId}</TableCell>
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field reference should be member.locationName instead of member.locationObjectId to match the corrected field name and maintain consistency with the codebase convention (see client/src/types/Survey.ts).

Copilot uses AI. Check for mistakes.
<TableCell>{member.phone}</TableCell>
<TableCell>
<Tooltip
title={
Expand Down
47 changes: 33 additions & 14 deletions client/src/pages/StaffDashboard/components/StaffDashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import StaffDashboardRow from './StaffDashboardRow';

interface StaffMember {
id: string;
employeeId: string;
name: string;
position: string;
locationObjectId: string;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field name locationObjectId is misleading because it stores the location name (hubName) rather than the ObjectId. According to the codebase convention established in client/src/types/Survey.ts and client/src/hooks/useApi.tsx (line 339), this should be renamed to locationName for consistency.

Suggested change
locationObjectId: string;
/**
* Human-readable location name (hubName), following app-wide convention.
*/
locationName: string;
/**
* @deprecated This field name is misleading; use `locationName` instead.
* Kept optional for backward compatibility with older code.
*/
locationObjectId?: string;

Copilot uses AI. Check for mistakes.
phone: string;
approvalStatus: string;
}

Expand Down Expand Up @@ -52,15 +53,15 @@ export default function StaffDashboardTable({
}}
>
<TableSortLabel
active={sortConfig.key === 'employeeId'}
active={sortConfig.key === 'name'}
direction={
sortConfig.key === 'employeeId'
sortConfig.key === 'name'
? sortConfig.direction
: 'asc'
}
onClick={() => onSort('employeeId')}
onClick={() => onSort('name')}
>
Employee ID
Name
</TableSortLabel>
</TableCell>
<TableCell
Expand All @@ -70,15 +71,15 @@ export default function StaffDashboardTable({
}}
>
<TableSortLabel
active={sortConfig.key === 'name'}
active={sortConfig.key === 'position'}
direction={
sortConfig.key === 'name'
sortConfig.key === 'position'
? sortConfig.direction
: 'asc'
}
onClick={() => onSort('name')}
onClick={() => onSort('position')}
>
Name
Role
</TableSortLabel>
</TableCell>
<TableCell
Expand All @@ -88,15 +89,33 @@ export default function StaffDashboardTable({
}}
>
<TableSortLabel
active={sortConfig.key === 'position'}
active={sortConfig.key === 'locationObjectId'}
direction={
sortConfig.key === 'position'
sortConfig.key === 'locationObjectId'
? sortConfig.direction
: 'asc'
}
onClick={() => onSort('position')}
onClick={() => onSort('locationObjectId')}
Comment on lines +92 to +98
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The sort key should be locationName instead of locationObjectId to match the corrected field name and maintain consistency with the codebase convention (see client/src/types/Survey.ts).

Copilot uses AI. Check for mistakes.
>
Location
</TableSortLabel>
</TableCell>
<TableCell
sx={{
fontWeight: 600,
backgroundColor: '#f9f9f9'
}}
>
<TableSortLabel
active={sortConfig.key === 'phone'}
direction={
sortConfig.key === 'phone'
? sortConfig.direction
: 'asc'
}
onClick={() => onSort('phone')}
>
Position
Phone Number
</TableSortLabel>
</TableCell>
<TableCell
Expand Down Expand Up @@ -131,7 +150,7 @@ export default function StaffDashboardTable({
<TableBody>
{staff.length === 0 ? (
<TableRow>
<TableCell colSpan={5} align="center">
<TableCell colSpan={6} align="center">
No staff members found.
</TableCell>
</TableRow>
Expand Down
9 changes: 6 additions & 3 deletions client/src/pages/StaffDashboard/utils/StaffDashboardUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { UserDocument } from '@/types/User';

interface StaffMember {
id: string;
employeeId: string;
name: string;
position: string;
locationObjectId: string;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field name locationObjectId is misleading because it stores the location name (hubName) rather than the ObjectId. According to the codebase convention established in client/src/types/Survey.ts and client/src/hooks/useApi.tsx (line 339), the field that stores the resolved location name should be called locationName, not locationObjectId.

This should be renamed to locationName in the StaffMember interface and all usages for consistency with the rest of the codebase.

Copilot uses AI. Check for mistakes.
phone: string;
approvalStatus: string;
}

Expand Down Expand Up @@ -84,15 +85,17 @@ export const paginateStaff = (
* Transform users data to staff members format
*/
export const transformUsersToStaff = (
users: UserDocument[] | undefined
users: UserDocument[] | undefined,
locationMap: Map<string, string>
): StaffMember[] => {
if (!users) return [];

return users.map((user: UserDocument) => ({
id: user._id,
employeeId: user._id ?? 'N/A',
name: `${user.firstName} ${user.lastName}`,
position: user.role,
locationObjectId: locationMap.get(user.locationObjectId?.toString() ?? '') ?? 'N/A',
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The field name in the object literal should be locationName instead of locationObjectId to match the corrected field name and maintain consistency with the codebase convention (see client/src/types/Survey.ts and client/src/hooks/useApi.tsx line 339).

Copilot uses AI. Check for mistakes.
phone: user.phone ?? 'N/A',
approvalStatus: user.approvalStatus ?? 'PENDING'
}));
};
Loading