Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable continue creation button and add tooltip for unverified users in draft project page #4896

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 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
100 changes: 83 additions & 17 deletions src/components/views/project/ProjectIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ const ProjectIndex: FC<IProjectBySlug> = () => {
const hasStellarAddress = recipientAddresses?.some(
address => address.chainType === ChainType.STELLAR,
);
const [isTooltipVisible, setTooltipVisible] = useState(false);

const handleMouseEnter = () => {
setTooltipVisible(true);
};

const handleMouseLeave = () => {
setTooltipVisible(false);
};

const isEmailVerifiedStatus = isAdmin ? isAdminEmailVerified : true;

Expand Down Expand Up @@ -258,19 +267,48 @@ const ProjectIndex: FC<IProjectBySlug> = () => {
{activeTab === 2 && <ProjectDonations />}
{activeTab === 3 && <ProjectGIVPowerIndex />}
{isDraft && (
<Flex $justifyContent='flex-end'>
<ContinueCreationButton
label={formatMessage({
id: 'label.continue_creation',
})}
buttonType='primary'
type='submit'
onClick={() =>
router.push(
idToProjectEdit(projectData?.id || ''),
)
}
/>
<Flex
$justifyContent='flex-end'
style={{ position: 'relative' }}
>
{/* Show tooltip only when the button is disabled (email not verified) */}
{!isEmailVerifiedStatus && (
<TooltipWrapper
isTooltipVisible={isTooltipVisible}
>
{formatMessage({
id: 'label.email_tooltip',
})}
</TooltipWrapper>
)}

{/* Wrapper for hover events */}
<div
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
style={{
display: 'inline-block', // Ensures it wraps the button
kkatusic marked this conversation as resolved.
Show resolved Hide resolved
cursor: !isEmailVerifiedStatus
? 'not-allowed'
: 'pointer', // Pointer only when enabled
}}
>
<ContinueCreationButton
label={formatMessage({
id: 'label.continue_creation',
})}
disabled={!isEmailVerifiedStatus} // Button disabled when email is not verified
buttonType='primary'
type='submit'
onClick={() =>
router.push(
idToProjectEdit(
projectData?.id || '',
),
)
}
/>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance button wrapper accessibility

The button wrapper should include proper ARIA attributes to indicate the disabled state and relationship with the tooltip.

 <div
   onMouseEnter={handleMouseEnter}
   onMouseLeave={handleMouseLeave}
+  role="presentation"
   style={{
     display: 'inline-block',
     cursor: !isEmailVerifiedStatus
       ? 'not-allowed'
       : 'pointer',
   }}
 >
   <ContinueCreationButton
     label={formatMessage({
       id: 'label.continue_creation',
     })}
     disabled={!isEmailVerifiedStatus}
     buttonType='primary'
     type='submit'
+    aria-describedby="email-verification-tooltip"
     onClick={() =>
       router.push(
         idToProjectEdit(
           projectData?.id || '',
         ),
       )
     }
   />
 </div>

Committable suggestion skipped: line range outside the PR's diff.

</Flex>
)}
<ProjectDevouchBox />
Expand Down Expand Up @@ -318,10 +356,6 @@ const Separator = styled.hr`
margin: 40px 0;
`;

const ContinueCreationButton = styled(Button)`
align-self: flex-end;
`;

const MobileContainer = styled.div<{ $hasActiveRound: boolean }>`
padding: ${props =>
props.$hasActiveRound ? '0 26px 26px 26px' : '0 26px'};
Expand Down Expand Up @@ -387,5 +421,37 @@ const LinkItem = styled(P)<{ color: string }>`
font-weight: 500;
text-transform: capitalize;
`;
const ContinueCreationButton = styled(Button)`
align-self: flex-end;
position: relative;
cursor: pointer;
`;
interface TooltipWrapperProps {
isTooltipVisible: boolean;
top?: string;
left?: string;
}
const TooltipWrapper = styled.div<TooltipWrapperProps>`
visibility: ${isTooltipVisible =>
isTooltipVisible ? 'visible' : 'hidden'};
opacity: ${({ isTooltipVisible }) => (isTooltipVisible ? 1 : 0)};
position: absolute;
bottom: -35px;
left: buttonRect.left + window.scrollX + 10;
transform: translateX(-50%);
background: #1a1a1a;
color: #fff;
padding: 8px 12px;
border-radius: 4px;
font-size: 12px;
white-space: nowrap;
transition: 'opacity 0.2s ease';
z-index: 1000;
/* Tooltip on hover */
${ContinueCreationButton}:hover & {
opacity: 1;
visibility: visible;
}
`;

export default ProjectIndex;
Loading