Refactor fetchWeeklyReport in EditWeeklyReport component
This commit is contained in:
parent
7c73a01d4c
commit
48e4d1a8df
1 changed files with 38 additions and 35 deletions
|
@ -18,44 +18,47 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
const [testingTime, setTestingTime] = useState(0);
|
||||
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const { projectName } = useParams();
|
||||
const { fetchedWeek } = useParams();
|
||||
|
||||
const fetchWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
projectName ?? "",
|
||||
fetchedWeek?.toString() ?? "0",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: WeeklyReport = response.data ?? {
|
||||
reportId: 0,
|
||||
userId: 0,
|
||||
projectId: 0,
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
const { projectName, fetchedWeek } = useParams<{
|
||||
projectName: string;
|
||||
fetchedWeek: string;
|
||||
}>();
|
||||
console.log(projectName, fetchedWeek);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
projectName ?? "",
|
||||
fetchedWeek ?? "",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: WeeklyReport = response.data ?? {
|
||||
reportId: 0,
|
||||
userId: 0,
|
||||
projectId: 0,
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchWeeklyReport();
|
||||
});
|
||||
}, [projectName, fetchedWeek, token]);
|
||||
|
||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||
const newWeeklyReport: NewWeeklyReport = {
|
||||
|
|
Loading…
Reference in a new issue