1
1
import React , { useCallback , useEffect , useState } from "react" ;
2
2
3
- import { ActivityTypeEnum } from "@sparcs-clubs/interface/common/enum/activity.enum " ;
3
+ import { IStudentSummary } from "@sparcs-clubs/interface/api/user/type/user.type " ;
4
4
5
+ import { ActivityTypeEnum } from "@sparcs-clubs/interface/common/enum/activity.enum" ;
5
6
import { FormProvider , useForm } from "react-hook-form" ;
6
7
7
8
import AsyncBoundary from "@sparcs-clubs/web/common/components/AsyncBoundary" ;
8
9
import Button from "@sparcs-clubs/web/common/components/Button" ;
9
10
import Card from "@sparcs-clubs/web/common/components/Card" ;
11
+ import { FileDetail } from "@sparcs-clubs/web/common/components/File/attachment" ;
10
12
import FileUpload from "@sparcs-clubs/web/common/components/FileUpload" ;
11
13
import FlexWrapper from "@sparcs-clubs/web/common/components/FlexWrapper" ;
12
14
import FormController from "@sparcs-clubs/web/common/components/FormController" ;
@@ -24,17 +26,52 @@ import SelectParticipant from "./SelectParticipant";
24
26
interface ActivityReportFormProps {
25
27
clubId : number ;
26
28
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
+
27
43
onSubmit : ( data : ActivityReportFormData ) => void ;
28
44
}
29
45
30
46
const ActivityReportForm : React . FC < ActivityReportFormProps > = ( {
31
47
clubId,
32
48
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
+
33
60
onSubmit,
34
61
} ) => {
35
62
const formCtx = useForm < ActivityReportFormData > ( {
36
63
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
+ } ,
38
75
} ) ;
39
76
40
77
const {
@@ -60,6 +97,13 @@ const ActivityReportForm: React.FC<ActivityReportFormProps> = ({
60
97
const participants = watch ( "participants" ) ;
61
98
const evidenceFiles = watch ( "evidenceFiles" ) ;
62
99
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
+
63
107
const [ startTerm , setStartTerm ] = useState < Date > (
64
108
durations
65
109
?. map ( d => d . startTerm )
@@ -82,6 +126,68 @@ const ActivityReportForm: React.FC<ActivityReportFormProps> = ({
82
126
endTerm,
83
127
} ) ;
84
128
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
+
85
191
useEffect ( ( ) => {
86
192
if ( startTerm && endTerm ) {
87
193
refetch ( ) ;
0 commit comments