Skip to content

fix: prevent saving empty links (#267)#285

Open
prakshithamalla-art wants to merge 3 commits into
vishnukothakapu:mainfrom
prakshithamalla-art:fix/empty-link-validation
Open

fix: prevent saving empty links (#267)#285
prakshithamalla-art wants to merge 3 commits into
vishnukothakapu:mainfrom
prakshithamalla-art:fix/empty-link-validation

Conversation

@prakshithamalla-art

@prakshithamalla-art prakshithamalla-art commented May 30, 2026

Copy link
Copy Markdown
Contributor

Overview

Closes #267. Added robust client-side validation to the dashboard to prevent users from submitting empty or whitespace-only links.

Changes Implemented

  • Validation Guard: Created validateAndAddLink inside DashboardClient.tsx to ensure both url and label are populated before API execution.
  • Data Sanitization: Implemented .trim() on all inputs to prevent the database from being populated with whitespace-only entries.
  • Enhanced UI Feedback: Integrated toast notifications to provide clear error messages when validation fails.
  • State Management: Added isProcessing state to prevent duplicate form submissions during network requests.

Why this improves LinkID

  • Database Integrity: Prevents malformed or empty data from entering the database.
  • Improved UX: Provides immediate, actionable feedback to users rather than failing silently or creating broken redirect links.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced validation to prevent submitting empty or whitespace-only URLs in the add link feature.
    • URLs are now automatically trimmed of leading and trailing whitespace during submission.
  • Tests

    • Added test coverage for link input validation.
  • Chores

    • Updated development dependencies.

@vercel

vercel Bot commented May 30, 2026

Copy link
Copy Markdown

@prakshithamalla-art is attempting to deploy a commit to the vishnukothakapu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@prakshithamalla-art, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5fb52059-2167-4d67-bdca-00c19fb0ffdb

📥 Commits

Reviewing files that changed from the base of the PR and between d06f3d5 and 624f525.

📒 Files selected for processing (2)
  • app/dashboard/AddLinkBox.tsx
  • app/dashboard/__tests__/AddLinkBox.test.tsx
📝 Walkthrough

Walkthrough

This PR addresses empty link submission in the dashboard by adding client-side validation to the AddLinkBox form. The component now rejects empty/whitespace URLs with an error toast before validation, trims URLs before POST, and includes comprehensive test coverage for the new behavior plus supporting test dependencies.

Changes

Empty URL Validation and Test Coverage

Layer / File(s) Summary
AddLinkBox empty URL validation and cleanup
app/dashboard/AddLinkBox.tsx
Adds formatLabel(key: string) utility for consistent platform-key display formatting. Refactors POPULAR_PLATFORMS structure for clarity. In submit(), inserts early rejection of empty/whitespace URLs with "Field cannot be empty" error before existing URL and platform validation. Changes POST payload to send url.trim() instead of raw URL. Adds JSDoc and comment blocks throughout, expands platform Select and input onChange handlers to multi-line format, and adds trailing "system maintenance" comment.
AddLinkBox empty-URL validation test and test dependencies
app/dashboard/__tests__/AddLinkBox.test.tsx, package.json
Introduces Jest/React Testing Library test file mocking react-hot-toast error/success functions and getCsrfToken. Test renders AddLinkBox, clicks "Add link" without entering URL, and verifies toast.error("Field cannot be empty") is called while onAdded callback is not invoked. Updates package.json to add @testing-library/react and @types/jest to devDependencies.
DashboardClient file structure
app/dashboard/DashboardClient.tsx
Adjusts closing-brace placement at end of file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • vishnukothakapu/linkid#148: Both PRs modify AddLinkBox.tsx submit() URL handling to prevent invalid submissions; main PR adds empty-check and trimming, while PR #148 tightens validation via validateUrl and blocks with toast.error.
  • vishnukothakapu/linkid#165: Both PRs refactor AddLinkBox.tsx platform-related constants and submit flow; main PR normalizes label formatting and adds empty-URL validation, while PR #165 refactors platform selection requirements.

Suggested reviewers

  • vedhapprakashni
  • Anushreebasics

Poem

🐰 A bunny hops through empty fields,
Finding validation that truly shields!
URLs now trimmed, no blanks allowed,
The form stands sturdy, tested and proud.
Tests in place, dependencies neat,
Another bug caught—chef's kiss, so sweet! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: prevent saving empty links (#267)' directly and concisely summarizes the main change: adding validation to prevent empty link submissions.
Linked Issues check ✅ Passed The PR successfully implements all acceptance criteria: empty URL validation with trimming, error message display, and prevents submission of empty/whitespace-only links.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #267: validation logic in AddLinkBox, test coverage, and necessary dependencies. File structure adjustments in DashboardClient.tsx are minimal and not out-of-scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
linkid Ready Ready Preview, Comment Jun 1, 2026 9:33am

@Anushreebasics Anushreebasics left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for PR!
Please address the following changes:

  • Remove or relocate validateAndAddLink from [DashboardClient] (or use it in [AddLinkBox] before POST).

  • Wire isProcessing through [LinksSection]→ [AddLinkBox] to disable the add UI during processing, or remove it and rely on the existing [loading] inside [AddLinkBox]

  • Add a small unit/integration test to cover the add-link flow (client + server validation).

  • Fix newline at EOF in [DashboardClient.tsx] and confirm any stylistic text/footer changes are intended.

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/dashboard/AddLinkBox.tsx (1)

85-93: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate the trimmed URL, not the raw input.

The empty-guard rejects whitespace-only input, but validateUrl(url) then runs on the untrimmed string while the payload later sends url.trim(). A value like " https://example.com " passes the empty check, may be rejected by validateUrl due to surrounding whitespace, yet the intended (trimmed) value is valid. Trim once and validate the trimmed value to keep validation and submission consistent.

🐛 Proposed fix
-        if (!url || !url.trim()) {
-            return toast.error("Field cannot be empty");
-        }
-
-        // Structural and configuration checking parameters
-        const validation = validateUrl(url);
+        const trimmedUrl = url.trim();
+        if (!trimmedUrl) {
+            return toast.error("Field cannot be empty");
+        }
+
+        const validation = validateUrl(trimmedUrl);
         if (!validation.valid) {
             return toast.error(validation.error);
         }

And reuse trimmedUrl in the payload:

-                    url: url.trim(),
+                    url: trimmedUrl,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/dashboard/AddLinkBox.tsx` around lines 85 - 93, Trim the input once and
validate the trimmed value: create a trimmedUrl = url.trim() and use trimmedUrl
for the empty check, pass trimmedUrl into validateUrl(trimmedUrl) instead of the
raw url, and reuse trimmedUrl in the payload submission; update any toast.error
calls to reference validation.error from validateUrl(trimmedUrl) so validation
and submission are consistent (references: AddLinkBox.tsx, variable url,
trimmedUrl, function validateUrl, toast.error).
package.json (1)

6-14: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Fix test runner/tooling wiring for the new React test

  • package.json’s test script runs tsx --test only for lib/csrf.test.ts, lib/middleware/csrf.test.ts, lib/analytics.test.ts, and lib/accountMergeUtils.test.ts—it doesn’t include app/dashboard/__tests__/AddLinkBox.test.tsx, so that test won’t run in CI.
  • Searches through JSON manifests found no Jest runner/config entries (jest, ts-jest, babel-jest, jest-environment-jsdom); the only related testing-library item surfaced was @testing-library/dom in package-lock.json.

Wire the new test into the invoked runner (either switch to a proper Jest + jsdom setup, or ensure the test is compatible with the tsx --test runner and that CI executes it).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 6 - 14, The test script in package.json currently
invokes "tsx --test" with a hardcoded list of files and omits the new React test
app/dashboard/__tests__/AddLinkBox.test.tsx; update the "test" npm script (the
"test" entry) to include the new test path or replace the hardcoded list with a
glob (e.g., all **/*.test.*) so the AddLinkBox.test.tsx runs in CI, and if the
test requires jsdom/React support, either switch the runner to a proper Jest
setup (add jest + jest-environment-jsdom and a jest config) or confirm the tsx
test runner supports jsdom and adjust test tooling accordingly; ensure
references to "test" script, "tsx --test", and the file
app/dashboard/__tests__/AddLinkBox.test.tsx are updated consistently.
🧹 Nitpick comments (1)
app/dashboard/AddLinkBox.tsx (1)

20-25: 💤 Low value

Trim the misleading/verbose comment blocks.

Several added comments are inaccurate or noise (e.g., the JSDoc has a stray * * on Line 23; Line 63 claims validation happens "inside local state handlers" when it's actually in submit(); the trailing "System Maintenance Context Block" on Lines 197-200 documents nothing actionable). These add maintenance overhead without value.

Also applies to: 59-65, 196-200

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/dashboard/AddLinkBox.tsx` around lines 20 - 25, Trim and correct
noisy/misleading comments in AddLinkBox: remove the stray "* *" in the JSDoc
block that documents the platform-key formatter and simplify that JSDoc to a
single accurate sentence with correct `@param` and `@returns`, update the comment
that currently claims validation happens "inside local state handlers" to
correctly state that validation occurs in submit(), and delete the
non-actionable "System Maintenance Context Block" comment at the end of the
file; locate these edits around the platform-key formatter JSDoc and the
AddLinkBox component's submit() method to ensure comments now reflect the actual
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/dashboard/__tests__/AddLinkBox.test.tsx`:
- Around line 1-25: The test file app/dashboard/__tests__/AddLinkBox.test.tsx is
not executed because the test runner only picks up lib/*.test.ts via `tsx
--test` and the test uses Jest globals; to fix, move or rename the test into the
lib test pattern (e.g., relocate AddLinkBox.test.tsx into lib/ as
lib/AddLinkBox.test.tsx or lib/__tests__/AddLinkBox.test.tsx) and update its
import path for AddLinkBox if needed so the existing jest.mock usage and
assertions remain valid; this ensures the test is discovered by the current npm
test runner without changing test framework wiring.

In `@package.json`:
- Line 54: Add `@testing-library/dom` to devDependencies in package.json alongside
`@testing-library/react`; update the devDependencies block to include the package
(matching semver compatible with `@testing-library/react`, e.g., a caret version
that aligns with the peer expected by "`@testing-library/react`": "^16.3.2") so
the project declares the peer explicitly instead of relying on package-lock.json
or auto-install behavior.

---

Outside diff comments:
In `@app/dashboard/AddLinkBox.tsx`:
- Around line 85-93: Trim the input once and validate the trimmed value: create
a trimmedUrl = url.trim() and use trimmedUrl for the empty check, pass
trimmedUrl into validateUrl(trimmedUrl) instead of the raw url, and reuse
trimmedUrl in the payload submission; update any toast.error calls to reference
validation.error from validateUrl(trimmedUrl) so validation and submission are
consistent (references: AddLinkBox.tsx, variable url, trimmedUrl, function
validateUrl, toast.error).

In `@package.json`:
- Around line 6-14: The test script in package.json currently invokes "tsx
--test" with a hardcoded list of files and omits the new React test
app/dashboard/__tests__/AddLinkBox.test.tsx; update the "test" npm script (the
"test" entry) to include the new test path or replace the hardcoded list with a
glob (e.g., all **/*.test.*) so the AddLinkBox.test.tsx runs in CI, and if the
test requires jsdom/React support, either switch the runner to a proper Jest
setup (add jest + jest-environment-jsdom and a jest config) or confirm the tsx
test runner supports jsdom and adjust test tooling accordingly; ensure
references to "test" script, "tsx --test", and the file
app/dashboard/__tests__/AddLinkBox.test.tsx are updated consistently.

---

Nitpick comments:
In `@app/dashboard/AddLinkBox.tsx`:
- Around line 20-25: Trim and correct noisy/misleading comments in AddLinkBox:
remove the stray "* *" in the JSDoc block that documents the platform-key
formatter and simplify that JSDoc to a single accurate sentence with correct
`@param` and `@returns`, update the comment that currently claims validation happens
"inside local state handlers" to correctly state that validation occurs in
submit(), and delete the non-actionable "System Maintenance Context Block"
comment at the end of the file; locate these edits around the platform-key
formatter JSDoc and the AddLinkBox component's submit() method to ensure
comments now reflect the actual implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b68eca50-cc11-4f7b-91c3-51895e12005e

📥 Commits

Reviewing files that changed from the base of the PR and between f11e0d7 and d06f3d5.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • app/dashboard/AddLinkBox.tsx
  • app/dashboard/DashboardClient.tsx
  • app/dashboard/__tests__/AddLinkBox.test.tsx
  • package.json

Comment thread app/dashboard/__tests__/AddLinkBox.test.tsx
Comment thread package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent saving empty links in Dashboard

3 participants