Skip to content

Refactor use devices hook mutations to support info banner system#3574

Merged
Baalmart merged 8 commits into
airqo-platform:stagingfrom
BwanikaRobert:Refactor-useDevices-hook-mutations-to-support-InfoBanner-system
Jun 5, 2026
Merged

Refactor use devices hook mutations to support info banner system#3574
Baalmart merged 8 commits into
airqo-platform:stagingfrom
BwanikaRobert:Refactor-useDevices-hook-mutations-to-support-InfoBanner-system

Conversation

@BwanikaRobert

@BwanikaRobert BwanikaRobert commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

Decouples all remaining ReusableToast calls from mutation hooks in useDevices.ts and delegates notification responsibility to the calling UI layer via the useBanner / useBannerWithDelay system.

Hooks decoupled (removed ReusableToast, added optional onSuccess/onError interfaces):
useClaimDevice, useBulkClaimDevices, useUnassignDeviceFromOrganization, useUpdateDeviceBulk, useUpdateDeviceGroup, usePrepareDeviceForShipping, usePrepareBulkDevicesForShipping, useGenerateShippingLabels

Components updated in this PR:

  • bulk-edit-device-details-modal.tsx — wired hook-level callbacks; error uses scoped: true inline, success uses showBannerWithDelay (scoped: false) after dialog closes.

  • PrepareShippingModal.tsx — replaced all 8 ReusableToast calls; file/import validation errors use scoped: true, bulk preparation success uses showBannerWithDelay (scoped: false).

  • shipping/[batchId]/page.tsx — removed ReusableToast; wired useGenerateShippingLabels with hook-level callbacks and replaced inline validation toasts with showBanner (scoped: false).

  • Components already migrated in PR feat(vertex/devices): migrate device management toasts to InfoBanner … #3503 (no changes needed):

  • create-device-modal.tsx

  • import-device-modal.tsx

  • deploy-device-component.tsx

  • recall-device-dialog.tsx

  • add-maintenance-log-modal.tsx

Not implemented because files in the task spec do not exist:

  • claim-devices-dialog.tsx, claim-single-device.tsx — actual file is claim-device-modal.tsx, which uses an internal multi-step state machine (step transitions + setError) for feedback. Adding banners would duplicate already-handled UX. Hook is decoupled; banner wiring can be added if a simpler claim component is built.
  • create-device-dialog.tsx, import-devices-dialog.tsx, recall-device-component.tsx, maintenance-log-dialog.tsx — none of these paths exist; their counterparts were already migrated in PR feat(vertex/devices): migrate device management toasts to InfoBanner … #3503.

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

How should this be manually tested?

  1. Open the Bulk Edit Devices modal (Admin → Networks → [Network] → select devices → Bulk Edit). Submit a valid update and confirm a global success banner appears after the dialog closes. Submit with an intentional error and confirm a scoped error banner appears inside the dialog.
  2. Open Prepare Shipping Modal (Admin → Shipping → Prepare New Batch). Try adding a duplicate device name and confirm a scoped error banner appears. Try importing an invalid file type and confirm the scoped error banner. Submit a valid batch and confirm a global success banner appears after the dialog closes.
  3. Navigate to Admin → Shipping → [Batch]. Select no devices and click Generate Labels — confirm an error banner appears. Select valid devices and generate labels — confirm a success banner appears with the label count.

What are the relevant tickets?

Summary by CodeRabbit

  • New Features

    • Added a shared clipboard copy utility for consistent copy-to-clipboard behavior across API cards, grids, and devices.
  • Bug Fixes

    • Replaced transient toasts with prominent banner messages for validation, import, and mutation error/success feedback across device, shipping, and bulk-update flows.
  • Refactor

    • Centralized notification handling by moving mutation callbacks to callers and standardizing success/error handling via banner callbacks.
  • Documentation

    • Changelog updated with the release entry.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 18 minutes and 29 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: 11509af7-9bd7-41ef-9943-577200f7eb35

📥 Commits

Reviewing files that changed from the base of the PR and between 56068c4 and 27cbb16.

📒 Files selected for processing (2)
  • src/vertex/components/features/grids/grid-details-card.tsx
  • src/vertex/components/features/grids/grid-measurements-api-card.tsx
📝 Walkthrough

Walkthrough

Refactors device/shipping mutation hooks to accept optional onSuccess/onError callbacks, centralizes clipboard copying in a new useClipboard hook, and updates multiple UI components (devices, grids, cohorts, shipping) to show banner-based feedback instead of ReusableToast.

Changes

Banner System Migration for Device Mutations and Clipboard

Layer / File(s) Summary
Mutation callback hooks
src/vertex/core/hooks/useDevices.ts
Multiple device/shipping mutation hooks now accept optional callback options (onSuccess/onError), invalidate relevant React Query caches, and forward data/errors to callers instead of showing toasts.
Shared clipboard hook
src/vertex/core/hooks/useClipboard.ts
New useClipboard(options?) wraps navigator.clipboard.writeText and shows success/error banners via useBanner.
Device UI banner & clipboard updates
src/vertex/components/features/devices/*, src/vertex/components/features/grids/*, src/vertex/components/features/cohorts/*
Bulk-edit modal, device activity and measurements cards, orphaned-devices alert, grid modals/cards, and cohort cards now use useClipboard and useBanner and rely on hook-level mutation callbacks for banner feedback.
Shipping label generation & preparation
src/vertex/app/(authenticated)/admin/shipping/[batchId]/page.tsx, src/vertex/components/features/shipping/PrepareShippingModal.tsx
Shipping page and PrepareShippingModal configure generate/prepare hooks with onSuccess/onError handlers and replace validation/import toast messages with banner calls; label success opens print modal via hook callback.
Changelog
src/vertex/app/changelog.md
Added Version 1.23.59 documenting the migration and files updated.

Sequence Diagram(s)

sequenceDiagram
  participant PrepareModal as PrepareShippingModal
  participant ShippingPage as ShippingBatchPage
  participant PrepareHook as usePrepareBulkDevicesForShipping
  participant LabelsHook as useGenerateShippingLabels

  PrepareModal->>PrepareHook: mutate(importData)
  PrepareHook-->>PrepareModal: onSuccess / onError (banner)
  ShippingPage->>LabelsHook: mutate(selectedDeviceNames)
  LabelsHook-->>ShippingPage: onSuccess (banner + open print modal) / onError (banner)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Baalmart
  • OchiengPaul442
  • Codebmk

Poem

✨ No more floating toasts adrift,
Callbacks steer each banner's lift,
Clipboard shared, mutations clean,
Scoped alerts in modal scene,
A tidier flow — the UI's swift.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The PR successfully decouples ReusableToast from hook mutations [#3497], adds onSuccess/onError callbacks to 8 hooks, and updates components to use useBanner. However, it only partially addresses the full scope: claim/onboarding/deployment/recall components mentioned in requirements remain unmodified. Verify whether the PR intentionally defers claim, onboarding, deployment, and recall component updates to a follow-up PR, or whether these should have been included in this PR's scope.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: refactoring useDevices hook mutations to support the banner system, which matches the primary objective of the PR.
Out of Scope Changes check ✅ Passed All changes directly support the PR objective. The useClipboard hook addition, banner integrations, and component updates are all within scope of decoupling ReusableToast and enabling banner-based notifications.

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

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

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

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure docs changes available for preview here

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure analytics_platform 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 (1)
src/vertex/components/features/devices/device-activity-item.tsx (1)

6-6: ⚡ Quick win

Consider using the useClipboard hook to reduce duplication.

This component reimplements the same clipboard-copy-with-banner-feedback pattern that was extracted to the useClipboard hook (introduced in this PR). device-measurements-api-card.tsx already uses the hook (line 12), and the PR summary mentions adding useClipboard to reduce duplication.

♻️ Refactor to use useClipboard
-import { useBanner } from '`@/context/banner-context`';
+import { useClipboard } from '`@/core/hooks/useClipboard`';
-    const { showBanner } = useBanner();
+    const { handleCopy } = useClipboard();
                                         <ReusableButton
                                             variant="text"
-                                            onClick={async () => {
-                                                try {
-                                                    await navigator.clipboard.writeText(previousSiteId);
-                                                    showBanner({ severity: 'success', message: 'Copied', scoped: false });
-                                                } catch {
-                                                    showBanner({ severity: 'error', message: 'Failed to copy', scoped: false });
-                                                }
-                                            }}
+                                            onClick={() => handleCopy(previousSiteId)}
                                             className="p-1"
                                             Icon={AqCopy01}
                                             aria-label="Copy site ID"
                                         />

Also applies to: 31-31, 109-123

🤖 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/vertex/components/features/devices/device-activity-item.tsx` at line 6,
This component duplicates clipboard-copy + banner feedback logic; refactor
DeviceActivityItem to use the existing useClipboard hook instead of manually
calling navigator.clipboard and useBanner: import and call useClipboard (the
hook already used in device-measurements-api-card) inside the DeviceActivityItem
component, replace the manual copy handlers (the duplicated logic around lines
31 and 109-123) with the hook's copy function and use its success/failure
callbacks to trigger banners as needed, and remove the now-unused
navigator.clipboard and banner-specific code (and any unused useBanner import)
so the component delegates copying and feedback to useClipboard.
🤖 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/vertex/core/hooks/useDevices.ts`:
- Around line 484-501: The hook useUpdateDeviceGroup dropped query invalidation;
restore it by injecting React Query's QueryClient (useQueryClient) and calling
queryClient.invalidateQueries(...) in the onSuccess handler (in addition to
options?.onSuccess?.()), invalidating the same query keys that
useUpdateDeviceBulk invalidates (e.g., device list and affected device detail
queries) so callers of useUpdateDeviceGroup no longer need to manually refresh;
keep mutationFn as devices.bulkUpdateDeviceDetails([...]) and ensure
options?.onError?.(error) remains unchanged.

---

Nitpick comments:
In `@src/vertex/components/features/devices/device-activity-item.tsx`:
- Line 6: This component duplicates clipboard-copy + banner feedback logic;
refactor DeviceActivityItem to use the existing useClipboard hook instead of
manually calling navigator.clipboard and useBanner: import and call useClipboard
(the hook already used in device-measurements-api-card) inside the
DeviceActivityItem component, replace the manual copy handlers (the duplicated
logic around lines 31 and 109-123) with the hook's copy function and use its
success/failure callbacks to trigger banners as needed, and remove the
now-unused navigator.clipboard and banner-specific code (and any unused
useBanner import) so the component delegates copying and feedback to
useClipboard.
🪄 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: 9728e814-6b56-416d-bafa-791b89573bef

📥 Commits

Reviewing files that changed from the base of the PR and between 740c697 and 55641b4.

📒 Files selected for processing (8)
  • src/vertex/app/(authenticated)/admin/shipping/[batchId]/page.tsx
  • src/vertex/components/features/devices/bulk-edit-device-details-modal.tsx
  • src/vertex/components/features/devices/device-activity-item.tsx
  • src/vertex/components/features/devices/device-measurements-api-card.tsx
  • src/vertex/components/features/devices/orphaned-devices-alert.tsx
  • src/vertex/components/features/shipping/PrepareShippingModal.tsx
  • src/vertex/core/hooks/useClipboard.ts
  • src/vertex/core/hooks/useDevices.ts

Comment thread src/vertex/core/hooks/useDevices.ts
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure docs changes available for preview here

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

@BwanikaRobert

Copy link
Copy Markdown
Contributor Author

@copilot review

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure docs changes available for preview here

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@Codebmk

Codebmk commented Jun 4, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Codebmk Codebmk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

kindly update changelog accordingly. @BwanikaRobert

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

New azure docs changes available for preview here

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

New azure analytics_platform 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: 2

🤖 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/vertex/components/features/grids/grid-details-card.tsx`:
- Around line 18-23: The hook call order error is caused by calling useClipboard
after an early return when loading is true; always call hooks unconditionally.
Move the useClipboard call (const { handleCopy } = useClipboard(...)) to the top
of the GridDetailsCard component (before checking the loading flag) so that
useClipboard is invoked on every render, then keep the early return UI for
loading unchanged.

In `@src/vertex/components/features/grids/grid-measurements-api-card.tsx`:
- Around line 16-21: The hook useClipboard is conditionally skipped when the
component returns early for loading; move the call to useClipboard (the const {
handleCopy } = useClipboard({...}) line) so it executes unconditionally before
the if (loading) return branch to preserve hook order across renders and then
keep the existing early return that renders the Loader2 Card when loading is
true.
🪄 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: 9414b08b-f7cd-4e5a-ada6-1dcac660d55f

📥 Commits

Reviewing files that changed from the base of the PR and between 55641b4 and 56068c4.

📒 Files selected for processing (8)
  • src/vertex/app/changelog.md
  • src/vertex/components/features/cohorts/cohort-measurements-api-card.tsx
  • src/vertex/components/features/devices/device-activity-item.tsx
  • src/vertex/components/features/grids/admin-levels-modal.tsx
  • src/vertex/components/features/grids/grid-details-card.tsx
  • src/vertex/components/features/grids/grid-measurements-api-card.tsx
  • src/vertex/core/hooks/useClipboard.ts
  • src/vertex/core/hooks/useDevices.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/vertex/core/hooks/useDevices.ts

Comment thread src/vertex/components/features/grids/grid-details-card.tsx Outdated
Comment thread src/vertex/components/features/grids/grid-measurements-api-card.tsx Outdated
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

New azure docs changes available for preview here

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

@Codebmk Codebmk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Amazing, thanks @BwanikaRobert

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.

[Vertex: Migration] Refactor useDevices hook mutations to support InfoBanner system

3 participants