Skip to content

Tiffany/308 parse unfinalized donor offer - #316

Merged
ND68 merged 3 commits into
mainfrom
tiffany/308-parse-unfinalized-donor-offer-clean
Mar 31, 2026
Merged

ND68 merged 3 commits into
mainfrom
tiffany/308-parse-unfinalized-donor-offer-clean

Conversation

@tifpham021

@tifpham021 tifpham021 commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Resolves ticket number: #308

Explain what your code changes:Admin is now able to turn unfinalized donor offers into csv files. Also when the partner's request in quantity amount is different from the initial quantity, the UI reflects the new quantity and crosses out the old one.

List the steps you took to test your code:

  • made sure that 'Convert to CSV' button is there
  • checked to see that data actually turns into a csv file when clicked on
  • tested out with data to see whether the UI worked when initial quantity and partner requested quantity are the same
  • tested out with data to see whether the UI worked when initial quantity and partner requested quantity are different
  • made sure that change was reflected in Prisma Studio and in the csv file

Before
571033435-3323744d-f544-4273-ab06-31b71d3004e7
csv-test-offer-requests.csv

After
571033545-2067160f-8ded-45e6-b829-191145ff8f7b
csv-test-offer-requests (1).csv

Checklist

  • The ticket is mentioned above
  • The changes fulfill the success criteria of the ticket
  • The changes were self-reviewed
  • A review was requested

@netlify

netlify Bot commented Mar 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hope-for-haiti ready!

Name Link
🔨 Latest commit cb25f08
🔍 Latest deploy log https://app.netlify.com/projects/hope-for-haiti/deploys/69c99c6a1472520008e69136
😎 Deploy Preview https://deploy-preview-316--hope-for-haiti.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tifpham021 tifpham021 changed the title able to turn unfinalized donor offers into csv files now and also imp… able to turn unfinalized donor offers into csv files now and also implemented strike through ui Mar 29, 2026
@greptile-apps

greptile-apps Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds CSV export support for unfinalized donor offers, allowing admins to download a spreadsheet of partner requests directly from the donor offers table. The strikethrough UI for revised quantities described in the PR description appears to already be implemented in the pre-existing Chip component and was not modified here.

Key changes:

  • New GET /api/donorOffers/[donorOfferId]/csv route that validates auth, permissions, and offer state before generating a BOM-prefixed CSV via PapaParse
  • getUnfinalizedDonorOfferCsv service method builds per-partner columns using a finalQuantity ?? quantity fallback, which correctly reflects unfinalized request quantities
  • handleConvertToCsv in AdminDonorOffersScreen uses fetch + Blob URL pattern (addressing the previous review thread's suggestion), with loading/success/error toasts
  • A console.error statement was left in the catch block of handleConvertToCsv — this should be removed per the project checklist
  • Partner names are used directly as CSV column keys; if two partners share a name, one column will silently overwrite the other in the row object

Checklist areas needing improvement:

  • No console.logs: console.error(\"CSV download error:\", error) on line 135 of AdminDonorOffersScreen.tsx should be removed since the error is already surfaced via toast

Confidence Score: 5/5

Safe to merge — all remaining findings are P2 style/edge-case suggestions that do not block the primary user path.

Both open findings are P2: a leftover console.error (easy cleanup) and a theoretical partner-name collision (unlikely in practice). The previously raised P1 concerns about per-partner column values and Request Total mismatch have been correctly addressed in this revision.

src/screens/DonorOffersScreens/AdminDonorOffersScreen.tsx (console.error cleanup), src/services/donorOfferService.ts (partner name collision edge case)

Important Files Changed

Filename Overview
src/app/api/donorOffers/[donorOfferId]/csv/route.ts New GET endpoint that streams a CSV file for an unfinalized donor offer; auth, permission, and input validation are all correctly handled.
src/screens/DonorOffersScreens/AdminDonorOffersScreen.tsx Adds "Convert to CSV" menu item for unfinalized offers with proper fetch-based download, loading toast, and error handling; minor issue: leftover console.error in the catch block.
src/services/donorOfferService.ts Adds getUnfinalizedDonorOfferCsv that correctly builds a BOM-prefixed CSV with per-partner columns using finalQuantity ?? quantity fallback; minor risk of column collision if two partners share the same name.

Sequence Diagram

sequenceDiagram
    participant Admin
    participant AdminDonorOffersScreen
    participant CSVRoute as GET /api/donorOffers/[id]/csv
    participant DonorOfferService

    Admin->>AdminDonorOffersScreen: Click "Convert to CSV"
    AdminDonorOffersScreen->>AdminDonorOffersScreen: toast.loading("Generating CSV...")
    AdminDonorOffersScreen->>CSVRoute: fetch(/api/donorOffers/{id}/csv)
    CSVRoute->>CSVRoute: auth() + checkPermission("offerWrite")
    CSVRoute->>DonorOfferService: getUnfinalizedDonorOfferCsv(donorOfferId)
    DonorOfferService->>DonorOfferService: getAdminDonorOfferDetails(id, true)
    DonorOfferService->>DonorOfferService: Validate state === UNFINALIZED
    DonorOfferService->>DonorOfferService: Build partnerMap from visibilities + requests
    DonorOfferService->>DonorOfferService: Papa.unparse(rows, { columns })
    DonorOfferService-->>CSVRoute: { csv, fileName }
    CSVRoute-->>AdminDonorOffersScreen: 200 text/csv + Content-Disposition
    AdminDonorOffersScreen->>AdminDonorOffersScreen: Blob URL → programmatic anchor click
    AdminDonorOffersScreen->>Admin: File download initiated
    AdminDonorOffersScreen->>AdminDonorOffersScreen: toast.success("CSV downloaded")
Loading

Reviews (2): Last reviewed commit: "fix donor offer csv export issues" | Re-trigger Greptile

Comment thread src/services/donorOfferService.ts Outdated
Comment thread src/services/donorOfferService.ts
Comment thread src/screens/DonorOffersScreens/AdminDonorOffersScreen.tsx Outdated
@tifpham021

Copy link
Copy Markdown
Contributor Author

@greptileai

@tifpham021 tifpham021 changed the title able to turn unfinalized donor offers into csv files now and also implemented strike through ui Tiffany/308 Mar 29, 2026
@tifpham021 tifpham021 changed the title Tiffany/308 Tiffany/308 parse unfinalized donor offer Mar 29, 2026
@ND68 ND68 linked an issue Mar 30, 2026 that may be closed by this pull request

@ND68 ND68 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.

feature works perfectly, great work

@ND68
ND68 merged commit de70c31 into main Mar 31, 2026
5 checks passed
@ND68
ND68 deleted the tiffany/308-parse-unfinalized-donor-offer-clean branch March 31, 2026 21:54
@ND68 ND68 mentioned this pull request Apr 1, 2026
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.

Parse Unfinalized Donor Offer

2 participants