Skip to content

fix: toast Message while creating the survey#3240

Merged
Dhruwang merged 6 commits intoformbricks:mainfrom
smritidoneria:fix-issue
Oct 2, 2024
Merged

fix: toast Message while creating the survey#3240
Dhruwang merged 6 commits intoformbricks:mainfrom
smritidoneria:fix-issue

Conversation

@smritidoneria
Copy link
Contributor

@smritidoneria smritidoneria commented Oct 1, 2024

What does this PR do?

This pr fixes the duplication of the toast message after creating the survey.

Fixes #3204

Screen.Recording.2024-10-02.at.10.57.12.AM.mov

How should this be tested?

  • Test A.
  1. Create a new Survey
    2.Publish it.
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced the success message display to prevent multiple notifications for successful survey submissions.
    • Added a new toast notification identifier for better management of success notifications.
  • Bug Fixes

    • Improved logic to ensure toast notifications and confetti are triggered only once per submission.

@vercel
Copy link

vercel bot commented Oct 1, 2024

@smritidoneria is attempting to deploy a commit to the formbricks Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes involve updating the SuccessMessage component to prevent duplicate success messages from appearing when a survey is published. A new reference, messageShownRef, is introduced to track whether the success message has already been displayed. The component's logic is adjusted to ensure that the success toast notification and confetti are triggered only once per successful submission. Additionally, the URL parameters are managed to remove the success parameter and add a share parameter based on the survey type.

Changes

File Change Summary
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx Added messageShownRef to track message display, updated logic to prevent duplicate toasts, and managed URL parameters.
apps/demo/next-env.d.ts Removed a comment line regarding file editing and documentation link.

Assessment against linked issues

Objective Addressed Explanation
Only show success toast once on survey publish (#3204)

Possibly related PRs

Suggested labels

🙋🏻‍♂️help wanted, good first issue

Suggested reviewers

  • jobenjada

Poem

In the meadow, a rabbit did hop,
With a message of joy, it couldn't stop.
"No more duplicates, just one toast,
For every survey we love the most!"
With confetti and cheer, they danced in delight,
A single success, oh what a sight! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 302cb1b and b928964.

📒 Files selected for processing (2)
  • apps/demo/next-env.d.ts (0 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/demo/next-env.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx

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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2024

Thank you for following the naming conventions for pull request titles! 🙏

@github-actions github-actions bot added bug Something isn't working hacktoberfest complete these issues to gather points for Hacktoberfest 🕹️ 150 points 🕹️ oss.gg Community issue via oss.gg labels Oct 1, 2024
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

🧹 Outside diff range and nitpick comments (1)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx (1)

Line range hint 26-38: Effective solution: Preventing duplicate messages in useEffect.

The changes in the useEffect hook successfully address the issue of duplicate toast messages:

  1. The added check !messageShownRef.current ensures the message is only shown once.
  2. Setting messageShownRef.current = true after showing the message prevents future displays.

These modifications align perfectly with the PR objective and the issue described in #3204.

For improved clarity, consider adding a comment explaining the purpose of messageShownRef:

 const messageShownRef = useRef(false);
+// Ref to track if the success message has been shown, preventing duplicates
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b7f4097 and 302cb1b.

📒 Files selected for processing (1)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx (3 hunks)
🔇 Additional comments (3)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage.tsx (3)

4-4: LGTM: Import statement updated correctly.

The addition of useRef to the import statement is consistent with its usage in the component and aligns with the PR objective of fixing duplicate toast messages.


18-18: Good addition: messageShownRef prevents duplicate messages.

The introduction of messageShownRef using useRef is an effective solution to track whether the success message has been shown. This directly addresses the issue of duplicate toast messages mentioned in the PR objectives (#3204). The initial value of false is appropriate, ensuring the message is shown at least once.


Line range hint 1-53: Summary: Effective solution for preventing duplicate toast messages.

The changes implemented in this file successfully address the issue of duplicate toast messages when creating and publishing a survey, as described in the PR objectives and issue #3204. The introduction of messageShownRef and its usage in the useEffect hook provide a clean and efficient solution to the problem.

To finalize this PR:

  1. Add the suggested comment for messageShownRef to improve code clarity.
  2. Ensure thorough testing of the survey creation and publishing process to verify that the toast message appears only once.
  3. Consider adding a unit test for the SuccessMessage component to prevent regression of this issue in the future.

To verify the changes, please run the following test script:

This script will help ensure that the changes are implemented correctly and consistently throughout the component.

@jobenjada
Copy link
Member

hey @smritidoneria your solution doesn't solve the problem but the symptom. Please find out why the Toast is issued twice (probably related to the component being rendered twice).

Consult with GPT to find out why and learn more on how React works 🤓

@jobenjada jobenjada marked this pull request as draft October 1, 2024 22:55
@smritidoneria
Copy link
Contributor Author

Hey @jobenjada ,this issue is likely to occur due to the due to use effect hook being triggered various times due to its dependency array change, causing it to re-run. Specifically searchPrams is causing this effect to re-run.

So the solution of this problem is to use useRef hook. The useRef hook allows you to persist a mutable value across renders without causing a re-render when the value changes. This will be useful for keeping track of whether the toast message has already been shown.( this pr uses this solution only)

@gupta-piyush19
Copy link
Contributor

@smritidoneria, you can try adding a unique ID to this toast. This should fix the issue without using ref https://arc.net/l/quote/pyoztdxy

@smritidoneria
Copy link
Contributor Author

Hey @gupta-piyush19 , Updated the code by adding a toastId. kindly have a look

@gupta-piyush19 gupta-piyush19 marked this pull request as ready for review October 2, 2024 09:29
@gupta-piyush19 gupta-piyush19 self-requested a review October 2, 2024 09:30
Copy link
Contributor

@gupta-piyush19 gupta-piyush19 left a comment

Choose a reason for hiding this comment

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

Thanks @smritidoneria, fix works great 🙌
LGTM 🚀

@gupta-piyush19 gupta-piyush19 added this pull request to the merge queue Oct 2, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 2, 2024
@smritidoneria
Copy link
Contributor Author

hey @gupta-piyush19 , can you please tell why this pr has been removed from merged Queue, are there any changes required?

@Dhruwang Dhruwang added this pull request to the merge queue Oct 2, 2024
Merged via the queue into formbricks:main with commit a8e1fce Oct 2, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 3, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hacktoberfest complete these issues to gather points for Hacktoberfest 🕹️ oss.gg Community issue via oss.gg 🕹️ 150 points

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🕹️] Duplicate Toasts on Publish Survey

4 participants