Skip to content

Comments

Store individual onboarding answers#492

Merged
elie222 merged 1 commit intomainfrom
feat/survey-answers
Jun 6, 2025
Merged

Store individual onboarding answers#492
elie222 merged 1 commit intomainfrom
feat/survey-answers

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Jun 6, 2025

Summary by CodeRabbit

  • New Features
    • User profiles now store additional survey information, including selected features, role, goals, source of discovery, and improvement suggestions.
  • Chores
    • Improved handling and storage of onboarding survey responses for easier access and analysis.

@vercel
Copy link

vercel bot commented Jun 6, 2025

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

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Jun 6, 2025 10:40am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

This update expands the user data schema and onboarding logic to extract and store specific survey responses as individual fields in the database. The changes include a database migration, Prisma schema updates, and logic in the onboarding answer-saving action to parse and persist these new survey fields.

Changes

File(s) Change Summary
apps/web/prisma/migrations/.../migration.sql Adds five new columns to the User table for storing survey responses (features, role, goal, etc).
apps/web/prisma/schema.prisma Updates the User model to include new fields for survey answers (string array and optional text).
apps/web/utils/actions/user.ts Adds logic to extract and store structured survey answers when saving onboarding responses.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebApp
    participant DB

    User->>WebApp: Submit onboarding survey answers
    WebApp->>WebApp: extractSurveyAnswers(questions, answers)
    WebApp->>DB: Update User record with onboardingAnswers + extracted survey fields
    DB-->>WebApp: Confirmation
    WebApp-->>User: Success response
Loading

Poem

In fields anew, the survey grows,
With features, roles, and goals it shows.
The answers parsed, now clear and bright,
Stored in columns, neat and right.
A rabbit hops through schema green,
Cheering code that's crisp and clean! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/utils/actions/user.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

✨ 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

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Schema vs Migration Mismatch Causes Errors

Schema mismatch for surveyFeatures: Defined as non-nullable String[] in the Prisma schema, but the migration creates a nullable TEXT[] database column. This causes runtime errors, especially when data extraction logic returns undefined which conflicts with the non-nullable schema definition during database updates. The schema field should be nullable (String[]?) or the extraction logic should always return [].

apps/web/prisma/schema.prisma#L62-L63

// survey answers (extracted from onboardingAnswers for easier querying)
surveyFeatures String[] // multiple choice: features user is interested in

Fix in Cursor


BugBot free trial expires on June 9, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

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 (2)
apps/web/utils/actions/user.ts (2)

121-190: Consider improving robustness of the extraction logic.

The extraction function handles the survey data parsing well, but there are some areas for improvement:

  1. Hardcoded answer key format: The logic assumes specific key patterns ($survey_response, $survey_response_${questionIndex}) which could break if the survey format changes.

  2. String literal filtering: The filtering for "undefined" strings suggests data quality issues upstream that might be better addressed at the source.

Consider these improvements:

+// Define constants for survey key patterns
+const SURVEY_RESPONSE_KEYS = {
+  first: '$survey_response',
+  subsequent: (index: number) => `$survey_response_${index}`
+} as const;

 function extractSurveyAnswers(questions: any[], answers: any) {
   // ... existing code ...
   
   const getAnswerByKey = (key: string) => {
     const questionIndex = questions.findIndex((q) => q.key === key);
     if (questionIndex === -1) return null;

-    const answerKey =
-      questionIndex === 0
-        ? "$survey_response"
-        : `$survey_response_${questionIndex}`;
+    const answerKey = questionIndex === 0 
+      ? SURVEY_RESPONSE_KEYS.first
+      : SURVEY_RESPONSE_KEYS.subsequent(questionIndex);
     
     const answer = answers[answerKey];
-    return answer && answer !== "" ? answer : null;
+    // Normalize undefined/empty values
+    return answer && answer !== "" && answer !== "undefined" ? answer : null;
   };

106-110: Consider stronger type validation for survey data.

The current schema uses z.any() for questions and answers, which provides no type safety. Consider defining more specific schemas if the survey structure is known.

+const surveyQuestionSchema = z.object({
+  key: z.string(),
+  // add other expected question properties
+});
+
+const surveyAnswersSchema = z.record(z.string(), z.any());

 const saveOnboardingAnswersBody = z.object({
   surveyId: z.string().optional(),
-  questions: z.any(),
-  answers: z.any(),
+  questions: z.array(surveyQuestionSchema),
+  answers: surveyAnswersSchema,
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97f033e and aa6baad.

📒 Files selected for processing (3)
  • apps/web/prisma/migrations/20250606102158_onboarding_answers/migration.sql (1 hunks)
  • apps/web/prisma/schema.prisma (1 hunks)
  • apps/web/utils/actions/user.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/web/prisma/migrations/20250606102158_onboarding_answers/migration.sql (1)

1-6: LGTM! Migration correctly adds survey fields.

The migration properly adds the new survey-related columns to the User table with appropriate data types.

apps/web/prisma/schema.prisma (1)

62-67: LGTM! Schema changes are well-structured and documented.

The new survey fields are properly typed and the comments clearly explain their purpose for easier querying of onboarding responses.

apps/web/utils/actions/user.ts (1)

195-205: LGTM! Database update correctly uses extracted survey answers.

The update operation properly saves both the original onboarding answers and the extracted individual survey fields for easier querying.

@elie222 elie222 merged commit 786a6a4 into main Jun 6, 2025
10 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 17, 2025
@elie222 elie222 deleted the feat/survey-answers branch December 18, 2025 23:04
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.

1 participant