@@ -16,6 +16,7 @@ import { fetchCurrentCommunity } from "@/store/services/community.service";
16
16
import { Submission as SubmissionType } from "@/types/bounty" ;
17
17
import { Community } from "@/types/community" ;
18
18
import { Challenge } from "@/types/course" ;
19
+ import { NotFoundError } from "@/utilities/errors/NotFoundError" ;
19
20
import { localePath } from "@/utilities/Routing" ;
20
21
import { GetServerSideProps } from "next" ;
21
22
import { useTranslation } from "next-i18next" ;
@@ -53,21 +54,24 @@ export default function Submission(props: { pageProps: { currentCommunity: Commu
53
54
dispatch ( initChallengeNavigationMenu ( navigation . community ) ) ;
54
55
} , [ navigation . community , dispatch ] ) ;
55
56
56
- const handleShowSubmission = useCallback ( ( e : any ) => {
57
+ const handleShowSubmission = useCallback (
58
+ ( e : any ) => {
57
59
const newUrl = e . detail ;
58
- const submissionId = newUrl . replace ( localePath ( router , router . asPath ) , "" ) . replace ( / \/ / g, '' ) ;
60
+ const submissionId = newUrl . replace ( localePath ( router , router . asPath ) , "" ) . replace ( / \/ / g, "" ) ;
59
61
const submission = submissions . find ( ( submission ) => submission . id === submissionId ) ;
60
62
if ( ! submission ) return ;
61
63
dispatch ( showSubmission ( submissionId ) ) ;
62
64
dispatch ( toggleBodyScrolling ( true ) ) ;
63
- } , [ dispatch , router , submissions ] ) ;
65
+ } ,
66
+ [ dispatch , router , submissions ]
67
+ ) ;
64
68
65
69
useEffect ( ( ) => {
66
- window . addEventListener ( ' onSoftNavigation' , handleShowSubmission ) ;
67
- window . addEventListener ( ' popstate' , handleCloseSubmission ) ;
70
+ window . addEventListener ( " onSoftNavigation" , handleShowSubmission ) ;
71
+ window . addEventListener ( " popstate" , handleCloseSubmission ) ;
68
72
return ( ) => {
69
- window . removeEventListener ( ' onSoftNavigation' , handleShowSubmission ) ;
70
- window . removeEventListener ( ' popstate' , handleCloseSubmission ) ;
73
+ window . removeEventListener ( " onSoftNavigation" , handleShowSubmission ) ;
74
+ window . removeEventListener ( " popstate" , handleCloseSubmission ) ;
71
75
} ;
72
76
} , [ handleCloseSubmission , handleShowSubmission ] ) ;
73
77
@@ -105,19 +109,26 @@ export const getServerSideProps: GetServerSideProps = wrapper.getServerSideProps
105
109
const { slug, challenge_id } = query ;
106
110
const { dispatch } = store ;
107
111
108
- const [ { data : currentCommunity } , { data : submissions } , { data : challenge } , translations ] = await Promise . all ( [
109
- dispatch ( fetchCurrentCommunity ( { slug : slug as string , locale : locale as string } ) ) ,
110
- dispatch ( fetchAllSubmission ( { challengeId : challenge_id as string , locale : locale as string } ) ) ,
111
- dispatch ( fetchChallenge ( { id : challenge_id as string , relations : [ "rubric" , "courses" , "learning-modules" ] } ) ) ,
112
- serverSideTranslations ( locale as string ) ,
113
- ] ) ;
112
+ try {
113
+ const [ { data : currentCommunity } , { data : submissions } , { data : challenge } , translations ] = await Promise . all ( [
114
+ dispatch ( fetchCurrentCommunity ( { slug : slug as string , locale : locale as string } ) ) ,
115
+ dispatch ( fetchAllSubmission ( { challengeId : challenge_id as string , locale : locale as string } ) ) ,
116
+ dispatch ( fetchChallenge ( { id : challenge_id as string , relations : [ "rubric" , "courses" , "learning-modules" ] } ) ) ,
117
+ serverSideTranslations ( locale as string ) ,
118
+ ] ) ;
114
119
115
- return {
116
- props : {
117
- currentCommunity,
118
- submissions,
119
- challenge,
120
- ...translations ,
121
- } ,
122
- } ;
120
+ if ( ! currentCommunity || ! challenge || ! submissions ) throw new NotFoundError ( ) ;
121
+ return {
122
+ props : {
123
+ currentCommunity,
124
+ submissions,
125
+ challenge,
126
+ ...translations ,
127
+ } ,
128
+ } ;
129
+ } catch ( error ) {
130
+ return {
131
+ notFound : true ,
132
+ } ;
133
+ }
123
134
} ) ;
0 commit comments