Add username parameter and error alerts in GetOtherUsersReport component
This commit is contained in:
parent
a6f3fc4a1c
commit
91bccba871
1 changed files with 19 additions and 10 deletions
|
@ -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}'s Report
|
||||
</h1>
|
||||
<h1 className="text-[30px] font-bold"> {username}'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">
|
||||
|
|
Loading…
Reference in a new issue