Skip to content

Update Feedback Unit ID field lookup to show saved responses#969

Merged
tarinrickett merged 1 commit into
masterfrom
tarin/feedback
May 27, 2025
Merged

Update Feedback Unit ID field lookup to show saved responses#969
tarinrickett merged 1 commit into
masterfrom
tarin/feedback

Conversation

@tarinrickett

@tarinrickett tarinrickett commented May 27, 2025

Copy link
Copy Markdown
Contributor

Description

  • Update to GET via Unit ID lookup field rather than actual Unit linked record itself
  • Also added "Submitting..." state

Issue

https://bluedotimpact.slack.com/archives/C08DC9SSA66/p1748294763877639

Developer checklist

Screenshot

Screenshot 2025-05-27 at 15 29 13
Screen.Recording.2025-05-27.at.15.28.19.mov

Summary by CodeRabbit

  • New Features

    • The feedback submission button now displays a "Sending..." label and is disabled during submission or loading, providing clearer feedback to users and preventing duplicate submissions.
  • Bug Fixes

    • Improved handling of feedback submission state to ensure users cannot submit multiple times or interact while loading.
  • Refactor

    • Updated feedback data structure, replacing the user name with a unit identifier for improved data consistency.

@coderabbitai

coderabbitai Bot commented May 27, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the UnitFeedback data model by removing the userFullName property and introducing a new unit string property, with corresponding adjustments in Airtable field mappings and schema. The feedback submission UI now provides explicit loading states, disables the submit button during asynchronous operations, and updates button text to reflect submission progress.

Changes

File(s) Change Summary
apps/website/src/components/courses/UnitFeedback.tsx Added isSubmitting state, improved UI feedback for loading/submitting, disabled button during async ops
apps/website/src/lib/api/db/tables.ts Updated UnitFeedback type: added unit, removed userFullName; adjusted Airtable mappings/schema
apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts Changed feedback creation to use unit field instead of unitId; removed obsolete comment

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UnitFeedbackComponent
    participant API
    participant AirtableDB

    User->>UnitFeedbackComponent: Open Unit Feedback UI
    UnitFeedbackComponent->>API: GET existing feedback
    API->>AirtableDB: Query feedback by unit
    AirtableDB-->>API: Return feedback data
    API-->>UnitFeedbackComponent: Return feedback data
    User->>UnitFeedbackComponent: Submit feedback
    UnitFeedbackComponent->>UnitFeedbackComponent: Set isSubmitting = true
    UnitFeedbackComponent->>API: PUT feedback (with unit field)
    API->>AirtableDB: Upsert feedback with unit field
    AirtableDB-->>API: Confirm save
    API-->>UnitFeedbackComponent: Return result
    UnitFeedbackComponent->>UnitFeedbackComponent: Set isSubmitting = false
Loading

Poem

A bunny hopped through fields of code,
Where feedback forms and states abode.
With "Sending..." now upon the screen,
No double clicks or race unseen.
The schema changed, a unit found—
The user's name no more renowned.
🐇✨

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.

npm warn config production Use --omit=dev instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-27T14_34_04_683Z-debug-0.log

✨ 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.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR Summary

Updates the feedback system to use lookup fields for unit references instead of direct record links, while adding loading states for better UX during submission.

  • Inconsistency in apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts between scan operation using 'unitId' and insert using 'unit' field could cause feedback retrieval issues
  • Added submission states in apps/website/src/components/courses/UnitFeedback.tsx with disabled button and 'Sending...' text
  • Removed 'userFullName' field and added new 'unit' field in apps/website/src/lib/api/db/tables.ts for lookup-based unit references

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@tarinrickett tarinrickett merged commit cc34060 into master May 27, 2025
3 of 4 checks passed
@tarinrickett tarinrickett deleted the tarin/feedback branch May 27, 2025 14:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1f3cb1 and abbc5de.

📒 Files selected for processing (3)
  • apps/website/src/components/courses/UnitFeedback.tsx (4 hunks)
  • apps/website/src/lib/api/db/tables.ts (2 hunks)
  • apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/website/src/components/courses/UnitFeedback.tsx (1)
apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts (1)
  • GetUnitFeedbackResponse (11-14)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (8)
apps/website/src/lib/api/db/tables.ts (3)

134-135: LGTM! Field mapping updates align with data model changes.

The field mappings correctly reflect the new unit and unitId field distinction. The changes appear to repurpose existing Airtable fields for the new lookup functionality.


143-144: Verify schema consistency with field mappings.

The schema correctly includes both unit and unitId as string fields, matching the type definition and field mappings.


120-120:

Details

✅ Verification successful

Verify the purpose and usage of the new unit field.

The addition of the unit: string field alongside the existing unitId: string suggests different purposes for these fields. Based on the PR objectives, unit appears to be a lookup field displaying the Unit ID, while unitId might be the actual linked record ID.

Ensure this dual-field approach is used consistently across the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Verify how unit and unitId fields are used in the codebase
# Expected: Consistent usage patterns for both fields

# Search for usage of both unit and unitId fields in TypeScript files
echo "=== Searching for 'unit:' field usage ==="
rg -A 2 -B 2 "unit:" --type ts

echo -e "\n=== Searching for 'unitId:' field usage ==="  
rg -A 2 -B 2 "unitId:" --type ts

echo -e "\n=== Searching for UnitFeedback type usage ==="
rg -A 5 "UnitFeedback" --type ts

Length of output: 23677


🏁 Script executed:

#!/bin/bash
# Verify db.update usage for UnitFeedback
echo "=== Looking for db.update(unitFeedbackTable) usage ==="
rg -n "db.update(unitFeedbackTable" -A 10 -B 5 apps/website/src/pages/api/courses

Length of output: 290


🏁 Script executed:

#!/bin/bash
# Verify insert and update calls for UnitFeedback
echo "=== Searching for db.insert(unitFeedbackTable) usage ==="
rg -F "db.insert(unitFeedbackTable" -n apps/website/src

echo -e "\n=== Searching for db.update(unitFeedbackTable) usage ==="
rg -F "db.update(unitFeedbackTable" -n apps/website/src

Length of output: 639


🏁 Script executed:

#!/bin/bash
# Get context around insert and update calls for UnitFeedback to verify both fields
echo "=== Context for db.insert(unitFeedbackTable) ==="
rg -A5 -B5 "db.insert(unitFeedbackTable" -n apps/website/src/pages/api/courses

echo -e "\n=== Context for db.update(unitFeedbackTable) ==="
rg -A5 -B5 "db.update(unitFeedbackTable" -n apps/website/src/pages/api/courses

Length of output: 557


Dual-field usage confirmed as consistent

  • In the API route (feedback.ts), only the unit field is explicitly set (as the linked-record key); the unitId lookup field is auto‐populated by Airtable.
  • Front-end components and tests reference only the unit property (or the returned UnitFeedback.overallRating/anythingElse), never the unitId lookup field.
  • The UnitFeedback type and table mappings correctly include both fields for schema completeness; no code references to unitId need updating.

All usages align with the intended distinction—no further changes required.

apps/website/src/components/courses/UnitFeedback.tsx (5)

23-23: LGTM! Proper state management for submission tracking.

The addition of isSubmitting state provides necessary control for preventing duplicate submissions and improving user experience.


27-27: Good practice: Extracting loading state for comprehensive button control.

Destructuring the loading state from the useAxios hook allows for proper button state management during both initial data fetching and form submission.


44-44: LGTM! Proper async operation state management.

Setting isSubmitting to true before the API call prevents multiple concurrent submissions and provides immediate user feedback.


63-65: Excellent: Proper cleanup in finally block.

Using the finally block ensures isSubmitting is reset regardless of success or failure, preventing the UI from getting stuck in a submitting state.


116-118: Perfect UX implementation for submit button state.

The button correctly:

  • Disables during both loading (initial fetch) and submitting states
  • Provides clear visual feedback with "Sending..." text
  • Prevents user confusion and duplicate submissions

// If the feedback does NOT exist, create it
upsertedFeedback = await db.insert(unitFeedbackTable, {
unitId,
unit: unitId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify consistency between GET filtering and PUT field assignment.

The PUT operation now assigns the unitId value to the unit field, but the GET operation (line 52) still filters by the unitId field. This inconsistency could lead to issues where newly created feedback records cannot be retrieved by subsequent GET requests.

Please verify this is intentional behavior. If both fields should contain the same value, consider updating the creation logic:

 upsertedFeedback = await db.insert(unitFeedbackTable, {
   unit: unitId,
+  unitId: unitId,
   createdAt: new Date().toISOString(),
   lastModified: new Date().toISOString(),
   userEmail: auth.email,
   overallRating,
   anythingElse,
 });

Or update the GET filter to use the unit field instead.

Run this script to check for existing feedback records and their field values:


🏁 Script executed:

#!/bin/bash
# Description: Check how existing feedback records use unit vs unitId fields
# Expected: Understanding of field usage patterns

# Look for other API endpoints that interact with UnitFeedback
echo "=== Searching for UnitFeedback API usage ==="
rg -A 5 -B 5 "unitFeedbackTable" --type ts

echo -e "\n=== Searching for feedback filtering patterns ==="
rg -A 3 -B 3 "filterByFormula.*unit" --type ts

Length of output: 8812


🏁 Script executed:

#!/bin/bash
echo "=== export type UnitFeedback ==="
rg -C 5 "export type UnitFeedback" -n apps/website/src/lib/api/db/tables.ts

echo -e "\n=== unitFeedbackTable mapping ==="
rg -C 10 "export const unitFeedbackTable" -n apps/website/src/lib/api/db/tables.ts

echo -e "\n=== unitFeedbackTable mappings block ==="
sed -n '/export const unitFeedbackTable/,/};/p' apps/website/src/lib/api/db/tables.ts | sed -n '/mappings:/,/}/p'

echo -e "\n=== Search for 'unitId' references in tables.ts ==="
rg -n "unitId" apps/website/src/lib/api/db/tables.ts

Length of output: 2208


Missing unitId in feedback insertion

The UnitFeedback type and Airtable mapping include both unit and unitId, but the insert call only sets unit. Since the GET scan filters by unitId, newly created feedback won’t be found.

• File: apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts (else branch around line 85)

Suggested fix:

 upsertedFeedback = await db.insert(unitFeedbackTable, {
   unit: unitId,
+  unitId: unitId,
   createdAt: new Date().toISOString(),
   lastModified: new Date().toISOString(),
   userEmail: auth.email,
   overallRating,
   anythingElse,
 });
📝 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
unit: unitId,
upsertedFeedback = await db.insert(unitFeedbackTable, {
unit: unitId,
unitId: unitId,
createdAt: new Date().toISOString(),
lastModified: new Date().toISOString(),
userEmail: auth.email,
overallRating,
anythingElse,
});
🤖 Prompt for AI Agents
In apps/website/src/pages/api/courses/[courseSlug]/[unitId]/feedback.ts at line
85, the PUT operation assigns the unitId value only to the 'unit' field but the
GET operation filters by 'unitId'. To fix this inconsistency, update the
feedback insertion logic to include both 'unit' and 'unitId' fields with the
unitId value. This ensures that newly created feedback records can be retrieved
correctly by the GET requests filtering on 'unitId'.

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