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

Feat/Allow project boost if project is vouched #4858

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Nov 8, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced localization with new keys for GIVbacks eligibility prompts in Catalan, English, and Spanish.
    • Introduced a new ProjectCardNotification component to inform users about project eligibility for GIVbacks.
  • Bug Fixes

    • Improved clarity of existing user interface strings and error messages across multiple languages.
  • Refactor

    • Updated rendering logic in the AdminActions component to include a new notification feature while maintaining existing functionalities.

Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2024 11:14am

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The pull request introduces updates to localization files for Catalan, English, and Spanish languages, enhancing user engagement through new keys and improved translations related to the GIVbacks program. Additionally, it modifies the ProjectGIVbackToast component to handle new eligibility conditions and introduces a new ProjectCardNotification component that displays notifications based on project verification and eligibility status. The changes maintain the overall structure of the files while ensuring clarity and accessibility for users.

Changes

File Path Change Summary
lang/ca.json Added new key "project.givback_toast.complete_eligibility" with translation for GIVbacks.
lang/en.json Added new key "project.givback_toast.complete_eligibility" and refined existing strings.
lang/es.json Added new key "project.givback_toast.complete_eligibility" and updated existing translations.
src/components/views/project/ProjectGIVbackToast.tsx Added conditional logic for verified but ineligible owners, updated icon color, and modified variable declaration.
src/components/views/project/projectActionCard/AdminActions.tsx Introduced ProjectCardNotification component and refactored mobile actions rendering.
src/components/views/project/projectActionCard/ProjectCardNotification.tsx Added new functional component to display notifications based on project eligibility.

Possibly related PRs

Suggested reviewers

  • Meriem-BM
  • mohammadranjbarz
  • RamRamez

Poem

🐇 In the fields where GIVbacks grow,
New words in Catalan, English, and Spanish flow.
With notifications bright, and clarity in sight,
Our users will hop with delight!
So let’s cheer for the changes, both big and small,
For a better Giveth, we’re giving our all! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
src/components/views/project/projectActionCard/ProjectCardNotification.tsx (4)

18-19: Rename condition for clarity.

The variable name isOwnerVerifiedNotEligible suggests checking ownership, but it's actually checking admin status. Consider renaming to isAdminVerifiedNotEligible for better clarity.

-	const isOwnerVerifiedNotEligible =
+	const isAdminVerifiedNotEligible =
 		isVerified && isAdmin && !isGivbackEligible;

13-16: Add TypeScript types for project data.

Consider adding proper TypeScript types for the project data to ensure type safety and better maintainability.

+interface ProjectData {
+  verified: boolean;
+  isGivbackEligible: boolean;
+}

-	const { isAdmin, projectData } = useProjectContext();
+	const { isAdmin, projectData }: { isAdmin: boolean; projectData?: ProjectData } = useProjectContext();

29-31: Consider using type-safe message IDs.

The message ID is hardcoded as a string. Consider using a type-safe approach with a messages constant or enum to prevent typos and enable better refactoring support.

+const MESSAGES = {
+  COMPLETE_ELIGIBILITY: 'project.givback_toast.complete_eligibility'
+} as const;

 {formatMessage({
-  id: `project.givback_toast.complete_eligibility`,
+  id: MESSAGES.COMPLETE_ELIGIBILITY,
 })}

37-45: Consider adding responsive design support.

The styling is clean, but consider adding responsive design support for different screen sizes, especially since this component is used in both desktop and mobile views (as mentioned in the AI summary).

 const ProjectCardNotificationWrapper = styled(Flex)`
 	align-items: center;
 	padding-top: 12px;
 	font-size: 14px;
 	color: ${semanticColors.golden[600]};
+	
+	@media (max-width: 768px) {
+		padding-top: 8px;
+		font-size: 12px;
+	}
+	
 	span {
 		margin-left: 8px;
+		
+		@media (max-width: 768px) {
+			margin-left: 6px;
+		}
 	}
 `;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02a85a3 and a2e6725.

📒 Files selected for processing (6)
  • lang/ca.json (1 hunks)
  • lang/en.json (1 hunks)
  • lang/es.json (1 hunks)
  • src/components/views/project/ProjectGIVbackToast.tsx (2 hunks)
  • src/components/views/project/projectActionCard/AdminActions.tsx (2 hunks)
  • src/components/views/project/projectActionCard/ProjectCardNotification.tsx (1 hunks)
🔇 Additional comments (8)
src/components/views/project/projectActionCard/ProjectCardNotification.tsx (2)

1-9: LGTM! Well-organized imports.

The imports are properly structured, following the convention of external dependencies first, followed by internal imports.


11-35: Verify component integration in AdminActions.

The component implementation looks good, but let's verify its integration in the AdminActions component.

✅ Verification successful

Component is properly integrated in AdminActions

The verification shows that ProjectCardNotification is correctly:

  • Imported in AdminActions.tsx
  • Used in both mobile and desktop views of the component
  • Properly handles GIVback eligibility notifications as designed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ProjectCardNotification usage in AdminActions
# Expected: Find import and usage of ProjectCardNotification in AdminActions

# Search for the component usage
rg -l "ProjectCardNotification" "src/components/views/project/projectActionCard/AdminActions"

Length of output: 191


Script:

#!/bin/bash
# Let's first find the correct path for AdminActions
fd -t f "AdminActions" src/

# Then search for ProjectCardNotification usage across the codebase
rg -l "ProjectCardNotification"

# Get the content of files that use ProjectCardNotification to understand the integration
rg -A 5 "ProjectCardNotification"

Length of output: 4120

src/components/views/project/projectActionCard/AdminActions.tsx (2)

34-34: LGTM: Clean import statement.

The import follows React conventions and maintains good code organization by importing from the same directory.


167-167: Verify props requirements for ProjectCardNotification.

The component is rendered without any props. Please verify if this is intentional and that the component can function correctly without any required props.

✅ Verification successful

ProjectCardNotification is correctly used without props

The component is properly implemented to work without props as it uses context hooks (useProjectContext) to access required data. It internally:

  • Gets project data and admin status from useProjectContext
  • Uses useIntl for internationalization
  • Has conditional rendering logic based on verification and eligibility status
  • Returns null when conditions aren't met
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if ProjectCardNotification requires any props

# Test: Search for the component definition to verify prop requirements
ast-grep --pattern 'interface $_ {
  $$$
}'  src/components/views/project/projectActionCard/ProjectCardNotification.tsx

# Test: Search for prop usage within the component
ast-grep --pattern 'const ProjectCardNotification = ($props) => {
  $$$
}' src/components/views/project/projectActionCard/ProjectCardNotification.tsx

Length of output: 272


Script:

#!/bin/bash
# Let's try different approaches to verify the component implementation

# First, let's check if the file exists and see its content
fd ProjectCardNotification.tsx | xargs cat

# If that doesn't work, let's try finding any file containing ProjectCardNotification
rg -l "ProjectCardNotification"

# Let's also search for any usage of this component to understand the patterns
rg "ProjectCardNotification" -A 3

Length of output: 3958

src/components/views/project/ProjectGIVbackToast.tsx (1)

56-56: LGTM: Variable declaration change is appropriate.

The change from const to let is necessary as the color value is reassigned in the new conditional block.

lang/en.json (1)

1682-1682: LGTM! New translation key added for GIVbacks eligibility form.

The new key follows proper naming conventions and provides a clear message for users to complete their GIVbacks eligibility form.

lang/es.json (1)

1682-1682: LGTM! New translation key added correctly

The Spanish translation for the new GIVbacks eligibility form message is grammatically correct and maintains consistency with the existing translations.

lang/ca.json (1)

1681-1681: LGTM! New translation key added correctly.

The new translation key "project.givback_toast.complete_eligibility" with Catalan translation "Completa el teu formulari d'elegibilitat per als GIVbacks" follows proper naming conventions, is well formatted, and maintains consistency with other GIVbacks related messages.

Comment on lines +170 to +223
<>
<MobileWrapper
gap='4px'
onClick={() => setShowMobileActionsModal(true)}
>
<div>Project Actions</div>
<IconChevronDown24 />
{showMobileActionsModal && (
<MobileActionsModal
setShowModal={setShowMobileActionsModal}
>
{options.map(option => (
<MobileActionModalItem
key={option.label}
onClick={option.cb}
>
<Flex gap='8px'>
<Flex $alignItems='center'>
{option.icon}
</Flex>
<div>{option.label}</div>
</Flex>
</MobileActionModalItem>
))}
{showVerificationModal && (
<VerificationModal
onClose={() => setShowVerificationModal(false)}
/>
)}
{deactivateModal && (
<DeactivateProjectModal
setShowModal={setDeactivateModal}
projectId={projectData?.id}
onSuccess={fetchProjectBySlug}
/>
)}
{showShareModal && (
<ShareModal
contentType={EContentType.thisProject}
setShowModal={setShowShareModal}
projectHref={slug}
/>
)}
</MobileActionsModal>
)}
{showClaimModal && (
<ClaimRecurringDonationModal
setShowModal={setShowClaimModal}
project={project}
/>
)}
</MobileWrapper>
<ProjectCardNotification />
</>
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

Improve code structure and accessibility.

Several issues need to be addressed in the mobile view implementation:

  1. The click handler is attached to a div element which may cause accessibility issues.
  2. The modal components are duplicated between desktop and mobile views.

Consider these improvements:

- <MobileWrapper
-   gap='4px'
-   onClick={() => setShowMobileActionsModal(true)}
- >
-   <div>Project Actions</div>
+ <MobileWrapper
+   gap='4px'
+   as="button"
+   onClick={() => setShowMobileActionsModal(true)}
+   role="button"
+   aria-label="Open project actions"
+ >
+   <span>Project Actions</span>

Also, consider extracting the modal components to avoid duplication:

const ActionModals = () => (
  <>
    {showVerificationModal && (
      <VerificationModal onClose={() => setShowVerificationModal(false)} />
    )}
    {deactivateModal && (
      <DeactivateProjectModal
        setShowModal={setDeactivateModal}
        projectId={projectData?.id}
        onSuccess={fetchProjectBySlug}
      />
    )}
    {/* ... other modals ... */}
  </>
);

@@ -163,55 +164,63 @@
project={project}
/>
)}
<ProjectCardNotification />
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

Prevent duplicate notifications on desktop/tablet views.

The ProjectCardNotification component is rendered in both desktop and mobile views. This could lead to duplicate notifications being displayed when transitioning between viewport sizes.

Consider consolidating the notification rendering:

return !isMobile ? (
  <Wrapper>
    <Dropdown
      style={dropdownStyle}
      label='Project Actions'
      options={options}
    />
    {/* ... modals ... */}
-   <ProjectCardNotification />
  </Wrapper>
) : (
  <>
    <MobileWrapper>
      {/* ... mobile content ... */}
    </MobileWrapper>
    <ProjectCardNotification />
  </>
);

And move it outside the conditional render:

return (
  <>
    {!isMobile ? (
      <Wrapper>
        <Dropdown
          style={dropdownStyle}
          label='Project Actions'
          options={options}
        />
        {/* ... modals ... */}
      </Wrapper>
    ) : (
      <MobileWrapper>
        {/* ... mobile content ... */}
      </MobileWrapper>
    )}
    <ProjectCardNotification />
  </>
);

Also applies to: 222-222

Comment on lines +230 to +252
} else if (isOwnerVerifiedNotEligible) {
title = formatMessage(
{
id: `${useIntlTitle}verified_owner`,
},
{
percent: givbackFactorPercent,
value: GIVBACKS_DONATION_QUALIFICATION_VALUE_USD,
},
);
description = formatMessage({
id: `${useIntlDescription}verified_owner_not_eligible`,
});
color = semanticColors.golden[600];
icon = <IconGIVBack24 color={semanticColors.golden[600]} />;
link = links.GIVPOWER_DOC;
Button = (
<OutlineButton
onClick={handleBoostClick}
label='Boost'
icon={<IconRocketInSpace16 />}
/>
);
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 duplicate condition and improve code organization.

There are several issues with the new conditional block:

  1. This condition appears twice in the code (here and later in the file), making the second occurrence unreachable.
  2. The Button implementation is duplicated.
  3. The color is inconsistently assigned (both to a variable and directly to the icon).

Consider consolidating the conditions and removing duplicates:

- } else if (isOwnerVerifiedNotEligible) {
-   title = formatMessage(
-     {
-       id: `${useIntlTitle}verified_owner`,
-     },
-     {
-       percent: givbackFactorPercent,
-       value: GIVBACKS_DONATION_QUALIFICATION_VALUE_USD,
-     },
-   );
-   description = formatMessage({
-     id: `${useIntlDescription}verified_owner_not_eligible`,
-   });
-   color = semanticColors.golden[600];
-   icon = <IconGIVBack24 color={semanticColors.golden[600]} />;
-   link = links.GIVPOWER_DOC;
-   Button = (
-     <OutlineButton
-       onClick={handleBoostClick}
-       label='Boost'
-       icon={<IconRocketInSpace16 />}
-     />
-   );

Move this logic to where the other isOwnerVerifiedNotEligible condition is handled and ensure consistent color usage:

} else if (isOwnerVerifiedNotEligible) {
  color = semanticColors.golden[600];
  title = formatMessage({
    id: `${useIntlTitle}verified_owner_not_eligible`,
  });
  description = formatMessage(
    {
      id: `${useIntlDescription}verified_owner_not_eligible`,
    },
    {
      stakeLock: (
        <InnerLink href={Routes.GIVfarm} target='_blank'>
          {formatMessage({ id: 'label.stake_and_lock' })}{' '}
        </InnerLink>
      ),
    },
  );
  icon = <IconGIVBack24 color={color} />;
  link = links.GIVPOWER_DOC;
  Button = (
    <OutlineButton
      onClick={handleBoostClick}
      label='Boost'
      icon={<IconRocketInSpace16 />}
    />
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant