1
- import React , { useCallback , useEffect , useMemo } from "react" ;
1
+ import React , { useCallback , useEffect , useMemo , useState } from "react" ;
2
2
import cn from "classnames" ;
3
3
import { Link , useOutletContext , useSearchParams } from "react-router-dom" ;
4
4
import { toast } from "react-toastify" ;
@@ -15,6 +15,8 @@ import { useLocale } from "../../providers/AppLocaleProvider";
15
15
import AppButton from "../common/Buttons/AppButton" ;
16
16
import AppRoutes from "../../navigation/AppRoutes" ;
17
17
import { useEffectOnce } from "../../hooks/useEffectOnce" ;
18
+ import { validateEmail } from "../../utils/regex" ;
19
+ import Tooltip from "../common/Tooltip/Tooltip" ;
18
20
import {
19
21
Proposal ,
20
22
ProposalVote ,
@@ -152,26 +154,54 @@ const RemindToVoteButton: React.FC<{
152
154
proposal : Proposal ;
153
155
vote : ProposalVote ;
154
156
} > = ( { proposal, vote } ) => {
157
+ const { translate } = useLocale ( ) ;
158
+ const [ containerRef , setContainerRef ] = useState < HTMLElement | null > ( null ) ;
159
+ const [ buttonRef , setButtonRef ] = useState < HTMLElement | null > ( null ) ;
160
+
155
161
if (
156
162
vote . option != null ||
157
163
vote . voter . __typename !== "Validator" ||
158
- vote . voter . securityContact == null ||
159
164
proposal . status !== ProposalStatus . VotingPeriod
160
165
) {
161
166
return null ;
162
167
}
163
168
164
- const email : string = vote . voter . securityContact ;
169
+ const email = vote . voter . securityContact ;
170
+ const validatedEmail : string | null =
171
+ email && validateEmail ( email ) ? email : null ;
165
172
166
173
return (
167
- < AppButton
168
- type = "anchor"
169
- theme = "secondary"
170
- size = "regular"
171
- className = { cn ( "border" , "border-app-grey" ) }
172
- messageID = "ProposalDetail.votes.remindToVote"
173
- href = { `mailto:${ email } ` }
174
- />
174
+ < div
175
+ ref = { setContainerRef }
176
+ className = { cn ( "flex" , "cursor-not-allowed" , "justify-end" ) }
177
+ >
178
+ < AppButton
179
+ type = "anchor"
180
+ theme = "secondary"
181
+ size = "regular"
182
+ ref = { setButtonRef }
183
+ className = { cn (
184
+ "border" ,
185
+ "border-app-grey" ,
186
+ validatedEmail == null
187
+ ? cn ( "bg-gray-300" , "pointer-events-none" )
188
+ : null
189
+ ) }
190
+ messageID = "ProposalDetail.votes.remindToVote"
191
+ href = { validatedEmail != null ? `mailto:${ validatedEmail } ` : "" }
192
+ />
193
+ { validatedEmail == null && (
194
+ < Tooltip
195
+ parentElement = { buttonRef }
196
+ triggerElement = { containerRef }
197
+ content = { translate ( "ProposalDetail.votes.voter.noSecurityContact" ) }
198
+ popperOptions = { {
199
+ placement : "bottom-start" ,
200
+ modifiers : [ { name : "offset" , options : { offset : [ 20 , 10 ] } } ] ,
201
+ } }
202
+ />
203
+ ) }
204
+ </ div >
175
205
) ;
176
206
} ;
177
207
0 commit comments