Skip to content

Commit

Permalink
Allow users to select more than 4 hours without confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Apr 1, 2024
1 parent 102d88d commit ed05c7e
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,26 @@ import { serverFunctions } from '../../utils/serverFunctions';

export interface BookingContextType {
bookingCalendarInfo: DateSelectArg | undefined;
canBookFullTime: boolean;
department: Department | undefined;
isBanned: boolean;
isSafetyTrained: boolean;
isThesis_PLACEHOLDER: boolean;
role: Role | undefined;
selectedRooms: RoomSetting[];
setBookingCalendarInfo: (x: DateSelectArg) => void;
setDepartment: (x: Department) => void;
setIsThesis: (x: boolean) => void;
setRole: (x: Role) => void;
setSelectedRooms: (x: RoomSetting[]) => void;
}

export const BookingContext = createContext<BookingContextType>({
bookingCalendarInfo: undefined,
canBookFullTime: false,
department: undefined,
isBanned: false,
isSafetyTrained: true,
isThesis_PLACEHOLDER: false,
role: undefined,
selectedRooms: [],
setBookingCalendarInfo: (x: DateSelectArg) => {},
setDepartment: (x: Department) => {},
setIsThesis: (x: boolean) => {},
setRole: (x: Role) => {},
setSelectedRooms: (x: RoomSetting[]) => {},
});
Expand All @@ -52,15 +46,9 @@ export function BookingProvider({ children }) {
useState<DateSelectArg>();
const [department, setDepartment] = useState<Department>();
const [isSafetyTrained, setIsSafetyTrained] = useState(true);
const [isThesis_PLACEHOLDER, setIsThesis] = useState(false);
const [role, setRole] = useState<Role>();
const [selectedRooms, setSelectedRooms] = useState<RoomSetting[]>([]);

const canBookFullTime = useMemo(
() => isThesis_PLACEHOLDER || role !== 'Student',
[isThesis_PLACEHOLDER, role]
);

const isBanned = useMemo<boolean>(() => {
if (!userEmail) return false;
return bannedUsers
Expand Down Expand Up @@ -90,16 +78,13 @@ export function BookingProvider({ children }) {
<BookingContext.Provider
value={{
bookingCalendarInfo,
canBookFullTime,
department,
isBanned,
isSafetyTrained,
isThesis_PLACEHOLDER,
role,
selectedRooms,
setBookingCalendarInfo,
setDepartment,
setIsThesis,
setRole,
setSelectedRooms,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type CalendarProps = {
selectedRooms: RoomSetting[];
handleSetDate: any;
refs?: any[];
canBookFullTime: Boolean;
};

const TITLE_TAG = '[Click to Delete]';
Expand All @@ -20,7 +19,6 @@ export const Calendars = ({
allRooms,
selectedRooms,
handleSetDate,
canBookFullTime,
}: CalendarProps) => {
const [bookingTimeEvent, setBookingTimeEvent] = useState<DateSelectArg>();

Expand Down Expand Up @@ -114,7 +112,6 @@ export const Calendars = ({
allRooms={allRooms}
bookingTimeEvent={bookingTimeEvent}
setBookingTimeEvent={setBookingTimeEvent}
canBookFullTime={canBookFullTime}
isOverlap={isOverlap}
key={i}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { Calendars } from './Calendars';
import { RoomSetting } from '../../../../types';
import { SelectRooms } from './SelectRooms';

export const MultipleCalendars = ({
allRooms,
handleSetDate,
canBookFullTime,
}) => {
export const MultipleCalendars = ({ allRooms, handleSetDate }) => {
const [calendarRefs, setCalendarRefs] = useState([]);
const [loading, setLoading] = useState(true);
const [checkedRoomIds, setCheckedRoomIds] = useState<string[]>([]);
Expand Down Expand Up @@ -122,7 +118,6 @@ export const MultipleCalendars = ({
allRooms={allRooms}
selectedRooms={checkedRooms}
handleSetDate={handleSubmit}
canBookFullTime={canBookFullTime}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const RoomCalendar = ({
allRooms,
bookingTimeEvent,
setBookingTimeEvent,
canBookFullTime,
isOverlap,
}) => {
const [events, setEvents] = useState<CalendarEvent[]>([]);
Expand Down Expand Up @@ -80,16 +79,6 @@ export const RoomCalendar = ({
setBookingTimeEvent(selectInfo);
};
const handleSelectAllow = (selectInfo) => {
console.log('selectInfo', selectInfo);
// only enrolledThesis user can book over 4 hours
if (
!canBookFullTime &&
selectInfo.end.getTime() / 1000 - selectInfo.start.getTime() / 1000 >
60 * 60 * 4
) {
return false;
}

console.log('isOverlap', !isOverlap(selectInfo));
return !isOverlap(selectInfo);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default function SelectRoomPage() {
const navigate = useNavigate();
const { roomSettings, userEmail } = useContext(DatabaseContext);
const {
canBookFullTime,
isBanned,
isSafetyTrained,
selectedRooms,
Expand Down Expand Up @@ -50,7 +49,6 @@ export default function SelectRoomPage() {
key="calendars"
allRooms={roomSettings}
handleSetDate={handleSetDate}
canBookFullTime={canBookFullTime}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ import { BookingContext } from '../bookingProvider';
import { useNavigate } from 'react-router-dom';

export default function UserRolePage() {
const {
isThesis_PLACEHOLDER,
role,
department,
setDepartment,
setIsThesis,
setRole,
} = useContext(BookingContext);
const { role, department, setDepartment, setRole } =
useContext(BookingContext);

const navigate = useNavigate();

Expand Down Expand Up @@ -70,23 +64,6 @@ export default function UserRolePage() {
))}
</select>
</div>
{role === 'Student' && (
<div className="flex items-center my-8">
<input
id="default-checkbox"
type="checkbox"
checked={isThesis_PLACEHOLDER}
onChange={(e) => setIsThesis(e.target.checked)}
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
/>
<label
htmlFor="default-checkbox"
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"
>
This request is related to my thesis or capstone
</label>
</div>
)}
<div className="block">
<button
onClick={handleNextClick}
Expand Down

0 comments on commit ed05c7e

Please sign in to comment.