diff --git a/web/app/schedules/home/components/GenerateScheduleButton.tsx b/web/app/schedules/home/components/GenerateScheduleButton.tsx index e8dff75..c96dfdc 100644 --- a/web/app/schedules/home/components/GenerateScheduleButton.tsx +++ b/web/app/schedules/home/components/GenerateScheduleButton.tsx @@ -1,47 +1,110 @@ -'use router'; +'use client'; import { useRouter } from 'next/navigation'; +import { useState } from 'react'; import useClassesToShow from '@/app/hooks/useClassesToShow'; import useSelectedClasses from '@/app/hooks/useSelectedClasses'; import useSchedules from '@/app/hooks/useSchedules'; +import useUser from '@/app/hooks/useUser'; import Button from '@/app/components/Button'; +import Modal from '@/app/components/Modal/Modal'; import { ScheduleClassType } from '@/app/contexts/SchedulesContext'; -import generateSchedule from '@/app/utils/api/generateSchedule'; +import generateSchedule, { EachFieldNumber } from '@/app/utils/api/generateSchedule'; import { errorToast } from '@/app/utils/errorToast'; +function PreferenceOrder({ setPreference }: { + setPreference: (preference: EachFieldNumber) => void +}) { + return ( + + ); +} + export default function GenerateScheduleButton() { const router = useRouter(); + const { setLoading } = useUser(); const { setLocalSchedules } = useSchedules(); const { selectedClasses } = useSelectedClasses(); const { classesToShow } = useClassesToShow(); - const createSchedule = async () => { + const [activeModal, setActiveModal] = useState(false); + const [morningPreference, setMorningPreference] = useState(1); + const [afternoonPreference, setAfternoonPreference] = useState(1); + const [nightPreference, setNightPreference] = useState(1); + + const createSchedule = () => { let classes_id = new Array(); selectedClasses.forEach((_class) => { Array.from(_class.keys()).forEach((key) => { classes_id.push(key); }); }); - const response = await generateSchedule(classes_id); - if (response.status === 200) { - const schedules = response.data as Array; - if (!schedules.length) { - errorToast('Nenhuma grade conseguiu ser gerada!'); + + setLoading(true); + generateSchedule(classes_id, [morningPreference, afternoonPreference, nightPreference]).then((response) => { + if (response.status === 200) { + const schedules = response.data as Array; + + if (!schedules.length) { + errorToast('Nenhuma grade conseguiu ser gerada!'); + setLoading(false); + } else { + setLocalSchedules(schedules); + router.replace('/schedules/mygrades'); + setTimeout(() => { + setLoading(false); + }, 500); + } } else { - setLocalSchedules(schedules); - router.replace('/schedules/mygrades'); + errorToast('Não foi possível gerar as grades, tente novamente mais tarde!'); + setLoading(false); } - } else errorToast('Não foi possível gerar as grades, tente novamente mais tarde!'); + }); }; + return ( -
- -
+ <> + {activeModal && + +
+

Período de preferência

+ +
+
+ Manhã + Tarde + Noite +
+
+ + + +
+
+ +
+ + +
+
+
+ } +
+ +
+ ); } \ No newline at end of file diff --git a/web/app/schedules/layout.tsx b/web/app/schedules/layout.tsx index ee61cec..8cefdd2 100644 --- a/web/app/schedules/layout.tsx +++ b/web/app/schedules/layout.tsx @@ -1,21 +1,22 @@ 'use client'; import { usePathname, useRouter } from 'next/navigation'; -import useUser from '@/app/hooks/useUser'; import { useCallback, useState } from 'react'; -import Button from '../components/Button'; -import Image from 'next/image'; +import useUser from '@/app/hooks/useUser'; +import useWindowDimensions from '../hooks/useWindowDimensions'; +import Image from 'next/image'; +import Button from '../components/Button'; import AsideButton from '../components/AsideButton'; import Protected from '../components/Protected'; import InfoHeader from '../components/InfoHeader'; +import { LoadingScreen } from '../components/LoadingScreen'; import homeIcon from '@/public/icons/home.jpg'; import infoIcon from '@/public/icons/info.jpg'; import googleIcon from '@/public/icons/google.jpg'; import scheduleIcon from '@/public/icons/schedule.jpg'; import profileIcon from '@/public/icons/profile.jpg'; -import useWindowDimensions from '../hooks/useWindowDimensions'; function calculatePositionOfBlob(node: any, width: number, footerWidth: number) { const infos = node.getBoundingClientRect(); @@ -33,7 +34,7 @@ function LogoReturnButton() { user.is_anonymous &&