Skip to content

Commit a559039

Browse files
committed
feat: temporary storage feature for activity report creation using localstorage
1 parent e27a062 commit a559039

File tree

3 files changed

+152
-4
lines changed

3 files changed

+152
-4
lines changed

Diff for: .npmrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
engine-strict=true
1+
engine-strict=true
2+
use-node-version=22.12.0

Diff for: packages/web/src/features/activity-report/components/ActivityReportForm.tsx

+108-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { useCallback, useEffect, useState } from "react";
22

3-
import { ActivityTypeEnum } from "@sparcs-clubs/interface/common/enum/activity.enum";
3+
import { IStudentSummary } from "@sparcs-clubs/interface/api/user/type/user.type";
44

5+
import { ActivityTypeEnum } from "@sparcs-clubs/interface/common/enum/activity.enum";
56
import { FormProvider, useForm } from "react-hook-form";
67

78
import AsyncBoundary from "@sparcs-clubs/web/common/components/AsyncBoundary";
89
import Button from "@sparcs-clubs/web/common/components/Button";
910
import Card from "@sparcs-clubs/web/common/components/Card";
11+
import { FileDetail } from "@sparcs-clubs/web/common/components/File/attachment";
1012
import FileUpload from "@sparcs-clubs/web/common/components/FileUpload";
1113
import FlexWrapper from "@sparcs-clubs/web/common/components/FlexWrapper";
1214
import FormController from "@sparcs-clubs/web/common/components/FormController";
@@ -24,17 +26,52 @@ import SelectParticipant from "./SelectParticipant";
2426
interface ActivityReportFormProps {
2527
clubId: number;
2628
initialData?: ActivityReportFormData;
29+
30+
temporaryStorageName?: string;
31+
temporaryStorageActivityTypeEnumId?: ActivityTypeEnum;
32+
temporaryStorageDurations?: {
33+
startTerm: Date;
34+
endTerm: Date;
35+
}[];
36+
temporaryStorageLocation?: string;
37+
temporaryStoragePurpose?: string;
38+
temporaryStorageDetail?: string;
39+
temporaryStorageEvidence?: string;
40+
temporaryStorageEvidenceFiles?: FileDetail[];
41+
temporaryStorageParticipants?: IStudentSummary[];
42+
2743
onSubmit: (data: ActivityReportFormData) => void;
2844
}
2945

3046
const ActivityReportForm: React.FC<ActivityReportFormProps> = ({
3147
clubId,
3248
initialData = undefined,
49+
50+
temporaryStorageName = undefined,
51+
temporaryStorageActivityTypeEnumId = undefined,
52+
temporaryStorageDurations = undefined,
53+
temporaryStorageLocation = undefined,
54+
temporaryStoragePurpose = undefined,
55+
temporaryStorageDetail = undefined,
56+
temporaryStorageEvidence = undefined,
57+
temporaryStorageEvidenceFiles = undefined,
58+
temporaryStorageParticipants = undefined,
59+
3360
onSubmit,
3461
}) => {
3562
const formCtx = useForm<ActivityReportFormData>({
3663
mode: "all",
37-
defaultValues: initialData,
64+
defaultValues: initialData || {
65+
name: temporaryStorageName,
66+
activityTypeEnumId: temporaryStorageActivityTypeEnumId,
67+
durations: temporaryStorageDurations,
68+
location: temporaryStorageLocation,
69+
purpose: temporaryStoragePurpose,
70+
detail: temporaryStorageDetail,
71+
evidence: temporaryStorageEvidence,
72+
evidenceFiles: temporaryStorageEvidenceFiles,
73+
participants: temporaryStorageParticipants,
74+
},
3875
});
3976

4077
const {
@@ -60,6 +97,13 @@ const ActivityReportForm: React.FC<ActivityReportFormProps> = ({
6097
const participants = watch("participants");
6198
const evidenceFiles = watch("evidenceFiles");
6299

100+
const name = watch("name");
101+
const activityTypeEnumId = watch("activityTypeEnumId");
102+
const location = watch("location");
103+
const purpose = watch("purpose");
104+
const detail = watch("detail");
105+
const evidence = watch("evidence");
106+
63107
const [startTerm, setStartTerm] = useState<Date>(
64108
durations
65109
?.map(d => d.startTerm)
@@ -82,6 +126,68 @@ const ActivityReportForm: React.FC<ActivityReportFormProps> = ({
82126
endTerm,
83127
});
84128

129+
useEffect(() => {
130+
localStorage.setItem(
131+
"durations",
132+
JSON.stringify(durations) === undefined
133+
? "null"
134+
: JSON.stringify(durations),
135+
);
136+
localStorage.setItem(
137+
"participants",
138+
JSON.stringify(participants) === undefined
139+
? "null"
140+
: JSON.stringify(participants),
141+
);
142+
localStorage.setItem(
143+
"evidenceFiles",
144+
JSON.stringify(evidenceFiles) === undefined
145+
? "null"
146+
: JSON.stringify(evidenceFiles),
147+
);
148+
149+
localStorage.setItem(
150+
"name",
151+
JSON.stringify(name) === undefined ? "null" : JSON.stringify(name),
152+
);
153+
localStorage.setItem(
154+
"activityTypeEnumId",
155+
JSON.stringify(activityTypeEnumId) === undefined
156+
? "null"
157+
: JSON.stringify(activityTypeEnumId),
158+
);
159+
localStorage.setItem(
160+
"location",
161+
JSON.stringify(location) === undefined
162+
? "null"
163+
: JSON.stringify(location),
164+
);
165+
localStorage.setItem(
166+
"purpose",
167+
JSON.stringify(purpose) === undefined ? "null" : JSON.stringify(purpose),
168+
);
169+
localStorage.setItem(
170+
"detail",
171+
JSON.stringify(detail) === undefined ? "null" : JSON.stringify(detail),
172+
);
173+
localStorage.setItem(
174+
"evidence",
175+
JSON.stringify(evidence) === undefined
176+
? "null"
177+
: JSON.stringify(evidence),
178+
);
179+
}, [
180+
durations,
181+
participants,
182+
evidenceFiles,
183+
name,
184+
activityTypeEnumId,
185+
location,
186+
purpose,
187+
detail,
188+
evidence,
189+
]);
190+
85191
useEffect(() => {
86192
if (startTerm && endTerm) {
87193
refetch();

Diff for: packages/web/src/features/activity-report/frames/ActivityReportCreateFrame.tsx

+42-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ const ActivityReportCreateFrame: React.FC<ActivityReportCreateFrameProps> = ({
3030
<Modal isOpen={isOpen}>
3131
<ConfirmModalContent
3232
onConfirm={() => {
33+
localStorage.removeItem("durations");
34+
localStorage.removeItem("participants");
35+
localStorage.removeItem("evidenceFiles");
36+
localStorage.removeItem("name");
37+
localStorage.removeItem("activityTypeEnumId");
38+
localStorage.removeItem("location");
39+
localStorage.removeItem("purpose");
40+
localStorage.removeItem("detail");
41+
localStorage.removeItem("evidence");
42+
3343
close();
3444
router.push("/manage-club/activity-report");
3545
}}
@@ -64,7 +74,38 @@ const ActivityReportCreateFrame: React.FC<ActivityReportCreateFrameProps> = ({
6474
title="활동 보고서 작성"
6575
enableLast
6676
/>
67-
<ActivityReportForm clubId={clubId} onSubmit={handleSubmit} />
77+
<ActivityReportForm
78+
clubId={clubId}
79+
onSubmit={handleSubmit}
80+
temporaryStorageName={
81+
JSON.parse(localStorage.getItem("name") || '""') || undefined
82+
}
83+
temporaryStorageActivityTypeEnumId={
84+
JSON.parse(localStorage.getItem("activityTypeEnumId") || '""') ||
85+
undefined
86+
}
87+
temporaryStorageDurations={
88+
JSON.parse(localStorage.getItem("durations") || '""') || undefined
89+
}
90+
temporaryStorageLocation={
91+
JSON.parse(localStorage.getItem("location") || '""') || undefined
92+
}
93+
temporaryStoragePurpose={
94+
JSON.parse(localStorage.getItem("purpose") || '""') || undefined
95+
}
96+
temporaryStorageDetail={
97+
JSON.parse(localStorage.getItem("detail") || '""') || undefined
98+
}
99+
temporaryStorageEvidence={
100+
JSON.parse(localStorage.getItem("evidence") || '""') || undefined
101+
}
102+
temporaryStorageEvidenceFiles={
103+
JSON.parse(localStorage.getItem("evidenceFiles") || '""') || undefined
104+
}
105+
temporaryStorageParticipants={
106+
JSON.parse(localStorage.getItem("participants") || '""') || undefined
107+
}
108+
/>
68109
</FlexWrapper>
69110
);
70111
};

0 commit comments

Comments
 (0)