Skip to content

Commit

Permalink
Maximum expected attendance data validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Jan 8, 2024
1 parent ebcd4ad commit 1614a85
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
const [showTextbox, setShowTextbox] = useState(false);
const roomNumber = selectedRoom.map((room) => room.roomId);

const maxCapacity = selectedRoom.map((room) => room.maxCapacity);
const maxCapacity = selectedRoom.reduce((sum, room) => {
return sum + parseInt(room.capacity);
}, 0);
const validateExpectedAttendance = (value) => {
const attendance = parseInt(value);
return (
(!isNaN(attendance) && attendance <= maxCapacity) ||
`Expected attendance exceeds maximum capacity of ${maxCapacity}`
);
};
console.log('maxCapacity', maxCapacity);
const disabledButton = !(checklist && resetRoom && bookingPolicy);
useEffect(() => {
Expand All @@ -88,7 +97,6 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
data.mediaServices = dumpMediaServices?.join(', ');
handleParentSubmit(data);
};
console.log('errors', errors);

const handleSelectChange = (event) => {
if (event.target.value === 'others') {
Expand Down Expand Up @@ -444,10 +452,13 @@ const FormInput = ({ hasEmail, handleParentSubmit, selectedRoom }) => {
<ErrorMessage errors={errors.expectedAttendance.message} />
)}
<input
type="expectedAttendance"
id="expectedAttendance"
type="number"
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('expectedAttendance', { required: true })}
{...register('expectedAttendance', {
required: true,
validate: validateExpectedAttendance,
})}
/>
</div>
<div className="mb-6">
Expand Down

0 comments on commit 1614a85

Please sign in to comment.