@@ -45,32 +45,44 @@ const SignatureCard = ({
45
45
const { userDetails } = useSecurity ( ) ;
46
46
47
47
const [ userSignature , setUserSignature ] = useState < UserType > ( ) ;
48
- const [ role , setRole ] = useState ( '' ) ;
48
+ const [ role , setRole ] = useState < string > ( ) ;
49
49
50
50
useEffect ( ( ) => {
51
+ if ( type ) { // need to do these separately because signatures may be null
52
+ if ( type === 'author' ) {
53
+ setRole ( 'author' ) ;
54
+ } else if ( type === 'reviewer' ) {
55
+ setRole ( 'reviewer' ) ;
56
+ } else if ( type === 'creator' ) {
57
+ setRole ( 'creator' ) ;
58
+ }
59
+ }
51
60
if ( signatures && type ) {
52
61
if ( type === 'author' ) {
53
62
setUserSignature ( signatures . authorSignature ) ;
54
- setRole ( 'author' ) ;
55
63
} else if ( type === 'reviewer' ) {
56
64
setUserSignature ( signatures . reviewerSignature ) ;
57
- setRole ( 'reviewer' ) ;
58
65
} else if ( type === 'creator' ) {
59
66
setUserSignature ( signatures . creatorSignature ) ;
60
- setRole ( 'bioinformatician' ) ;
61
67
}
62
68
}
63
69
} , [ signatures , type , setRole ] ) ;
64
70
65
71
const handleSign = useCallback ( async ( ) => {
66
72
let newReport = null ;
67
73
74
+ let reportRole = role ;
68
75
// Assign user
69
76
try {
77
+ if ( role === 'creator' ) {
78
+ reportRole = 'bioinformatician' ;
79
+ } else if ( role === 'author' ) {
80
+ // Hardcode analyst role here because report does not accept 'author'
81
+ reportRole = 'analyst' ;
82
+ }
70
83
newReport = await api . post (
71
84
`/reports/${ report . ident } /user` ,
72
- // Hardcode analyst role here because report does not accept 'author'
73
- { user : userDetails . ident , role : 'analyst' } ,
85
+ { user : userDetails . ident , role : reportRole } ,
74
86
{ } ,
75
87
) . request ( ) ;
76
88
} catch ( e ) {
@@ -79,7 +91,6 @@ const SignatureCard = ({
79
91
snackbar . error ( 'Error assigning user to report: ' , e . message ) ;
80
92
}
81
93
}
82
-
83
94
// Do signature
84
95
try {
85
96
const newSignature = await api . put (
@@ -198,9 +209,9 @@ const SignatureCard = ({
198
209
Date
199
210
</ Typography >
200
211
{ renderDate ?? (
201
- < Typography >
202
- { NON_BREAKING_SPACE }
203
- </ Typography >
212
+ < Typography >
213
+ { NON_BREAKING_SPACE }
214
+ </ Typography >
204
215
) }
205
216
</ div >
206
217
{ userSignature ?. ident && canEdit && (
0 commit comments