Skip to content

Commit

Permalink
Asking department and role at first
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Feb 5, 2024
1 parent 81714e4 commit ac7b2c7
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef } from 'react';
import { CalendarDatePicker } from './CalendarDatePicker';
import { DateSelectArg } from '@fullcalendar/core';
import { RoomSetting } from './SheetEditor';
import { Role, RoomSetting } from './SheetEditor';
import { formatDate } from '../../utils/date';
import { RoomCalendar } from './RoomCalendar';

Expand All @@ -10,6 +10,7 @@ type CalendarProps = {
selectedRooms: RoomSetting[];
handleSetDate: any;
refs?: any[];
canBookFullTime: Boolean;
};

const TITLE_TAG = '[Click to Delete]';
Expand All @@ -18,10 +19,9 @@ export const Calendars = ({
allRooms,
selectedRooms,
handleSetDate,
canBookFullTime,
}: CalendarProps) => {
console.log('allrooms', allRooms);
const [enrolledThisis, setEnrolledThesis] = useState(false);
const [faculty, setFaculty] = useState(false);
const [bookingTimeEvent, setBookingTimeEvent] = useState<DateSelectArg>();
const isOverlap = (info) => {
return selectedRooms.some((room, i) => {
Expand Down Expand Up @@ -86,23 +86,6 @@ export const Calendars = ({
<div className="">Select date</div>
<CalendarDatePicker handleChange={handleChange} />
</div>
<div className="flex flex-col justify-center items-center">
<div className="flex ">
<input
id="default-checkbox"
type="checkbox"
value=""
className="pt-4 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"
onChange={(e) => setEnrolledThesis(!enrolledThisis)}
/>
<label
htmlFor="default-checkbox"
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"
>
Enrolled in thesis
</label>
</div>
</div>
<div className="flex flex-col items-center ">
<button
key="calendarNextButton"
Expand All @@ -128,7 +111,7 @@ export const Calendars = ({
allRooms={allRooms}
bookingTimeEvent={bookingTimeEvent}
setBookingTimeEvent={setBookingTimeEvent}
enrolledThisis={enrolledThisis || faculty}
canBookFullTime={canBookFullTime}
isOverlap={isOverlap}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type Inputs = {
nNumber: string;
netId: string;
phoneNumber: string;
department: String;
department: string;
role: string;
sponsorFirstName: string;
sponsorLastName: string;
Expand Down Expand Up @@ -42,7 +42,13 @@ const ErrorMessage = (message) => {
);
};

const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
const FormInput = ({
hasEmail,
handleParentSubmit,
selectedRoom,
role: initialRole,
department: initialDepartment,
}) => {
const {
register,
handleSubmit,
Expand All @@ -57,14 +63,14 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
sponsorLastName: '',
sponsorEmail: '',
mediaServicesDetails: '',
role: '',
role: initialRole,
catering: '',
chartFieldForCatering: '',
chartFieldForSecurity: '',
chartFieldForRoomSetup: '',
hireSecurity: '',
attendeeAffiliation: '',
department: '',
department: initialDepartment,
roomSetup: '',
},
mode: 'onBlur',
Expand Down Expand Up @@ -276,70 +282,7 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
})}
/>
</div>
<div className="mb-6">
<label
htmlFor="department"
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>
Department
</label>
{errors.department && (
<ErrorMessage errors={errors.department.message} />
)}
<select
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
{...register('department', {
required: true,
validate: (value) => value !== '',
})}
onChange={(e) => {
handleSelectChange(e);
}}
>
<option value="" disabled>
Select option
</option>
<option value="ALT">ALT</option>
<option value="GameCenter">Game Center</option>
<option value="IDM">IDM</option>
<option value="ITP / IMA / Low Res">ITP / IMA / Low Res</option>
<option value="MARL">MARL</option>
<option value="Music Tech">Music Tech</option>
<option value="Recorded Music">Recorded Music</option>
<option value="others">Other Group</option>
</select>
{showTextbox && (
<input
type="text"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
{...register('department')}
/>
)}
</div>
<div className="mb-6">
<label
htmlFor="role"
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>
Requestor's Role
</label>
{errors.role && <ErrorMessage errors={errors.role.message} />}
<select
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
{...register('role', {
required: true,
validate: (value) => value !== '',
})}
>
<option value="" disabled>
Select option
</option>
<option value="Student">Student</option>
<option value="Resident/Fellow">Resident / Fellow</option>
<option value="Faculty">Faculty</option>
<option value="Admin/Staff">Admin / Staff</option>
</select>
</div>

{watch('role') === 'Student' && (
<div>
<div className="mb-6">
Expand Down Expand Up @@ -369,6 +312,9 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
>
Sponsor Last Name
</label>
{errors.sponsorFirstName && (
<ErrorMessage errors={errors.sponsorFirstName.message} />
)}
<input
type="sponsorLastName"
id="sponsorLastName"
Expand Down Expand Up @@ -396,11 +342,11 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder=""
{...register('sponsorEmail', {
required: watch('role') === 'Student',
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: 'Invalid email address',
},
required: watch('role') === 'Student',
})}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Calendars } from './Calendars';
import { SelectRooms } from './SelectRooms';
import { SelectMotionCapture } from './SelectMotionCapture';

export const MultipleCalendars = ({ allRooms, handleSetDate }) => {
export const MultipleCalendars = ({
allRooms,
handleSetDate,
canBookFullTime,
}) => {
const [calendarRefs, setCalendarRefs] = useState([]);
const [loading, setLoading] = useState(true);
const [checkedRoomIds, setCheckedRoomIds] = useState([]);
Expand Down Expand Up @@ -112,6 +116,7 @@ export const MultipleCalendars = ({ allRooms, handleSetDate }) => {
allRooms={allRooms}
selectedRooms={checkedRooms}
handleSetDate={handleSubmit}
canBookFullTime={canBookFullTime}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useState } from 'react';

export const RoleModal = ({ handleClick }) => {
const [role, setRole] = useState('');
const [department, setDepartment] = useState('');
const [enrolledThesis, setEnrolledThesis] = useState(false);

// Nextボタンのクリックイベントハンドラ
const handleNextClick = () => {
if (!role || !department) {
// 適切なエラーメッセージを設定
alert('Please make sure all fields are selected.');
return; // ここで処理を中断
}
handleClick(role, department, enrolledThesis);
};

return (
<div
id="staticModal"
data-modal-backdrop="static"
tabIndex={-1}
aria-hidden="true"
className="fixed top-0 left-0 bg-white right-0 z-50 w-full h-120 p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full"
>
<div className="relative w-full max-w-2xl max-h-full">
<div className="relative bg-white rounded-lg shadow dark:bg-gray-700">
<div className="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600"></div>
<label className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Select Department
</label>
<select
onChange={(e) => setDepartment(e.target.value)}
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
<option value="">Choose a Department</option>
<option value="ALT">ALT</option>
<option value="GameCenter">Game Center</option>
<option value="IDM">IDM</option>
<option value="ITP / IMA / Low Res">ITP / IMA / Low Res</option>
<option value="MARL">MARL</option>
<option value="Music Tech">Music Tech</option>
<option value="Recorded Music">Recorded Music</option>
<option value="others">Other Group</option>
</select>

<label className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Select Role
</label>
<select
onChange={(e) => setRole(e.target.value)}
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
<option value="">Choose a Role</option>
<option value="Student">Student</option>
<option value="Resident/Fellow">Resident / Fellow</option>
<option value="Faculty">Faculty</option>
<option value="Admin/Staff">Admin / Staff</option>
</select>

{role === 'Student' && (
<>
<input
id="default-checkbox"
type="checkbox"
checked={enrolledThesis}
onChange={(e) => setEnrolledThesis(e.target.checked)}
className="mt-4 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"
>
Enrolled in thesis
</label>
</>
)}

<button
onClick={handleNextClick}
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
>
Next
</button>
</div>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const RoomCalendar = ({
allRooms,
bookingTimeEvent,
setBookingTimeEvent,
enrolledThisis,
canBookFullTime,
isOverlap,
}) => {
const [events, setEvents] = useState([]);
Expand Down Expand Up @@ -74,7 +74,7 @@ export const RoomCalendar = ({
console.log('selectInfo', selectInfo);
// only enrolledThesis user can book over 4 hours
if (
!enrolledThisis &&
!canBookFullTime &&
selectInfo.end.getTime() / 1000 - selectInfo.start.getTime() / 1000 >
60 * 60 * 4
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type RoomSetting = {
calendarRef?: any;
};

export type Role = 'Student' | 'Resident/Fellow' | 'Faculty' | 'Admin/Staff';

export type Purpose = 'multipleRoom' | 'motionCapture';

const SAFETY_TRAINING_REQUIRED_ROOM = [
Expand Down Expand Up @@ -73,6 +75,12 @@ const SheetEditor = () => {
const [mappingRoomSettings, setMappingRoomSettings] = useState([]);
const [section, setSection] = useState('selectRoom');
const [loading, setLoading] = useState(true);
const [role, setRole] = useState('');
const [department, setDepartment] = useState('');
const [enrolledThesis, setEnrolledThesis] = useState(false);
const canBookFullTime = enrolledThesis || role !== 'Student';
console.log('enrolledThesis', enrolledThesis, 'role', role);

const order: (keyof Inputs)[] = [
'firstName',
'lastName',
Expand Down Expand Up @@ -186,7 +194,7 @@ const SheetEditor = () => {
// Add the event to the calendar.
const calendarEventId = await serverFunctions.addEventToCalendar(
roomCalendarId(room),
`[REQUESTED] ${room.roomId} ${data.department} - ${data.firstName} ${data.lastName} (${data.netId})`,
`[REQUESTED] ${room.roomId} ${department} - ${data.firstName} ${data.lastName} (${data.netId})`,
'Your reservation is not yet confirmed. The coordinator will review and finalize your reservation within a few days.',
bookInfo.startStr,
bookInfo.endStr,
Expand Down Expand Up @@ -293,6 +301,8 @@ const SheetEditor = () => {
hasEmail={userEmail ? true : false}
handleParentSubmit={handleSubmit}
selectedRoom={selectedRoom}
role={role}
department={department}
/>
</div>
);
Expand All @@ -304,6 +314,7 @@ const SheetEditor = () => {
key="calendars"
allRooms={mappingRoomSettings}
handleSetDate={handleSetDate}
canBookFullTime={canBookFullTime}
/>
</div>
);
Expand All @@ -314,7 +325,10 @@ const SheetEditor = () => {
setShowModal(false);
setRoleModal(true);
};
const handleRoleModalClick = () => {
const handleRoleModalClick = (role, department, enrolledThesis) => {
setRole(role);
setDepartment(department);
setEnrolledThesis(enrolledThesis);
setRoleModal(false);
};
return (
Expand Down

0 comments on commit ac7b2c7

Please sign in to comment.