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

fix: suid screen getting stuck #4229

Merged
merged 1 commit into from
Nov 6, 2024
Merged

fix: suid screen getting stuck #4229

merged 1 commit into from
Nov 6, 2024

Conversation

Dhruwang
Copy link
Member

@Dhruwang Dhruwang commented Nov 4, 2024

What does this PR do?

Fixes #4224

How should this be tested?

Test suid link page for survey which is already taken

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

    • Improved translation handling in the SurveyLinkUsed component for enhanced client-side rendering.
  • Bug Fixes

    • Resolved issues related to translation fetching by transitioning to a hook-based approach.
  • Refactor

    • Updated the component to be marked as a client component, ensuring proper functionality in the client environment.

Copy link

vercel bot commented Nov 4, 2024

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

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Nov 4, 2024 9:48am
formbricks-docs ⬜️ Ignored (Inspect) Nov 4, 2024 9:48am

Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The pull request modifies the SurveyLinkUsed component by transitioning from the getTranslations method to the useTranslations hook for managing translations. This change shifts the translation fetching from a server-side asynchronous operation to a client-side hook approach. The component is now designated as a client component with "use client", while its rendering logic and functionality remain unchanged. Additionally, the async keyword has been removed from the component's export signature.

Changes

File Change Summary
apps/web/app/s/[surveyId]/components/SurveyLinkUsed.tsx Updated translation handling from getTranslations to useTranslations, marked as a client component, and removed async from the export signature.

Assessment against linked issues

Objective Addressed Explanation
Page should show configured error message (4224) The changes do not address the infinite loading issue when a survey is reused.

Possibly related PRs

Suggested reviewers

  • gupta-piyush19

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

github-actions bot commented Nov 4, 2024

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

@github-actions github-actions bot added the bug Something isn't working label Nov 4, 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: 1

🧹 Outside diff range and nitpick comments (1)
apps/web/app/s/[surveyId]/components/SurveyLinkUsed.tsx (1)

Line range hint 1-38: Good architectural solution for handling survey link states.

The transition to client-side rendering with proper error state handling is a solid architectural choice for this use case. It ensures that users get immediate feedback when attempting to access an already submitted survey, rather than facing an infinite loading state.

A few key improvements in this implementation:

  1. Reactive error handling through client-side rendering
  2. Clear user feedback with visual indicators
  3. Flexible message customization with fallbacks

This should effectively resolve the issue reported in #4224.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 18be650 and 406517d.

📒 Files selected for processing (1)
  • apps/web/app/s/[surveyId]/components/SurveyLinkUsed.tsx (2 hunks)
🔇 Additional comments (2)
apps/web/app/s/[surveyId]/components/SurveyLinkUsed.tsx (2)

Line range hint 17-38: LGTM! Verify translation strings.

The error state UI implementation looks good with proper fallback messages and clear visual feedback. This should effectively communicate to users when they try to access an already submitted survey.

Let's verify the translation keys exist:

✅ Verification successful

Translation keys are properly defined and consistent across languages

The translation keys survey_already_answered_heading and survey_already_answered_subheading are correctly defined in all language files (en-US, de-DE, pt-BR) with appropriate translations. The implementation will work as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the translation keys in the messages files
rg "survey_already_answered_(heading|subheading)" --type json

Length of output: 1447


1-4: LGTM! Verify client-side rendering impact.

The transition to client-side rendering with "use client" and useTranslations is appropriate for fixing the infinite loading issue, as it ensures the component can handle the error state reactively.

Let's verify no other components depend on this being server-rendered:

✅ Verification successful

Client-side rendering transition is safe

The component is only used conditionally within LinkSurvey.tsx to display a message when a single-use survey has already been submitted. Converting it to a client component is appropriate and safe as:

  • It's used as a leaf component for displaying a static message
  • The parent component already handles the state check (hasFinishedSingleUseResponse)
  • No server-side dependencies are affected by this change
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for imports of SurveyLinkUsed to verify usage
rg -l "SurveyLinkUsed" --type tsx

Length of output: 61


Script:

#!/bin/bash
# Search for imports of SurveyLinkUsed using ripgrep without file type filter
rg -l "SurveyLinkUsed"

Length of output: 130


Script:

#!/bin/bash
# Check how SurveyLinkUsed is used in LinkSurvey.tsx
rg "SurveyLinkUsed" apps/web/app/s/[surveyId]/components/LinkSurvey.tsx -B 2 -A 2

Length of output: 541

Comment on lines 14 to 16
export const SurveyLinkUsed = async ({ singleUseMessage }: SurveyLinkUsedProps) => {
const t = await getTranslations();
const t = useTranslations();
const defaultHeading = t("s.survey_already_answered_heading");
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

Remove async keyword from component signature.

The component is using the useTranslations hook which is synchronous, but the component is incorrectly marked as async. React hooks cannot be used in async components, and this could lead to unexpected behavior.

Apply this fix:

- export const SurveyLinkUsed = async ({ singleUseMessage }: SurveyLinkUsedProps) => {
+ export const SurveyLinkUsed = ({ singleUseMessage }: SurveyLinkUsedProps) => {
📝 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
export const SurveyLinkUsed = async ({ singleUseMessage }: SurveyLinkUsedProps) => {
const t = await getTranslations();
const t = useTranslations();
const defaultHeading = t("s.survey_already_answered_heading");
export const SurveyLinkUsed = ({ singleUseMessage }: SurveyLinkUsedProps) => {
const t = useTranslations();
const defaultHeading = t("s.survey_already_answered_heading");

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@Dhruwang Thank you for fixing this 😊

@mattinannt mattinannt added this pull request to the merge queue Nov 6, 2024
Merged via the queue into main with commit fc3c044 Nov 6, 2024
17 checks passed
@mattinannt mattinannt deleted the fix-suid-screen branch November 6, 2024 04:51
@coderabbitai coderabbitai bot mentioned this pull request Nov 27, 2024
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 27, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Forms with suId are loading infinitely when already used
2 participants