Skip to content

Add HCaptcha integration to NetworkCoverageAddMonitorDialog and update dependencies - #3621

Merged
Baalmart merged 2 commits into
stagingfrom
website-hcapture
Jun 10, 2026
Merged

Add HCaptcha integration to NetworkCoverageAddMonitorDialog and update dependencies#3621
Baalmart merged 2 commits into
stagingfrom
website-hcapture

Conversation

@OchiengPaul442

@OchiengPaul442 OchiengPaul442 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done

Screenshots (optional)

Summary by CodeRabbit

  • New Features
    • Added HCaptcha verification requirement when saving network monitors.
    • Added required field indicators for Network, Operator, Manufacturer, and Pollutants fields.
    • Improved error messaging and auto-scrolling to error notifications in the monitor dialog.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 27 minutes and 42 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5f4010a3-f8b1-4028-b3b2-aa81b82ac67a

📥 Commits

Reviewing files that changed from the base of the PR and between ed2e60a and 6636795.

📒 Files selected for processing (1)
  • src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx
📝 Walkthrough

Walkthrough

This PR adds HCaptcha bot-verification to the NetworkCoverageAddMonitorDialog. The component now requires users to complete a captcha challenge before submitting a new network monitor, validates the captcha token alongside other form fields, includes the token in the API payload, and resets the widget after successful submission.

Changes

HCaptcha Bot Verification in Network Monitor Dialog

Layer / File(s) Summary
HCaptcha Dependency Addition
src/website/package.json
The @hcaptcha/react-hcaptcha package (version ^2.0.2) is added to dependencies.
Captcha State and Lifecycle Management
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx
useCallback hook is imported; refs and state track captchaToken, HCaptcha instance, and error scroll target; memoized onVerify and onExpire handlers manage token lifecycle; an effect scrolls error into view when error changes; captcha token is cleared when the dialog opens.
Form Validation and Payload Integration
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx
Validation enforces that network, operator, manufacturer, pollutants, and captchaToken are all present before submission; the submission payload conditionally includes captchaToken.
Post-Save Captcha Reset
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx
After successful save, the captcha token is cleared and the HCaptcha widget is reset via captchaRef.current?.resetCaptcha() before the dialog closes.
UI Updates: Labels, Error Scrolling, and Widget Rendering
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx
Scrollable content area uses scrollContainerRef for error scroll behavior; form field labels add required-field markers (*) for Network, Operator, Manufacturer, and Pollutants; error message rendering uses errorRef; HCaptcha component is rendered in the dialog footer with sitekey from NEXT_PUBLIC_HCAPTCHA_SITE_KEY environment variable and wired to verify/expire handlers and the captcha ref.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • Baalmart
  • Codebmk

Poem

🤖 A robot gatekeeper now guards the door,
Verifying humans before they soar,
With captcha tokens and refs held tight,
The monitor form now sleeps more sound at night. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding HCaptcha integration to the NetworkCoverageAddMonitorDialog component and updating project dependencies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch website-hcapture

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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.

@github-actions

Copy link
Copy Markdown
Contributor

New azure website changes available for preview here

@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

🧹 Nitpick comments (2)
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx (2)

81-85: ⚡ Quick win

Remove unused scrollContainerRef check.

The effect checks scrollContainerRef.current but never uses it. The scrollIntoView call only operates on errorRef.current, so the container check is unnecessary.

♻️ Simplify the condition
-  if (error && errorRef.current && scrollContainerRef.current) {
+  if (error && errorRef.current) {
     errorRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' });
   }
🤖 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
`@src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx`
around lines 81 - 85, The useEffect in NetworkCoverageAddMonitorDialog checks
scrollContainerRef.current but never uses it; remove the unnecessary check so
the effect only guards on error and errorRef.current before calling
errorRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' }). Update
the dependency array and condition to reference only error and errorRef (keep
useEffect, errorRef, and the scrollIntoView call intact) to simplify the logic.

474-474: 💤 Low value

Optional: Simplify captcha token payload assignment.

Since validation at line 419 enforces captchaToken as required, it will always be truthy at this point. The conditional check is technically redundant, though it follows the defensive pattern used for optional fields above.

♻️ Alternative (optional)
-    if (captchaToken) payload.captchaToken = captchaToken;
+    payload.captchaToken = captchaToken;
🤖 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
`@src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx`
at line 474, In NetworkCoverageAddMonitorDialog, the conditional "if
(captchaToken) payload.captchaToken = captchaToken;" is redundant because prior
validation guarantees captchaToken is set; simplify by assigning directly: set
payload.captchaToken = captchaToken (remove the conditional) where payload is
constructed so the token is always included; ensure you only change this
assignment and keep other optional-field defensive checks intact.
🤖 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
`@src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx`:
- Around line 938-945: The HCaptcha usage unconditionally asserts
process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY with ! which can throw if the env var
is missing; update the NetworkCoverageAddMonitorDialog render to check the
runtime value of process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY (used as the sitekey
prop for HCaptcha) and only render the HCaptcha component when it is a non-empty
string, otherwise render a safe fallback UI/message and ensure
handleCaptchaVerify/handleCaptchaExpire/captchaRef logic is bypassed or handles
the absence gracefully; alternatively, compute a validated const (e.g.,
captchaSiteKey) at module/component start and use that in the conditional render
to avoid the non-null assertion.

---

Nitpick comments:
In
`@src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx`:
- Around line 81-85: The useEffect in NetworkCoverageAddMonitorDialog checks
scrollContainerRef.current but never uses it; remove the unnecessary check so
the effect only guards on error and errorRef.current before calling
errorRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' }). Update
the dependency array and condition to reference only error and errorRef (keep
useEffect, errorRef, and the scrollIntoView call intact) to simplify the logic.
- Line 474: In NetworkCoverageAddMonitorDialog, the conditional "if
(captchaToken) payload.captchaToken = captchaToken;" is redundant because prior
validation guarantees captchaToken is set; simplify by assigning directly: set
payload.captchaToken = captchaToken (remove the conditional) where payload is
constructed so the token is always included; ensure you only change this
assignment and keep other optional-field defensive checks intact.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9731e998-6f0d-4963-b40d-98eb3e03a605

📥 Commits

Reviewing files that changed from the base of the PR and between 27e8ce4 and ed2e60a.

⛔ Files ignored due to path filters (1)
  • src/website/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • src/website/package.json
  • src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx

Copilot AI 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.

Pull request overview

This PR adds an hCaptcha gate to the Network Coverage “Add Monitor” dialog so that saving a network monitor requires captcha verification, and updates the website dependencies to include the hCaptcha React package.

Changes:

  • Added @hcaptcha/react-hcaptcha dependency.
  • Integrated an hCaptcha widget into NetworkCoverageAddMonitorDialog, including token handling and sending captchaToken in the save payload.
  • Added additional required-field validation and improved error display (auto-scroll to error).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx Adds hCaptcha UI + token state, expands required-field validation, and improves error visibility/scrolling.
src/website/package.json Adds @hcaptcha/react-hcaptcha dependency.
src/website/package-lock.json Locks @hcaptcha/react-hcaptcha and its resolved metadata.
Files not reviewed (1)
  • src/website/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx:703

  • These fields are now visually marked as required ("*") but the inputs are missing required/aria-required, so browsers and assistive tech won’t recognize them as required. Add required and aria-required="true" to match the new validation rules.
            <label className="block sm:col-span-2">
              <div className="mb-1 text-xs font-semibold text-slate-500">
                Network *
              </div>
              <input
                value={network}
                onChange={(e) => setNetwork(e.target.value)}
                className="w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm outline-none focus:border-blue-300"
              />
            </label>

src/website/src/views/solutions/NetworkCoverage/components/NetworkCoverageAddMonitorDialog.tsx:748

  • These fields are now visually marked as required ("*") but the inputs are missing required/aria-required, so browsers and assistive tech won’t recognize them as required. Add required and aria-required="true" to match the new validation rules.
            <label className="block">
              <div className="mb-1 text-xs font-semibold text-slate-500">
                Manufacturer *
              </div>
              <input
                value={manufacturer}
                onChange={(e) => setManufacturer(e.target.value)}
                className="w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm outline-none focus:border-blue-300"
              />
            </label>

            <label className="block sm:col-span-2">
              <div className="mb-1 text-xs font-semibold text-slate-500">
                Pollutants (comma separated) *
              </div>
              <input
                value={pollutants}
                onChange={(e) => setPollutants(e.target.value)}
                placeholder="PM2.5, PM10"
                className="w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm outline-none focus:border-blue-300"
              />
            </label>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const previousActiveElementRef = useRef<HTMLElement | null>(null);
const closeTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const captchaRef = useRef<HCaptcha>(null);
Comment on lines +938 to +945
<div className="mt-4">
<HCaptcha
sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
onVerify={handleCaptchaVerify}
onExpire={handleCaptchaExpire}
ref={captchaRef}
/>
</div>
if (!operator.trim()) return 'Operator is required';
if (!manufacturer.trim()) return 'Manufacturer is required';
if (!pollutants.trim()) return 'Pollutants are required';
if (!captchaToken) return 'Please complete the captcha verification';
@github-actions

Copy link
Copy Markdown
Contributor

New azure website changes available for preview here

@Baalmart
Baalmart merged commit ad750bd into staging Jun 10, 2026
27 checks passed
@Baalmart
Baalmart deleted the website-hcapture branch June 10, 2026 19:09
@Baalmart Baalmart mentioned this pull request Jun 10, 2026
6 tasks
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.

3 participants