Skip to content

Commit e4e3bb3

Browse files
committed
react-app: Show tooltip for remind to vote button if no email
refs oursky#74
1 parent 7754318 commit e4e3bb3

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

react-app/src/components/ProposalDetailScreen/ProposalVotesPanel.tsx

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useMemo } from "react";
1+
import React, { useCallback, useEffect, useMemo, useState } from "react";
22
import cn from "classnames";
33
import { Link, useOutletContext, useSearchParams } from "react-router-dom";
44
import { toast } from "react-toastify";
@@ -15,6 +15,8 @@ import { useLocale } from "../../providers/AppLocaleProvider";
1515
import AppButton from "../common/Buttons/AppButton";
1616
import AppRoutes from "../../navigation/AppRoutes";
1717
import { useEffectOnce } from "../../hooks/useEffectOnce";
18+
import { validateEmail } from "../../utils/regex";
19+
import Tooltip from "../common/Tooltip/Tooltip";
1820
import {
1921
Proposal,
2022
ProposalVote,
@@ -152,26 +154,54 @@ const RemindToVoteButton: React.FC<{
152154
proposal: Proposal;
153155
vote: ProposalVote;
154156
}> = ({ proposal, vote }) => {
157+
const { translate } = useLocale();
158+
const [containerRef, setContainerRef] = useState<HTMLElement | null>(null);
159+
const [buttonRef, setButtonRef] = useState<HTMLElement | null>(null);
160+
155161
if (
156162
vote.option != null ||
157163
vote.voter.__typename !== "Validator" ||
158-
vote.voter.securityContact == null ||
159164
proposal.status !== ProposalStatus.VotingPeriod
160165
) {
161166
return null;
162167
}
163168

164-
const email: string = vote.voter.securityContact;
169+
const email = vote.voter.securityContact;
170+
const validatedEmail: string | null =
171+
email && validateEmail(email) ? email : null;
165172

166173
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>
175205
);
176206
};
177207

react-app/src/i18n/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"ProposalDetail.votes.remindToVote": "Remind to vote",
101101
"ProposalDetail.votes.requestState.error": "Failed to fetch proposal votes, please try again later.",
102102
"ProposalDetail.votes.voter": "Voter",
103+
"ProposalDetail.votes.voter.noSecurityContact": "Contact information for this validator is not available",
103104
"ProposalDetail.votes.voter.validator": "Validator",
104105
"ProposalDetail.votingDateRange": "{from} to {to}",
105106
"ProposalDetail.votingDurationRemaining": "{duration} left",

react-app/src/i18n/translations/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"ProposalDetail.votes.remindToVote": "Remind to vote",
101101
"ProposalDetail.votes.requestState.error": "Failed to fetch proposal votes, please try again later.",
102102
"ProposalDetail.votes.voter": "Voter",
103+
"ProposalDetail.votes.voter.noSecurityContact": "Contact information for this validator is not available",
103104
"ProposalDetail.votes.voter.validator": "Validator",
104105
"ProposalDetail.votingDateRange": "{from} 至 {to}",
105106
"ProposalDetail.votingDurationRemaining": "剩餘{duration}",

0 commit comments

Comments
 (0)