10000 Update CreateCause.tsx by maryjaf · Pull Request #5154 · Giveth/giveth-dapps-v2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update CreateCause.tsx #5154

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

Merged
merged 3 commits into from
Jul 7, 2025
Merged

Update CreateCause.tsx #5154

merged 3 commits into from
Jul 7, 2025

Conversation

maryjaf
Copy link
Collaborator
@maryjaf maryjaf commented Jul 7, 2025

add
localStorage.setItem(
'causeProjectsCount',
String(cause.data.createCause.activeProjectsCount ?? 0),
);

Summary by CodeRabbit

  • New Features
    • After creating a cause, the number of active projects linked to the new cause is now saved locally for future reference.
    • The success page now displays project information reflecting the newly created cause, enhancing user feedback.

add
localStorage.setItem(
				'causeProjectsCount',
				String(cause.data.createCause.activeProjectsCount ?? 0),
			);
Copy link
vercel bot commented Jul 7, 2025

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 Jul 7, 2025 4:24pm

@maryjaf maryjaf removed the request for review from kkatusic July 7, 2025 15:16
Copy link
Contributor
coderabbitai bot commented Jul 7, 2025

Walkthrough

A new side effect is added to the cause creation flow: after a cause is successfully created via GraphQL mutation, the number of active projects linked to the new cause is saved to localStorage under the key 'causeProjectsCount'. The success page component reads this count from localStorage on mount and passes it as a prop to the ProjectCard component. The rest of the flow, including clearing form storage and redirecting, is unchanged.

Changes

File(s) Change Summary
src/components/views/causes/create/CreateCause.tsx After successful cause creation, stores activeProjectsCount from the response in localStorage under 'causeProjectsCount'.
src/components/views/causes/create/SuccessfulCauseCreation.tsx Reads 'causeProjectsCount' from localStorage on mount, sets it in state, and passes it as a prop to ProjectCardAlt. Added CardWrapper styling around ProjectCardAlt.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CreateCauseComponent
    p
8000
articipant GraphQLServer
    participant localStorage
    participant SuccessPageComponent
    participant ProjectCardAlt

    User->>CreateCauseComponent: Submit new cause form
    CreateCauseComponent->>GraphQLServer: createCause mutation
    GraphQLServer-->>CreateCauseComponent: Mutation response (includes activeProjectsCount)
    CreateCauseComponent->>localStorage: Save activeProjectsCount as 'causeProjectsCount'
    CreateCauseComponent->>CreateCauseComponent: Clear form storage
    CreateCauseComponent->>User: Redirect to success page

    User->>SuccessPageComponent: Load success page
    SuccessPageComponent->>localStorage: Read 'causeProjectsCount'
    SuccessPageComponent->>SuccessPageComponent: Set projectsCount state
    SuccessPageComponent->>ProjectCardAlt: Render with isNew=true, projectsCount=state value
Loading

Possibly related PRs

  • Fixing Cause card on list #5150: The main PR adds storing and passing the active projects count for a newly created cause to the success page and its ProjectCardAlt component, while the retrieved PR modifies the ProjectCard and related components to accept and display projectsCount and isCause props for cause project cards, indicating a direct relation in how projectsCount is handled and displayed in cause-related project cards.

Suggested reviewers

  • divine-comedian
  • ae2079

Poem

🐇 A cause is born, the count is stored,
In localStorage, numbers soared.
Projects linked, the data’s sound,
Success achieved, the count is found.
With every hop and every byte,
This bunny codes through day and night! ✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a82836b and 59468fe.

📒 Files selected for processing (1)
  • src/components/views/causes/create/SuccessfulCauseCreation.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/views/causes/create/SuccessfulCauseCreation.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 0

🧹 Nitpick comments (1)
src/components/views/causes/create/CreateCause.tsx (1)

185-188: Use consistent StorageLabel pattern for localStorage operations.

The code correctly stores the active projects count, but uses a hardcoded string 'causeProjectsCount' instead of following the established StorageLabel pattern used elsewhere in the file (e.g., line 36: StorageLabel.CREATE_CAUSE_FORM).

Consider adding the key to the StorageLabel enum and using it consistently:

-			localStorage.setItem(
-				'causeProjectsCount',
-				String(cause.data.createCause.activeProjectsCount ?? 0),
-			);
+			localStorage.setItem(
+				StorageLabel.CAUSE_PROJECTS_COUNT,
+				String(cause.data.createCause.activeProjectsCount ?? 0),
+			);

This would require adding CAUSE_PROJECTS_COUNT to the StorageLabel enum definition.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 998fe04 and 6832353.

📒 Files selected for processing (1)
  • src/components/views/causes/create/CreateCause.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

Update SuccessfulCauseCreation.tsx
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6832353 and a82836b.

📒 Files selected for processing (1)
  • src/components/views/causes/create/SuccessfulCauseCreation.tsx (2 hunks)
🧰 Additional context used
🪛 ESLint
src/components/views/causes/create/SuccessfulCauseCreation.tsx

[error] 36-36: Delete

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
src/components/views/causes/create/SuccessfulCauseCreation.tsx (2)

39-45: LGTM! Consider localStorage cleanup strategy.

The localStorage reading logic is implemented correctly with proper error handling. The value is safely parsed as an integer and the existence check prevents errors.

The commented removal line suggests you may want to keep the value in localStorage for other components. Consider documenting this decision or implementing a cleanup strategy if the value should be removed after use.


81-87: LGTM! Props correctly passed to ProjectCard.

The JSX changes properly implement the feature requirements:

  • CardWrapper provides appropriate styling for the card layout
  • isNew={true} correctly identifies this as a newly created cause
  • projectsCount={projectsCount} passes the value read from localStorage

The implementation aligns well with the PR objectives to display the project count for the newly created cause.

Comment on lines 36 to 37
const router = useRouter();
const [projectsCount, setProjectsCount] = useState(0);
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 missing imports and remove unused variable.

This code has several issues:

  1. Missing imports for useRouter and useState
  2. useRouter is declared but never used
  3. Formatting issue flagged by ESLint

Apply this diff to fix the imports and remove the unused variable:

-import React, { useEffect } from 'react';
+import React, { useEffect, useState } from 'react';

And remove the unused useRouter declaration:

-	const router = useRouter();
-	const [projectsCount, setProjectsCount] = useState(0);
+	const [projectsCount, setProjectsCount] = useState(0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const router = useRouter();
const [projectsCount, setProjectsCount] = useState(0);
// Before:
import React, { useEffect } from 'react';
// ...
// replace with:
import React, { useEffect, useState } from 'react';
// ...
function SuccessfulCauseCreation() {
// removed unused router
const [projectsCount, setProjectsCount] = useState(0);
// ...
}
🧰 Tools
🪛 ESLint

[error] 36-36: Delete

(prettier/prettier)

🤖 Prompt for AI Agents
In src/components/views/causes/create/SuccessfulCauseCreation.tsx around lines
36 to 37, the code is missing imports for useRouter and useState, and the
useRouter variable is declared but never used. Fix this by adding the necessary
imports for useState from React and removing the import and declaration of
useRouter since it is unused. Also, ensure the code formatting complies with
ESLint rules by adjusting spacing and indentation as needed.

@maryjaf maryjaf merged commit be96378 into develop Jul 7, 2025
4 checks passed
@maryjaf maryjaf deleted the maryjaf-patch-2 branch July 7, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA
Development

Successfully merging this pull request may close these issues.

2 participants
0