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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: template breaking issue #1954

Merged
merged 1 commit into from
Jan 24, 2024
Merged

fix: template breaking issue #1954

merged 1 commit into from
Jan 24, 2024

Conversation

Dhruwang
Copy link
Contributor

Apparently Next.js is not comfortable having a button tag wrapping your div, sections, etc., so it will yell "Hydration failed because the initial UI does not match what was rendered on the server".

What does this PR do?

Fixes 1694

How should this be tested?

This error occurs when user has completed onboarding and have selected an objective (not "other")
Then when on survey stater, shift reload the page

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

Copy link

vercel bot commented Jan 24, 2024

The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌

2 Ignored Deployments
Name Status Preview Updated (UTC)
formbricks-cloud 猬滐笍 Ignored (Inspect) Jan 24, 2024 6:48am
formbricks-com 猬滐笍 Ignored (Inspect) Jan 24, 2024 6:48am

Copy link
Contributor

Thank you for following the naming conventions for pull request titles! 馃檹

Copy link
Contributor

apps/web/app/(app)/environments/[environmentId]/surveys/templates/TemplateList.tsx

Currently, the logic for determining the category color is embedded directly within the JSX. This makes the code harder to read and maintain. By extracting this logic into a separate function, we can improve the readability and maintainability of the code.
Create Issue
See the diff
Checkout the fix

    const getCategoryColor = (category) => {
      switch (category) {
        case "Product Experience":
          return "border-blue-300 bg-blue-50 text-blue-500";
        case "Exploration":
          return "border-pink-300 bg-pink-50 text-pink-500";
        case "Growth":
          return "border-orange-300 bg-orange-50 text-orange-500";
        case "Increase Revenue":
          return "border-emerald-300 bg-emerald-50 text-emerald-500";
        case "Customer Success":
          return "border-violet-300 bg-violet-50 text-violet-500";
        default:
          return "border-slate-300 bg-slate-50 text-slate-500";
      }
    };

    // Then in the JSX
    <div className={`rounded border px-1.5 py-0.5 text-xs ${getCategoryColor(template.category)}`}>
      {template.category}
    </div>
git fetch origin && git checkout -b ReviewBot/Impro-xws1ccr origin/ReviewBot/Impro-xws1ccr

Currently, the filteredTemplates are recalculated every time the component re-renders. This can be inefficient, especially if the templates array is large. By using the useMemo hook, we can memoize the filteredTemplates and only recalculate them when the dependencies change.
Create Issue
See the diff
Checkout the fix

    const filteredTemplates = useMemo(() => {
      return templates.filter((template) => {
        // existing filter logic
      });
    }, [templates, selectedFilter, templateSearch, user.objective]);
git fetch origin && git checkout -b ReviewBot/Impro-ibc7iud origin/ReviewBot/Impro-ibc7iud

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 thanks a lot for the fix for this issue 馃槉馃殌

@mattinannt mattinannt added this pull request to the merge queue Jan 24, 2024
Merged via the queue into main with commit f386de1 Jan 24, 2024
14 checks passed
@mattinannt mattinannt deleted the template-layout-issue branch January 24, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants