Skip to content

Commit

Permalink
fixed a bug related to rooms dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ahnaf committed Oct 23, 2024
1 parent cd58ccf commit 8f5a787
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 37 deletions.
2 changes: 1 addition & 1 deletion client/src/components/EventCard/EditDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default function EditDialog({ open, event, handleClose, currentRoom, onEd
<RoomsDropdown
id="room"
options={availableRoomOptions}
value={formData.room || ''}
value={formData.room || (availableRoomOptions.length > 0 ? availableRoomOptions[0].value : '')}
loading={roomLoading}
currentRoom={currentRoom}
disabled={!availableRoomOptions.length}
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Home/BookRoomView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default function BookRoomView({ refresh, setRefresh }: BookRoomViewProps)
<RoomsDropdown
id="room"
options={availableRoomOptions}
value={formData.room || ''}
value={formData.room || (availableRoomOptions.length > 0 ? availableRoomOptions[0].value : '')}
loading={roomLoading}
disabled={!availableRoomOptions.length}
onChange={handleInputChange}
Expand Down
58 changes: 30 additions & 28 deletions client/src/pages/Home/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const StyledToggleButtonGroup = styled(ToggleButtonGroup)(({ theme }) => ({
borderRadius: 30,
},
},
justifyContent: 'center',
}));

const StyledToggleButton = styled(ToggleButton)(({ theme }) => ({
Expand Down Expand Up @@ -441,12 +442,12 @@ export default function SettingsDialog({ open, handleClose, onSave }: SettingsDi
borderRadius: 100,
backgroundColor: 'white',
py: 1,
px: 1,
px: 0,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
mr: 1,
mr: 0,
}}
>
<IconButton aria-label="settings" sx={{ backgroundColor: 'white' }} onClick={handleClose}>
Expand All @@ -471,6 +472,7 @@ export default function SettingsDialog({ open, handleClose, onSave }: SettingsDi
px: 0.5,
width: '100%',
borderRadius: 30,
textAlign: 'center',
}}
>
<StyledToggleButtonGroup sx={{ mx: 0 }} value={tabIndex} exclusive onChange={handleTabChange} aria-label="event tabs" fullWidth={true}>
Expand All @@ -482,33 +484,33 @@ export default function SettingsDialog({ open, handleClose, onSave }: SettingsDi
</StyledToggleButton>
</StyledToggleButtonGroup>
</Box>
{/* logout icon */}
<Box
sx={{
borderRadius: 100,
backgroundColor: 'white',
py: 1,
px: 0,
display: 'flex',
// width: '100%',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
ml: 0,
}}
>
<IconButton aria-label="settings" sx={{ mr: 0, backgroundColor: 'white' }} onClick={onLogoutClick}>
<ExitToAppRoundedIcon
fontSize="small"
sx={[
(theme) => ({
color: theme.palette.common.black,
}),
]}
/>
</IconButton>
</Box>
</TopBar>
{/* logout icon */}
<Box
sx={{
borderRadius: 100,
backgroundColor: 'white',
py: 1,
px: 1,
display: 'flex',
// width: '100%',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
ml: 1,
}}
>
<IconButton aria-label="settings" sx={{ mr: 0, backgroundColor: 'white' }} onClick={onLogoutClick}>
<ExitToAppRoundedIcon
fontSize="small"
sx={[
(theme) => ({
color: theme.palette.common.black,
}),
]}
/>
</IconButton>
</Box>
</Box>

{tabs[tabIndex].component({ onSave: () => onSave() })}
Expand Down
34 changes: 27 additions & 7 deletions server/src/calender/calender.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export class CalenderService {
): Promise<ConferenceRoom[]> {
const filteredRoomEmails: string[] = [];
const rooms = await this.authService.getDirectoryResources(domain);

for (const room of rooms) {
if (room.seats >= Number(minSeats) && (floor === undefined || room.floor === floor)) {
filteredRoomEmails.push(room.email);
Expand All @@ -151,13 +150,34 @@ export class CalenderService {

if (eventId) {
const event = await this.googleApiService.getCalenderEvent(client, eventId);
const requestStart = new Date(start);
const requestEnd = new Date(end);

const isWithinRange = new Date(event.start.dateTime) >= requestStart && new Date(event.end.dateTime) <= requestEnd;
if (isWithinRange) {
const attendee = event.attendees.find((attendee) => attendee.email.endsWith('resource.calendar.google.com'));
const currentRoom = extractRoomByEmail(rooms, attendee.email);
const currentStartTime = new Date(event.start.dateTime).getTime();
const currentEndTime = new Date(event.end.dateTime).getTime();

const requestStart = new Date(start).getTime();
const requestEnd = new Date(end).getTime();

const attendee = event.attendees.find((attendee) => attendee.email.endsWith('resource.calendar.google.com'));
const currentRoom = extractRoomByEmail(rooms, attendee.email);

const { timeZone } = event.start;

let isEventRoomAvailable = true;
if (requestStart < currentStartTime) {
const isAvailable = await this.isRoomAvailable(client, start, event.start.dateTime, attendee.email, timeZone);
if (!isAvailable) {
isEventRoomAvailable = false;
}
}

if (requestEnd > currentEndTime) {
const isAvailable = await this.isRoomAvailable(client, event.end.dateTime, end, attendee.email, timeZone);
if (!isAvailable) {
isEventRoomAvailable = false;
}
}

if (isEventRoomAvailable) {
availableRooms.unshift(currentRoom);
}
}
Expand Down
1 change: 1 addition & 0 deletions server/src/google-api/google-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class GoogleApiService implements IGoogleApiService {
timeMin: start,
timeMax: end,
timeZone,
calendarExpansionMax: 100,
items: rooms.map((email) => {
return {
id: email,
Expand Down

0 comments on commit 8f5a787

Please sign in to comment.