Skip to content

Nathan/donor offer bugs - #341

Merged
ND68 merged 2 commits into
mainfrom
Nathan/donor-offer-bugs
Apr 14, 2026
Merged

ND68 merged 2 commits into
mainfrom
Nathan/donor-offer-bugs

Conversation

@ND68

@ND68 ND68 commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Description

Resolves ticket number: #327 & #330

Explain what your code changes: Removed create donor offer button from finalized and archived tabs. Added date validation create donor offer screen.

List the steps you took to test your code: Visually confirmed and tested invalid dates.

Checklist

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

@ND68 ND68 linked an issue Apr 14, 2026 that may be closed by this pull request
@netlify

netlify Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hope-for-haiti ready!

Name Link
🔨 Latest commit 9ef185c
🔍 Latest deploy log https://app.netlify.com/projects/hope-for-haiti/deploys/69dda4690a2fa30008dafb66
😎 Deploy Preview https://deploy-preview-341--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.

@ND68 ND68 linked an issue Apr 14, 2026 that may be closed by this pull request
@greptile-apps

greptile-apps Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two bugs: it hides the "Create Donor Offer" button on the Finalized and Archived tabs, and adds client-side validation to prevent past deadlines when creating a donor offer.

  • Date validation bypass (P1): The new past-date checks live only in validateBeforeUpload, which fires on file selection. After the file is uploaded, both date inputs remain editable and neither showPreview nor handleSubmit re-validates them, so a user can upload with valid dates, change them to past dates, and still create the offer.

Confidence Score: 4/5

Safe to merge after fixing the date-validation bypass in handleSubmit; the tab-button fix is correct as-is.

One P1 finding: the new date validation is applied only at file-upload time and can be trivially bypassed by editing dates afterward, defeating the stated goal of the PR. The tab-button change is clean and correct.

src/app/donorOffers/create/page.tsx — handleSubmit needs the same date guard that was added to validateBeforeUpload.

Important Files Changed

Filename Overview
src/app/donorOffers/create/page.tsx Adds date-in-the-past validation inside validateBeforeUpload (file-select callback only); handleSubmit and showPreview do not re-validate, so changed dates after a successful upload bypass the new guard entirely.
src/screens/DonorOffersScreens/AdminDonorOffersScreen.tsx Correctly hides the "Create Donor Offer" button on Finalized and Archived tabs by adding the activeTab === StatusFilterKey.UNFINALIZED guard.

Sequence Diagram

sequenceDiagram
    actor User
    participant Form as CreateDonorOfferPage
    participant Upload as useFileUpload
    participant API as /api/donorOffers

    User->>Form: Fill in offerName, donorName, deadlines
    User->>Form: Select file
    Form->>Upload: handleFileChange()
    Upload->>Upload: validateBeforeUpload() ✅ date check here
    alt Validation fails (past date)
        Upload-->>Form: Return errors
        Form-->>User: Show error messages
    else Validation passes
        Upload->>API: POST /api/donorOffers?preview=true
        API-->>Upload: Preview data
        Upload-->>Form: fileUploaded = true
    end
    Note over User,Form: ⚠️ User can now freely edit date fields
    User->>Form: Optionally change dates to past
    User->>Form: Click Preview Offer
    Form->>Form: showPreview() — no date re-validation
    Form-->>User: Show preview table
    User->>Form: Click Create Offer
    Form->>Form: handleSubmit() — no date validation ❌
    Form->>API: POST /api/donorOffers (possibly with past dates)
    API-->>Form: Success/Error
Loading

Comments Outside Diff (1)

  1. src/app/donorOffers/create/page.tsx, line 126-150 (link)

    P1 Date validation can be bypassed after file upload

    validateBeforeUpload runs only when the file is selected. After a file is successfully uploaded with valid future dates, the user can freely edit the date inputs and then click Preview Offer → Create Offer without those changed dates ever being re-checked. showPreview only guards on fileUploaded/fileErrorMessage, and handleSubmit contains no date validation at all, so a past-date offer can be submitted despite the new guards.

Reviews (1): Last reviewed commit: "date validatino on donor offers" | Re-trigger Greptile

Comment on lines +41 to +48
const getTodayDateString = () => {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

return `${year}-${month}-${day}`;
};

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.

P2 getTodayDateString should be a module-level utility

This function doesn't close over any component state or props, so defining it inside the component creates a new function reference on every render. Move it outside the component (or to a shared utility file).

Suggested change
const getTodayDateString = () => {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
};
const getTodayDateString = () => {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
};
export default function CreateDonorOfferPage() {

@ND68
ND68 merged commit 0ea1df7 into main Apr 14, 2026
5 checks passed
@ND68
ND68 deleted the Nathan/donor-offer-bugs branch April 14, 2026 02:25
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.

Date Validation on Donor Offers Misleading Create Offer Button

1 participant