Skip to content

Commit

Permalink
fixed a bug regarding preferred rooms not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ahnaf committed Jan 27, 2025
1 parent 387fcdb commit d8be034
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
26 changes: 5 additions & 21 deletions client/src/components/RoomsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ interface DropdownProps {
currentRoom?: IConferenceRoom;
}

interface StyledMenuItemProps {
i: number;
option: RoomsDropdownOption;
currentRoom?: IConferenceRoom;
}

export interface RoomsDropdownOption {
text: string;
value: string; // the main value used for api calls
Expand All @@ -32,9 +26,9 @@ export interface RoomsDropdownOption {
isBusy?: boolean;
}

const CustomMenuItem = ({ i, option, currentRoom }: StyledMenuItemProps) => {
const renderMenuItem = (option: RoomsDropdownOption, currentRoom?: IConferenceRoom) => {
return (
<MenuItem value={option.value} key={i}>
<MenuItem value={option.value} key={option.value}>
<Box
sx={{
display: 'flex',
Expand Down Expand Up @@ -173,7 +167,6 @@ const RenderSelectText = ({ icon, loading, selectedOption }: { icon?: ReactEleme

export default function RoomsDropdown({ sx, id, disabled, currentRoom, value, options, onChange, icon, placeholder, loading }: DropdownProps) {
const height = '58px';
const { preferences } = usePreferences();

const handleChange = (event: SelectChangeEvent) => {
onChange(id, event.target.value);
Expand Down Expand Up @@ -220,23 +213,14 @@ export default function RoomsDropdown({ sx, id, disabled, currentRoom, value, op
</MenuItem>
)}

{options.preferred.length === 0 && preferences.floor && (
<StyledHintTypography sx={{ my: 0.5 }}>No rooms available according to your preferences</StyledHintTypography>
)}

{options.preferred.map((option, i) => (
<CustomMenuItem key={i} currentRoom={currentRoom} option={option} i={i} />
))}
{options.preferred.map((option) => renderMenuItem(option, currentRoom))}

{options.others.length > 0 && (
<ListSubheader>
<StyledHintTypography sx={{ my: 0.5 }}>Others</StyledHintTypography>
<StyledHintTypography sx={{ my: 0.5 }}>Less preferred rooms</StyledHintTypography>
</ListSubheader>
)}

{options.others.map((option, i) => (
<CustomMenuItem key={i} currentRoom={currentRoom} option={option} i={i} />
))}
{options.others.map((option) => renderMenuItem(option, currentRoom))}
</Select>
);
}
5 changes: 2 additions & 3 deletions client/src/pages/Home/BookRoomView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function BookRoomView({ onRoomBooked }: BookRoomViewProps) {
duration: Number(preferences.duration),
seats: preferences.seats,
conference: false,
room: '',
});

// Utilities and hooks
Expand Down Expand Up @@ -145,14 +146,12 @@ export default function BookRoomView({ onRoomBooked }: BookRoomViewProps) {

const data = res.data as IAvailableRooms;

console.log(data);

let roomEmail: string | undefined;
let preferredRoomOptions: RoomsDropdownOption[] = [];
let unPreferredRoomOptions: RoomsDropdownOption[] = [];

if (data.preferred.length > 0 || data.others.length > 0) {
roomEmail = data.preferred[0].email || data.others[0].email;
roomEmail = (data.preferred?.[0] || data.others?.[0])?.email;
preferredRoomOptions = createRoomDropdownOptions(data.preferred);
unPreferredRoomOptions = createRoomDropdownOptions(data.others);
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Home/MyEventsView/EditEventsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function EditEventsView({ open, event, handleClose, currentRoom,

if (currentRoom) {
const filteredPreferredRooms = data.preferred.filter((item) => item.email !== currentRoom.email);
const filteredUnPreferredRooms = data.preferred.filter((item) => item.email !== currentRoom.email);
const filteredUnPreferredRooms = data.others.filter((item) => item.email !== currentRoom.email);

preferredRoomOptions = createRoomDropdownOptions(filteredPreferredRooms);
unPreferredRoomOptions = createRoomDropdownOptions(filteredUnPreferredRooms);
Expand All @@ -168,7 +168,7 @@ export default function EditEventsView({ open, event, handleClose, currentRoom,
} else {
preferredRoomOptions = createRoomDropdownOptions(data.preferred);
unPreferredRoomOptions = createRoomDropdownOptions(data.others);
const roomEmail = data.preferred[0].email || data.others[0].email;
const roomEmail = (data.preferred?.[0] || data.others?.[0])?.email;

setFormData((prev) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion server/src/calender/calender.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class CalenderService {
}

if (isEventRoomAvailable) {
if (isPreferredRoom[room.email]) {
if (isPreferredRoom[currentRoom.email]) {
availableRooms.preferred.unshift(currentRoom);
} else {
availableRooms.others.unshift(currentRoom);
Expand Down

0 comments on commit d8be034

Please sign in to comment.