Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions components/testimony/TestimonyDetailPage/PolicyActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export const PolicyActions: FC<React.PropsWithChildren<PolicyActionsProps>> = ({
setFollowStatus(prev => ({ ...prev, [topicName]: false }))
}

const { t } = useTranslation("testimony")

const isFollowing = followStatus[topicName]
const isUnverified = !!user && !isUser && !user.emailVerified
const text = isFollowing ? "Unfollow" : "Follow"
const checkmark = isFollowing ? (
<StyledImage src="/check-white.svg" alt="" />
Expand Down Expand Up @@ -159,13 +162,19 @@ export const PolicyActions: FC<React.PropsWithChildren<PolicyActionsProps>> = ({
items.push(
<PolicyActionItem
key="add-testimony"
billName={`${isUser ? "Edit" : "Add"} Testimony for ${policyLabel}`}
href={formUrl(bill.id, bill.court, "position", ballotQuestionId)}
billName={
isUnverified
? t("panel.unverifiedEmail.title")
: `${isUser ? "Edit" : "Add"} Testimony for ${policyLabel}`
}
href={
isUnverified
? `/profile?id=${uid}`
: formUrl(bill.id, bill.court, "position", ballotQuestionId)
}
/>
)

const { t } = useTranslation("testimony")

return (
<Card
className={className}
Expand Down
10 changes: 8 additions & 2 deletions pages/submit-testimony.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react"
import { useRouter } from "next/router"
import { requireAuth } from "../components/auth"
import { requireAuth, useAuth } from "../components/auth"
import { isActiveBallotQuestionPhase } from "../components/ballotquestions/status"
import { dbService } from "../components/db"
import { createPage } from "../components/page"
Expand All @@ -18,11 +18,17 @@ export default createPage({

function SubmitTestimonyPage() {
const router = useRouter()
const { user } = useAuth()
const [isAllowed, setIsAllowed] = useState(false)

useEffect(() => {
if (!router.isReady) return

if (user && !user.emailVerified) {
void router.replace(`/profile?id=${user.uid}`)
return
}

const ballotQuestionId =
typeof router.query.ballotQuestionId === "string"
? router.query.ballotQuestionId
Expand Down Expand Up @@ -62,7 +68,7 @@ function SubmitTestimonyPage() {
return () => {
active = false
}
}, [router])
}, [router, user])

if (!isAllowed) return null

Expand Down
Loading