Add username parameter and error alerts in GetOtherUsersReport component

This commit is contained in:
Davenludd 2024-04-04 22:20:09 +02:00
parent a6f3fc4a1c
commit 91bccba871

View file

@ -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<void> => {
await api.signReport(reportId, token);
const handleSignWeeklyReport = async (): Promise<boolean> => {
const response = await api.signReport(reportId, token);
if (response.success) {
return true;
} else {
return false;
}
};
const navigate = useNavigate();
return (
<>
<h1 className="text-[30px] font-bold">
{" "}
UserId: {username}&apos;s Report
</h1>
<h1 className="text-[30px] font-bold"> {username}&apos;s Report</h1>
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
<form
onSubmit={(e) => {
e.preventDefault();
void handleSignWeeklyReport();
void (async (): Promise<void> => {
const success = await handleSignWeeklyReport();
if (!success) {
alert("Failed to sign report!");
return;
}
alert("Report successfully signed!");
navigate(-1);
})();
}}
>
<div className="flex flex-col items-center">