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 1 commit
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
108 changes: 91 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,58 @@ 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
style={{
maryjaf marked this conversation as resolved.
Show resolved Hide resolved
visibility: isTooltipVisible
? 'visible'
: 'hidden',
position: 'absolute',
zIndex: 1000,
top: '50px', // Adjust as needed to position the tooltip near the button
left: '+10',
opacity: isTooltipVisible ? 1 : 0,
transition: 'opacity 0.2s ease',
}}
>
{formatMessage({
id: 'label.email_tooltip',
})}
</TooltipWrapper>
)}
kkatusic marked this conversation as resolved.
Show resolved Hide resolved

{/* 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 +366,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 +431,35 @@ const LinkItem = styled(P)<{ color: string }>`
font-weight: 500;
text-transform: capitalize;
`;
const ContinueCreationButton = styled(Button)`
align-self: flex-end;
position: relative;
cursor: pointer;
`;

const TooltipWrapper = styled.div`
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;
opacity: 0;
visibility: hidden;
transition:
opacity 0.2s ease-in-out,
visibility 0.2s ease-in-out;
z-index: 1000;

/* Tooltip on hover */
${ContinueCreationButton}:hover & {
opacity: 1;
visibility: visible;
}
`;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix styled components implementation

There are several issues in the styled components implementation:

  1. Invalid CSS in TooltipWrapper (buttonRect is undefined)
  2. Redundant cursor style in ContinueCreationButton
  3. Complex hover selector that might not work as intended
 const ContinueCreationButton = styled(Button)`
   align-self: flex-end;
   position: relative;
-  cursor: pointer;
 `;

 const TooltipWrapper = styled.div<{ $isVisible: boolean }>`
   position: absolute;
   bottom: -35px;
-  left: buttonRect.left + window.scrollX + 10;
+  left: 50%;
   transform: translateX(-50%);
   background: #1a1a1a;
   color: #fff;
   padding: 8px 12px;
   border-radius: 4px;
   font-size: 12px;
   white-space: nowrap;
-  opacity: 0;
-  visibility: hidden;
+  opacity: ${props => (props.$isVisible ? 1 : 0)};
+  visibility: ${props => (props.$isVisible ? 'visible' : 'hidden')};
   transition:
     opacity 0.2s ease-in-out,
     visibility 0.2s ease-in-out;
   z-index: 1000;

-  /* Tooltip on hover */
-  ${ContinueCreationButton}:hover & {
-    opacity: 1;
-    visibility: visible;
-  }
 `;

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


export default ProjectIndex;
Loading