From 91bccba871df1e327b78c4a99b3beec00d5c5a0f Mon Sep 17 00:00:00 2001 From: Davenludd Date: Thu, 4 Apr 2024 22:20:09 +0200 Subject: [PATCH] Add username parameter and error alerts in GetOtherUsersReport component --- .../src/Components/ViewOtherTimeReport.tsx | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/frontend/src/Components/ViewOtherTimeReport.tsx b/frontend/src/Components/ViewOtherTimeReport.tsx index bde0529..3689854 100644 --- a/frontend/src/Components/ViewOtherTimeReport.tsx +++ b/frontend/src/Components/ViewOtherTimeReport.tsx @@ -31,8 +31,9 @@ export default function GetOtherUsersReport(): JSX.Element { projectName ?? "", fetchedWeek?.toString() ?? "0", token, + username ?? "", ); - + console.log(response); if (response.success) { const report: WeeklyReport = response.data ?? { reportId: 0, @@ -62,25 +63,33 @@ export default function GetOtherUsersReport(): JSX.Element { void fetchUsersWeeklyReport(); }); - const handleSignWeeklyReport = async (): Promise => { - await api.signReport(reportId, token); + const handleSignWeeklyReport = async (): Promise => { + const response = await api.signReport(reportId, token); + if (response.success) { + return true; + } else { + return false; + } }; const navigate = useNavigate(); return ( <> -

- {" "} - UserId: {username}'s Report -

+

{username}'s Report

{ e.preventDefault(); - void handleSignWeeklyReport(); - alert("Report successfully signed!"); - navigate(-1); + void (async (): Promise => { + const success = await handleSignWeeklyReport(); + if (!success) { + alert("Failed to sign report!"); + return; + } + alert("Report successfully signed!"); + navigate(-1); + })(); }} >