@@ -12,7 +12,7 @@ import { CacheTag } from "@/utils/cacheTag";
12
12
import { type AsyncActionResponse , handleAsync } from "@/utils/handleAsync" ;
13
13
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData" ;
14
14
import routePaths from "@/utils/routePaths" ;
15
- import { Forms } from "@/utils/form/formsEnums" ;
15
+ import { Forms , UserRole } from "@/utils/form/formsEnums" ;
16
16
import { type Question , type TeamMemberForCheckbox } from "@/utils/form/types" ;
17
17
import { getSprintCheckinIsStatus } from "@/utils/getFormStatus" ;
18
18
import { getCurrentSprint } from "@/utils/getCurrentSprint" ;
@@ -75,6 +75,11 @@ export default async function WeeklyCheckInWrapper({
75
75
let description = "" ;
76
76
let questions = [ ] as Question [ ] ;
77
77
78
+ let hasProductOwner = false ;
79
+ let hasScrumMaster = false ;
80
+ let isScrumMaster = false ;
81
+ let isProductOwner = false ;
82
+
78
83
const [ user , error ] = await getUser ( ) ;
79
84
80
85
const { errorResponse, data } = await getCurrentVoyageData ( {
@@ -141,6 +146,25 @@ export default async function WeeklyCheckInWrapper({
141
146
} ) . voyageTeamMemberId ;
142
147
}
143
148
149
+ // Check if a team has a product owner or a scrum muster and if a user is a team has a product owner or a scrum muster
150
+ hasScrumMaster = ! ! res . voyageTeamMembers . find (
151
+ ( member ) =>
152
+ member . voyageRole . name === UserRole . scrumMaster . toString ( ) ,
153
+ ) ;
154
+
155
+ hasProductOwner = ! ! res . voyageTeamMembers . find (
156
+ ( member ) =>
157
+ member . voyageRole . name === UserRole . productOwner . toString ( ) ,
158
+ ) ;
159
+
160
+ const currentUserRole = res . voyageTeamMembers . find (
161
+ ( member ) => member . id === voyageTeamMemberId ,
162
+ ) ?. voyageRole . name ;
163
+
164
+ isScrumMaster = currentUserRole === UserRole . scrumMaster . toString ( ) ;
165
+
166
+ isProductOwner = currentUserRole === UserRole . productOwner . toString ( ) ;
167
+
144
168
// Get all teamMembers except for the current user
145
169
if ( voyageTeamMemberId ) {
146
170
teamMembers = res . voyageTeamMembers
@@ -163,7 +187,7 @@ export default async function WeeklyCheckInWrapper({
163
187
) ;
164
188
}
165
189
166
- // Fetch form
190
+ // Fetch general checkin form
167
191
const [ formRes , formError ] = await fetchFormQuestions ( {
168
192
formId : Forms . checkIn ,
169
193
} ) ;
@@ -176,8 +200,49 @@ export default async function WeeklyCheckInWrapper({
176
200
/>
177
201
) ;
178
202
}
203
+
179
204
if ( formRes && formRes ?. description ) description = formRes . description ;
180
205
if ( formRes && formRes ?. questions ) questions = formRes . questions ;
206
+
207
+ // Fetch PO checkin questions (form)
208
+ if ( hasProductOwner && ! isProductOwner ) {
209
+ const [ POformRes , POformError ] = await fetchFormQuestions ( {
210
+ formId : Forms . checkinPO ,
211
+ } ) ;
212
+
213
+ if ( POformError ) {
214
+ return (
215
+ < ErrorComponent
216
+ errorType = { ErrorType . FETCH_FORM_QUESTIONS }
217
+ message = { POformError . message }
218
+ />
219
+ ) ;
220
+ }
221
+
222
+ if ( POformRes && POformRes ?. questions )
223
+ questions = [ ...questions , ...POformRes . questions ] ;
224
+ }
225
+
226
+ // Fetch SM checkin questions (form)
227
+ if ( hasScrumMaster && ! isScrumMaster ) {
228
+ const [ SMformRes , SMformError ] = await fetchFormQuestions ( {
229
+ formId : Forms . checkinSM ,
230
+ } ) ;
231
+
232
+ if ( SMformError ) {
233
+ return (
234
+ < ErrorComponent
235
+ errorType = { ErrorType . FETCH_FORM_QUESTIONS }
236
+ message = { SMformError . message }
237
+ />
238
+ ) ;
239
+ }
240
+
241
+ if ( SMformRes && SMformRes ?. questions )
242
+ questions = [ ...questions , ...SMformRes . questions ] ;
243
+ }
244
+
245
+ questions = questions . sort ( ( a , b ) => a . order - b . order ) ;
181
246
}
182
247
} else {
183
248
redirect ( routePaths . dashboardPage ( ) ) ;
0 commit comments