Skip to content

Commit ecc36a0

Browse files
authored
Merge pull request #4230 from Northeastern-Electric-Racing/#4400-availability-ui
ui fixes
2 parents 5f12917 + 6ed751a commit ecc36a0

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

src/frontend/src/pages/CalendarPage/Components/EventAvailabilityPage.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ export const EventAvailabilityPage: React.FC = () => {
148148
return event.confirmedMembers.some((m) => m.userId === currentUser.userId);
149149
}, [event, currentUser]);
150150

151+
// Reorders users by alphabetical order.
152+
const reorderAlphabetically = (users: User[]) => {
153+
return users.sort((a, b) => (a.lastName + a.firstName).localeCompare(b.lastName + b.firstName));
154+
};
155+
156+
// Reorders users by confirmation or not. All confirmed users are above the unconfirmed users
157+
const reorderByConfirmation = (users: User[]) => {
158+
return [...reorderAlphabetically(users)].sort((a, b) => {
159+
const aConfirmation = event && event.confirmedMembers.some((m) => m.userId === a.userId) ? 1 : 0;
160+
const bConfirmation = event && event.confirmedMembers.some((m) => m.userId === b.userId) ? 1 : 0;
161+
return bConfirmation - aConfirmation;
162+
});
163+
};
164+
151165
useEffect(() => {
152166
if (userScheduleSettings && userScheduleSettings.availabilities.length > 0) {
153167
const confirmed = getMostRecentAvailabilities(userScheduleSettings.availabilities, displayDate);
@@ -318,11 +332,15 @@ export const EventAvailabilityPage: React.FC = () => {
318332
</Typography>
319333
<Box sx={{ maxHeight: 300, overflowY: 'auto' }}>
320334
{currentAvailableUsers.length > 0 ? (
321-
currentAvailableUsers.map((user) => {
335+
reorderByConfirmation(currentAvailableUsers).map((user) => {
322336
const isConfirmed = event.confirmedMembers.some((cm) => cm.userId === user.userId);
323-
const displayName = fullNamePipe(user) + (isConfirmed ? '' : ' *');
337+
const displayName = fullNamePipe(user);
324338
return (
325-
<Typography key={user.userId} variant="body2" sx={{ py: 0.25 }}>
339+
<Typography
340+
key={user.userId}
341+
variant="body2"
342+
sx={{ py: 0.25, color: isConfirmed ? 'inherit' : '#ef4345' }}
343+
>
326344
{displayName}
327345
</Typography>
328346
);
@@ -341,11 +359,15 @@ export const EventAvailabilityPage: React.FC = () => {
341359
</Typography>
342360
<Box sx={{ maxHeight: 300, overflowY: 'auto' }}>
343361
{currentUnavailableUsers.length > 0 ? (
344-
currentUnavailableUsers.map((user) => {
362+
reorderByConfirmation(currentUnavailableUsers).map((user) => {
345363
const isConfirmed = event.confirmedMembers.some((cm) => cm.userId === user.userId);
346-
const displayName = fullNamePipe(user) + (isConfirmed ? '' : ' *');
364+
const displayName = fullNamePipe(user);
347365
return (
348-
<Typography key={user.userId} variant="body2" sx={{ py: 0.25 }}>
366+
<Typography
367+
key={user.userId}
368+
variant="body2"
369+
sx={{ py: 0.25, color: isConfirmed ? 'inherit' : '#ef4345' }}
370+
>
349371
{displayName}
350372
</Typography>
351373
);
@@ -361,7 +383,7 @@ export const EventAvailabilityPage: React.FC = () => {
361383

362384
{(currentAvailableUsers.length > 0 || currentUnavailableUsers.length > 0) && (
363385
<Typography variant="caption" color="text.secondary" sx={{ mt: 2, display: 'block' }}>
364-
* has not confirmed availability
386+
<span style={{ color: '#ef4345' }}>Red</span> means has not confirmed availability
365387
</Typography>
366388
)}
367389

0 commit comments

Comments
 (0)