1
- import React , { FC , useEffect , useState } from 'react' ;
1
+ import React , { FC , useContext , useEffect , useState } from 'react' ;
2
2
import { LightFormInfo } from 'types/form' ;
3
3
import { Link } from 'react-router-dom' ;
4
4
import FormStatus from './FormStatus' ;
5
5
import QuickAction from './QuickAction' ;
6
6
import { default as i18n } from 'i18next' ;
7
+ import { AuthContext } from '../../..' ;
7
8
8
9
type FormRowProps = {
9
10
form : LightFormInfo ;
10
11
} ;
11
12
13
+ const SUBJECT_ELECTION = 'election' ;
14
+ const ACTION_CREATE = 'create' ;
15
+
12
16
const FormRow : FC < FormRowProps > = ( { form } ) => {
13
17
const [ titles , setTitles ] = useState < any > ( { } ) ;
18
+ const authCtx = useContext ( AuthContext ) ;
14
19
useEffect ( ( ) => {
15
20
if ( form . Title === undefined ) return ;
16
21
setTitles ( { En : form . Title . En , Fr : form . Title . Fr , De : form . Title . De , URL : form . Title . URL } ) ;
@@ -25,14 +30,17 @@ const FormRow: FC<FormRowProps> = ({ form }) => {
25
30
formRowI18n . addResource ( lang . toLowerCase ( ) , 'form' , 'title' , title ) ;
26
31
}
27
32
} ) ;
33
+ const formTitle = formRowI18n . t ( 'title' , { ns : 'form' , fallbackLng : 'en' } ) ;
28
34
return (
29
35
< tr className = "bg-white border-b hover:bg-gray-50 " >
30
36
< td className = "px-1.5 sm:px-6 py-4 font-medium text-gray-900 whitespace-nowrap truncate" >
31
- < Link className = "text-gray-700 hover:text-[#ff0000]" to = { `/forms/${ form . FormID } ` } >
32
- < div className = "max-w-[20vw] truncate" >
33
- { formRowI18n . t ( 'title' , { ns : 'form' , fallbackLng : 'en' } ) }
34
- </ div >
35
- </ Link >
37
+ { authCtx . isLogged && authCtx . isAllowed ( SUBJECT_ELECTION , ACTION_CREATE ) ? (
38
+ < Link className = "text-gray-700 hover:text-[#ff0000]" to = { `/forms/${ form . FormID } ` } >
39
+ < div className = "max-w-[20vw] truncate" > { formTitle } </ div >
40
+ </ Link >
41
+ ) : (
42
+ < div className = "max-w-[20vw] truncate" > { formTitle } </ div >
43
+ ) }
36
44
</ td >
37
45
< td className = "px-1.5 sm:px-6 py-4" > { < FormStatus status = { form . Status } /> } </ td >
38
46
< td className = "px-1.5 sm:px-6 py-4 text-right" >
0 commit comments