Skip to content

feat: Add Embed </> options to Survey cta bar and minor changes#3272

Merged
jobenjada merged 11 commits intoformbricks:mainfrom
nawinsharma:survey-cta-bar
Oct 14, 2024
Merged

feat: Add Embed </> options to Survey cta bar and minor changes#3272
jobenjada merged 11 commits intoformbricks:mainfrom
nawinsharma:survey-cta-bar

Conversation

@nawinsharma
Copy link
Contributor

@nawinsharma nawinsharma commented Oct 3, 2024

What does this PR do?

This PR resolves Reworks Survey Summary CTA bar:

Fixes: #3217

before:
image

after changes:

Screencast.from.2024-10-03.15-51-38.webm

How should this be tested?

  • Test A Go to survey summary section and preview it

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

  • New Features

    • Introduced a flexible modal system in the survey sharing interface, allowing users to access different views for sharing, embedding, or panel information based on the selected modal type.
    • Added a dropdown menu for additional actions, enhancing user interaction capabilities.
    • Enhanced modal state management for improved visibility control of sharing and embedding options.
    • Improved performance by memoizing the survey URL.
    • Updated the EmbedView component to conditionally render the back button based on user preferences.
  • Bug Fixes

    • Resolved issues with modal visibility handling, ensuring a smoother user experience.
  • Documentation

    • Updated component interfaces for clarity, improving overall code maintainability.

@vercel
Copy link

vercel bot commented Oct 3, 2024

@NawinKumarSharma 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 3, 2024

Walkthrough

The changes introduce new props, modalType and modalView, to the ShareEmbedSurvey component, enhancing its ability to render various modal views. The SurveyAnalysisCTA component has been refactored for improved state management and performance, consolidating modal visibility handling into a single object. Additionally, new dropdown actions have been added, allowing users to copy links and configure alerts. These modifications improve the overall structure and usability of the components.

Changes

File Change Summary
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx Introduced modalType and modalView props in ShareEmbedSurveyProps, updated component signature, and modified internal state initialization and handling.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA.tsx Defined SurveyAnalysisCTAProps, refactored internal state to a single modalState object, and enhanced rendering logic with new dropdown actions and modal management functions.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/AppTab.tsx Removed Alert component, replacing it with a styled <div> for displaying the SDK development message.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/EmbedView.tsx Added disableBack prop to EmbedViewProps, modified rendering logic to conditionally display the back button based on this prop.

Assessment against linked issues

Objective Addressed Explanation
Update CTA to include options for embedding, previewing, and editing surveys (#3217)
Add functionality for copying survey link and sending to panel (#3217)
Ensure consistency in modal behavior across components (#3217)

Possibly related PRs

Suggested labels

good first issue, 🕹️ 150 points

Suggested reviewers

  • Dhruwang

Poem

In the land of surveys, bright and fair,
A modal dances, with options to share.
With buttons and links, all snug and tight,
The rabbit hops in, with pure delight!
So embed and preview, let joy take flight,
In the world of surveys, everything's right! 🐇✨


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 github-actions bot added enhancement New feature or request hacktoberfest complete these issues to gather points for Hacktoberfest 🕹️ 300 points 🕹️ oss.gg Community issue via oss.gg labels Oct 3, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2024

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

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: 5

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

52-56: LGTM: Styling adjustments for back button presence

The conditional styling for the sidebar and content area based on the disableBack prop is well implemented. It ensures proper spacing when the back button is not present.

For consistency, consider using the same condition structure for both the sidebar and content area. You could update line 77 to match the structure used in the sidebar:

-          <div className={!disableBack ? "mt-10" : ""}>
+          <div className={cn(!disableBack && "mt-10")}>

This change would make the code more uniform and easier to read.

Also applies to: 77-77


Line range hint 1-114: Summary of review for EmbedView.tsx

Overall, the changes to the EmbedView component align well with the PR objectives to rework the Survey Summary CTA bar. The addition of the disableBack prop and the corresponding UI adjustments are good improvements. However, there are a few points to address:

  1. The most critical issue is the inverted logic in the back button rendering condition. This needs to be fixed to ensure correct functionality.
  2. For consistency, consider updating the conditional class application in the content area to match the structure used in the sidebar.

Once these points are addressed, the changes will significantly enhance the functionality and user experience of the Survey Summary CTA bar.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/PanelInfoView.tsx (1)

10-10: LGTM! Consider renaming for clarity.

The addition of the disableBack property to the PanelInfoViewProps interface is appropriate. It aligns with the component's new functionality to conditionally render a "Back" button.

Consider renaming disableBack to showBackButton for improved clarity. This would make the property's purpose more immediately obvious and align better with its usage in the component.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1c10679 and 16c95f4.

📒 Files selected for processing (4)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx (3 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/EmbedView.tsx (4 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/PanelInfoView.tsx (1 hunks)
🔇 Additional comments (13)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/EmbedView.tsx (2)

17-17: LGTM: Addition of disableBack property

The new disableBack boolean property in the EmbedViewProps interface is a good addition. It aligns with the PR objectives to rework the Survey Summary CTA bar and provides a clear way to control the visibility of the back button.


28-28: LGTM: disableBack prop added to component

The disableBack prop has been correctly added to the EmbedView component's destructured props. This implementation allows the new functionality to be passed into the component as intended.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/PanelInfoView.tsx (1)

14-14: LGTM! Component signature updated correctly.

The PanelInfoView component signature has been properly updated to include the new disableBack prop. This change correctly implements the interface modification and uses appropriate destructuring syntax.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx (5)

26-26: 'modalType' prop correctly added to 'ShareEmbedSurveyProps' interface

The addition of the modalType prop enhances the component's flexibility by allowing different modal views.


32-39: Updated function signature includes 'modalType' prop

The function now accepts the modalType prop, which is essential for rendering content based on modal type.


59-59: Properly updating 'showView' state in 'handleOpenChange' function

The setShowView correctly resets the view when the modal opens or closes.


122-122: Inconsistent 'disableBack' prop values for 'EmbedView' component

In the EmbedView component, the disableBack prop is set to true when modalType is "start" (line 122) and false when modalType is "embed" (line 145). This inconsistency might lead to unexpected behavior. Please verify if this difference is intentional. If not, consider using a consistent value for the disableBack prop.

Also applies to: 145-145


145-145: Ensure consistent 'disableBack' prop in 'EmbedView' across different modal types

When modalType is "embed", the disableBack prop in EmbedView is set to false (line 145). Confirm whether this is intentional, especially if the back functionality should be consistent regardless of how the modal is opened.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA.tsx (5)

24-30: Good practice: Using a dedicated props interface

Defining SurveyAnalysisCTAProps enhances type safety and improves code readability.


50-55: Consolidated modal state management

Using a single modalState object simplifies state management for modals and improves maintainability.


57-57: Efficient use of useMemo for surveyUrl

Memoizing surveyUrl with useMemo prevents unnecessary recalculations and enhances performance.


91-97: Well-structured modal state handler

The handleModalState higher-order function cleanly updates specific modal states, enhancing code reusability.


184-212: Effective conditional rendering of modals

Conditionally rendering ShareEmbedSurvey and SuccessMessage components based on modalState optimizes performance and user experience.

@Dhruwang Dhruwang self-requested a review October 3, 2024 12:14
@nawinsharma
Copy link
Contributor Author

@Dhruwang , please review it!

Copy link
Member

@jobenjada jobenjada left a comment

Choose a reason for hiding this comment

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

hey mate!

thanks for your submission.

There are a few issues:

The 'Back' buttons don't work here:

image image

The button size doesn't add up:
image

Pls fix these before merge

interface ShareEmbedSurveyProps {
survey: TSurvey;
open: boolean;
modalType: "start" | "embed" | "panel";
Copy link
Member

Choose a reason for hiding this comment

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

pls change variable name to modalView

)}

{user && <SuccessMessage environment={environment} survey={survey} />}
{user && (
Copy link
Member

Choose a reason for hiding this comment

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

embedding the same modal 3x just because a prop changes is not the right approach. pls refactor :)

Back
</Button>
</div>
{!disableBack && (
Copy link
Member

Choose a reason for hiding this comment

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

look like double negation got you here ;)

@jobenjada jobenjada marked this pull request as draft October 6, 2024 22:21
@nawinsharma nawinsharma requested a review from jobenjada October 7, 2024 10:16
@nawinsharma
Copy link
Contributor Author

@jobenjada can you review it ?

Screencast.from.2024-10-07.15-42-05.webm

@jobenjada jobenjada marked this pull request as ready for review October 7, 2024 22:33
@jobenjada
Copy link
Member

hey mate!

kiiiinda works ;)

2 things:

if you open the modal the second time, you end up here again:
image

pls make your solution more robust.


secondly, we need to tweak it a bit more (and I'll add 150 points for this as it wasn't part of the original ticket):

we need to pass the survey type to the modal. If the survey type is not link then we need to hide tab menu and set the last tab as default:

image

the other three tabs don't make any sense for web and app surveys.

Thanks mate 🙌

Copy link
Member

@jobenjada jobenjada left a comment

Choose a reason for hiding this comment

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

see prev comment

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

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

45-45: LGTM: Improved props typing and state management

The use of SurveyAnalysisCTAProps interface and the consolidated modalState object are excellent improvements. The useMemo hook for the survey URL is a good optimization.

Consider adding a comment explaining the structure of the modalState object for better maintainability:

// modalState controls the visibility of various modals and dropdowns
const [modalState, setModalState] = useState<ModalState>({
  // ... (rest of the code)
});

Also applies to: 50-57


111-189: LGTM: Enhanced functionality with new buttons and dropdown menu

The addition of "Embed" and "Preview" buttons, along with the dropdown menu for additional actions, significantly improves the component's functionality. These changes align well with the PR objectives.

Consider adding aria-labels to the buttons for improved accessibility:

<Button
  variant="secondary"
  size="sm"
  onClick={() => handleModalState("embed")(true)}
  EndIcon={Code2Icon}
  aria-label="Embed survey">
  Embed
</Button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3968e3f and a6ca817.

📒 Files selected for processing (2)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA.tsx (1 hunks)
  • packages/ui/components/Button/index.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
packages/ui/components/Button/index.tsx (1)

96-96: Improved code readability for secondary variant styling.

The modification to group the class names for the enabled state of the 'secondary' variant on a single line enhances code readability. This change doesn't affect the functionality of the component but makes the styling logic more cohesive and easier to understand at a glance.

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA.tsx (4)

6-7: LGTM: Improved imports and type definitions

The new imports and interface definitions enhance the component's functionality and type safety. The ModalState interface, in particular, is a good addition for managing multiple modal states in a structured manner.

Also applies to: 9-10, 16-22, 24-37


69-78: LGTM: Improved modal state management

The refactored handleShareModalToggle function and the new handleModalState function provide a more flexible and maintainable approach to managing multiple modal states. This change aligns well with the new ModalState structure.

Also applies to: 98-103


80-91: LGTM: Improved clipboard handling

The handleCopyLink function has been updated to use a promise-based approach with proper error handling. This change addresses the issue raised in a previous review comment and improves the robustness of the clipboard operation.


Line range hint 1-224: Overall LGTM: Significant improvements to SurveyAnalysisCTA component

The changes to the SurveyAnalysisCTA component represent a substantial improvement in functionality, state management, and code organization. The new features, including the embed option, preview functionality, and additional dropdown actions, align well with the PR objectives.

Key improvements:

  1. Enhanced type safety with new interfaces
  2. Improved state management with the consolidated modalState object
  3. New functionality with embed, preview, and dropdown actions
  4. Better error handling for clipboard operations

While the overall implementation is solid, consider the following minor improvements:

  1. Add comments for better code documentation
  2. Enhance accessibility with aria-labels on buttons
  3. Refactor the multiple ShareEmbedSurvey components for better efficiency

Great work on this significant update to the component!

@jobenjada
Copy link
Member

@NawinKumarSharma are you willing to wrap this up for the additional 150 points mentioned?

@coderabbitai coderabbitai bot mentioned this pull request Jan 31, 2025
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Apr 16, 2025
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jul 8, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request hacktoberfest complete these issues to gather points for Hacktoberfest 🕹️ oss.gg Community issue via oss.gg 🕹️ 300 points

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🕹️] Rework Survey Summary CTA bar

4 participants