@@ -25,14 +25,15 @@ import {
2525 BackendSubmission ,
2626 ChallengeDetailContextModel ,
2727 convertBackendSubmissionToSubmissionInfo ,
28+ ReviewAppContextModel ,
2829 SubmissionInfo ,
2930} from '../../models'
3031import { TableNoRecord } from '../TableNoRecord'
3132import { TableWrapper } from '../TableWrapper'
3233import { SubmissionHistoryModal } from '../SubmissionHistoryModal'
3334import { useSubmissionDownloadAccess } from '../../hooks/useSubmissionDownloadAccess'
3435import type { UseSubmissionDownloadAccessResult } from '../../hooks/useSubmissionDownloadAccess'
35- import { ChallengeDetailContext } from '../../contexts'
36+ import { ChallengeDetailContext , ReviewAppContext } from '../../contexts'
3637import {
3738 challengeHasSubmissionLimit ,
3839 getSubmissionHistoryKey ,
@@ -42,6 +43,7 @@ import {
4243import type { SubmissionHistoryPartition } from '../../utils'
4344import { TABLE_DATE_FORMAT } from '../../../config/index.config'
4445import { CollapsibleAiReviewsRow } from '../CollapsibleAiReviewsRow'
46+ import { useRolePermissions , UseRolePermissionsResult } from '../../hooks'
4547
4648import styles from './TabContentSubmissions.module.scss'
4749
@@ -67,9 +69,36 @@ export const TabContentSubmissions: FC<Props> = props => {
6769 isSubmissionDownloadRestrictedForMember,
6870 getRestrictionMessageForMember,
6971 } : UseSubmissionDownloadAccessResult = useSubmissionDownloadAccess ( )
72+ const { loginUserInfo } : ReviewAppContextModel = useContext ( ReviewAppContext )
73+ const { canViewAllSubmissions } : UseRolePermissionsResult = useRolePermissions ( )
7074
7175 const { challengeInfo } : ChallengeDetailContextModel = useContext ( ChallengeDetailContext )
7276
77+ const isCompletedDesignChallenge = useMemo ( ( ) => {
78+ if ( ! challengeInfo ) return false
79+ const type = challengeInfo . track . name ? String ( challengeInfo . track . name )
80+ . toLowerCase ( ) : ''
81+ const status = challengeInfo . status ? String ( challengeInfo . status )
82+ . toLowerCase ( ) : ''
83+ return type === 'design' && (
84+ status === 'completed'
85+ )
86+ } , [ challengeInfo ] )
87+
88+ const isSubmissionsViewable = useMemo ( ( ) => {
89+ if ( ! challengeInfo ?. metadata ?. length ) return false
90+ return challengeInfo . metadata . some ( m => m . name === 'submissionsViewable' && String ( m . value )
91+ . toLowerCase ( ) === 'true' )
92+ } , [ challengeInfo ] )
93+
94+ const canViewSubmissions = useMemo ( ( ) => {
95+ if ( isCompletedDesignChallenge ) {
96+ return canViewAllSubmissions || isSubmissionsViewable
97+ }
98+
99+ return true
100+ } , [ isCompletedDesignChallenge , isSubmissionsViewable , canViewAllSubmissions ] )
101+
73102 const submissionMetaById = useMemo (
74103 ( ) => {
75104 const map = new Map < string , BackendSubmission > ( )
@@ -205,19 +234,32 @@ export const TabContentSubmissions: FC<Props> = props => {
205234
206235 const filteredSubmissions = useMemo < BackendSubmission [ ] > (
207236 ( ) => {
237+
238+ const filterFunc = ( submissions : BackendSubmission [ ] ) : BackendSubmission [ ] => submissions
239+ . filter ( submission => {
240+ if ( ! canViewSubmissions ) {
241+ return String ( submission . memberId ) === String ( loginUserInfo ?. userId )
242+ }
243+
244+ return true
245+ } )
246+ const filteredByUserId = filterFunc ( latestBackendSubmissions )
247+ const filteredByUserIdSubmissions = filterFunc ( props . submissions )
208248 if ( restrictToLatest && hasLatestFlag ) {
209249 return latestBackendSubmissions . length
210- ? latestBackendSubmissions
211- : props . submissions
250+ ? filteredByUserId
251+ : filteredByUserIdSubmissions
212252 }
213253
214- return props . submissions
254+ return filteredByUserIdSubmissions
215255 } ,
216256 [
217257 latestBackendSubmissions ,
218258 props . submissions ,
219259 restrictToLatest ,
220260 hasLatestFlag ,
261+ canViewSubmissions ,
262+ loginUserInfo ?. userId ,
221263 ] ,
222264 )
223265
0 commit comments