diff --git a/frontend/src/Components/NewWeeklyReport.tsx b/frontend/src/Components/NewWeeklyReport.tsx index 1204e11..b0bccac 100644 --- a/frontend/src/Components/NewWeeklyReport.tsx +++ b/frontend/src/Components/NewWeeklyReport.tsx @@ -22,7 +22,7 @@ export default function NewWeeklyReport(): JSX.Element { const { projectName } = useParams(); const token = localStorage.getItem("accessToken") ?? ""; - const handleNewWeeklyReport = async (): Promise => { + const handleNewWeeklyReport = async (): Promise => { const newWeeklyReport: NewWeeklyReport = { projectName: projectName ?? "", week: week, @@ -34,7 +34,13 @@ export default function NewWeeklyReport(): JSX.Element { testingTime: testingTime, }; - await api.submitWeeklyReport(newWeeklyReport, token); + const response = await api.submitWeeklyReport(newWeeklyReport, token); + console.log(response); + if (response.success) { + return true; + } else { + return false; + } }; const navigate = useNavigate(); @@ -46,14 +52,22 @@ export default function NewWeeklyReport(): JSX.Element {
{ - if (week === 0 || week > 53 || week < 1) { - alert("Please enter a valid week number"); - e.preventDefault(); - return; - } e.preventDefault(); - void handleNewWeeklyReport(); - navigate(-1); + void (async (): Promise => { + if (week === 0 || week > 53 || week < 1) { + alert("Please enter a valid week number"); + return; + } + + const success = await handleNewWeeklyReport(); + if (!success) { + alert( + "A Time Report for this week already exists, please go to the edit page to edit it or change week number.", + ); + return; + } + navigate(-1); + })(); }} >