Skip to content

Sciweave marketing export#5

Merged
kadamidev merged 1 commit into
developfrom
sciweave-marketing-export
Jan 29, 2026
Merged

Sciweave marketing export#5
kadamidev merged 1 commit into
developfrom
sciweave-marketing-export

Conversation

@kadamidev

@kadamidev kadamidev commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features
    • Added export functionality for Sciweave marketing email data with support for CSV and Excel formats (.xlsx, .xls) via a new dropdown menu in the data table toolbar.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a new API endpoint for exporting Sciweave marketing consent data with configurable format support and implements a corresponding UI export feature in the users datatable toolbar that allows exporting Sciweave marketing emails in CSV, XLS, or XLSX formats with error handling and user feedback.

Changes

Cohort / File(s) Summary
API Endpoint Implementation
src/app/api/export-sciweave-marketing-consent/route.ts
New GET endpoint that proxies export requests to upstream NODES_API_URL with configurable format parameter (default "csv"), forwards credentials and cookies, and handles errors with JSON error responses.
UI Export Feature
src/components/organisms/users-datatable/data-table-toolbar.tsx
Adds Sciweave marketing email export functionality with support for CSV, XLS, and XLSX formats. Introduces export state variables, handler for API calls with blob-based downloads, dropdown menu UI group, loading states, and toast notifications for success/error feedback.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as Data Table Toolbar
    participant API as API Route Handler
    participant Upstream as NODES_API_URL
    participant Browser as Browser Download

    User->>UI: Click "Export Sciweave<br/>Marketing Emails" (format)
    UI->>UI: Set loading state
    UI->>API: GET /api/export-sciweave-marketing-consent<br/>?format={format}
    API->>Upstream: Forward request with credentials
    alt Successful Export
        Upstream-->>API: Export data (blob)
        API-->>UI: Return response
        UI->>Browser: Trigger blob download
        Browser-->>User: Download file
        UI->>UI: Show success toast
    else Error Occurs
        Upstream-->>API: Error response
        API->>API: Log error
        API-->>UI: 500 with error JSON
        UI->>UI: Show error toast
    end
    UI->>UI: Clear loading state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop, hop, hooray! The exports now flow,
Sciweave emails bundled in CSV show,
With Excel in formats both sharp and so clear,
The data downloads, no errors to fear! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
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.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Sciweave marketing export' directly and accurately describes the main feature added: a new export functionality for Sciweave marketing emails in multiple formats (CSV, XLS, XLSX).

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

✨ 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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/app/api/export-sciweave-marketing-consent/route.ts`:
- Around line 19-21: The catch block returns the raw error object (err) which
serializes inconsistently; change it to return a stable payload with a message
string by extracting err.message (or using String(err) if undefined) and pass
NextResponse.json({ message: message }, { status: 500 }); keep
console.error/console.error(err) or console.error(err.stack) for server logs but
do not return the raw err object; update the catch in route.ts (the catch
handling around NextResponse.json) accordingly.
- Around line 7-10: The code reads the format query via
request.nextUrl.searchParams.get("format") and forwards it to the upstream fetch
without validation; add a whitelist (e.g., allow only "csv" and "json") and if
the provided format is missing or not one of the allowed values return a 400
response immediately with a clear error message, otherwise continue using the
validated format when building the fetch URL to
`${NODES_API_URL}/v1/admin/users/export-sciweave-marketing-consent?format=${format}`;
update the handler around the format variable (where
request.nextUrl.searchParams.get is called) to perform this check and
short-circuit invalid requests.

Comment on lines +7 to +10
const format = request.nextUrl.searchParams.get("format") || "csv";
const response = await fetch(
`${NODES_API_URL}/v1/admin/users/export-sciweave-marketing-consent?format=${format}`,
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Validate the format query and reject unsupported values.

Whitelisting avoids unexpected formats reaching the upstream export and returns a clear 400 to callers.

🛠️ Suggested fix
-    const format = request.nextUrl.searchParams.get("format") || "csv";
+    const formatParam = request.nextUrl.searchParams.get("format") ?? "csv";
+    if (!["csv", "xls", "xlsx"].includes(formatParam)) {
+      return NextResponse.json(
+        { message: "Invalid format. Use csv, xls, or xlsx." },
+        { status: 400 }
+      );
+    }
+    const format = formatParam;
📝 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
const format = request.nextUrl.searchParams.get("format") || "csv";
const response = await fetch(
`${NODES_API_URL}/v1/admin/users/export-sciweave-marketing-consent?format=${format}`,
{
const formatParam = request.nextUrl.searchParams.get("format") ?? "csv";
if (!["csv", "xls", "xlsx"].includes(formatParam)) {
return NextResponse.json(
{ message: "Invalid format. Use csv, xls, or xlsx." },
{ status: 400 }
);
}
const format = formatParam;
const response = await fetch(
`${NODES_API_URL}/v1/admin/users/export-sciweave-marketing-consent?format=${format}`,
{
🤖 Prompt for AI Agents
In `@src/app/api/export-sciweave-marketing-consent/route.ts` around lines 7 - 10,
The code reads the format query via request.nextUrl.searchParams.get("format")
and forwards it to the upstream fetch without validation; add a whitelist (e.g.,
allow only "csv" and "json") and if the provided format is missing or not one of
the allowed values return a 400 response immediately with a clear error message,
otherwise continue using the validated format when building the fetch URL to
`${NODES_API_URL}/v1/admin/users/export-sciweave-marketing-consent?format=${format}`;
update the handler around the format variable (where
request.nextUrl.searchParams.get is called) to perform this check and
short-circuit invalid requests.

Comment on lines +19 to +21
} catch (err) {
console.error(err);
return NextResponse.json({ error: err }, { status: 500 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Return a stable error payload (message) instead of the raw error object.

The client expects a message; returning the raw error can serialize poorly and exposes inconsistent shapes.

🛠️ Suggested fix
   } catch (err) {
     console.error(err);
-    return NextResponse.json({ error: err }, { status: 500 });
+    const message =
+      err instanceof Error
+        ? err.message
+        : "Failed to export Sciweave marketing consent data";
+    return NextResponse.json({ message }, { status: 500 });
   }
📝 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
} catch (err) {
console.error(err);
return NextResponse.json({ error: err }, { status: 500 });
} catch (err) {
console.error(err);
const message =
err instanceof Error
? err.message
: "Failed to export Sciweave marketing consent data";
return NextResponse.json({ message }, { status: 500 });
}
🤖 Prompt for AI Agents
In `@src/app/api/export-sciweave-marketing-consent/route.ts` around lines 19 - 21,
The catch block returns the raw error object (err) which serializes
inconsistently; change it to return a stable payload with a message string by
extracting err.message (or using String(err) if undefined) and pass
NextResponse.json({ message: message }, { status: 500 }); keep
console.error/console.error(err) or console.error(err.stack) for server logs but
do not return the raw err object; update the catch in route.ts (the catch
handling around NextResponse.json) accordingly.

@kadamidev kadamidev merged commit a12dba0 into develop Jan 29, 2026
2 of 3 checks passed
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