From fc8e85ba37b4cd6c1e74c9e0ffbb400857597e96 Mon Sep 17 00:00:00 2001 From: ryanmio Date: Sat, 17 Feb 2024 15:51:40 -0500 Subject: [PATCH] Add date validation logic and description max length, fixes #238 fixes #238 --- src/App.css | 14 +++++++++++++- src/components/Dashboard.js | 3 ++- src/components/EditPumpkin.js | 23 ++++++++++++++++++++++- src/components/PumpkinDetail.js | 2 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/App.css b/src/App.css index bffe0142..e518a81d 100644 --- a/src/App.css +++ b/src/App.css @@ -325,4 +325,16 @@ a, .link { height: 100%; z-index: 9999; background: var(--color-background); -} \ No newline at end of file +} + + +.description-text { + white-space: pre-wrap; /* Allows text to wrap and preserves whitespace */ + word-wrap: break-word; /* Breaks long words if necessary to fit within the container */ + overflow-wrap: break-word; /* Similar to word-wrap, ensures the text breaks to prevent overflow */ + max-width: 100%; /* Ensures the text does not exceed the width of its container */ + margin-bottom: 1em; /* Adjust as needed for your design */ + line-height: 1.5; /* Adjust as needed for your design */ +} + + \ No newline at end of file diff --git a/src/components/Dashboard.js b/src/components/Dashboard.js index ddded792..3ca70651 100644 --- a/src/components/Dashboard.js +++ b/src/components/Dashboard.js @@ -159,7 +159,7 @@ return (

navigate(`/pumpkin/${pumpkin.id}`)}>{pumpkin.name}

-

{pumpkin.description}

+

{pumpkin.description}

{pumpkin.latestMeasurement &&

Latest Weight: {pumpkin.latestMeasurement.estimatedWeight} lbs

} {pumpkin.pollinated && pumpkin.weighOff &&

Days After Pollination: {daysSincePollination(pumpkin.pollinated, pumpkin.weighOff)} days

}
@@ -207,3 +207,4 @@ return ( } export default Dashboard; + diff --git a/src/components/EditPumpkin.js b/src/components/EditPumpkin.js index b1c59259..e1a18528 100644 --- a/src/components/EditPumpkin.js +++ b/src/components/EditPumpkin.js @@ -39,6 +39,27 @@ function EditPumpkin() { e.preventDefault(); if (auth.currentUser) { try { + // Validate dates + const seedStartedDate = new Date(pumpkin.seedStarted); + const transplantOutDate = new Date(pumpkin.transplantOut); + const pollinatedDate = pumpkin.pollinated ? new Date(pumpkin.pollinated) : null; + const weighOffDate = pumpkin.weighOff ? new Date(pumpkin.weighOff) : null; + + if (transplantOutDate < seedStartedDate) { + toast.error("Transplant out date cannot be earlier than seed started date."); + return; // Stop the form submission + } + + if (pollinatedDate && transplantOutDate > pollinatedDate) { + toast.error("Pollinated date cannot be earlier than transplant out date."); + return; // Stop the form submission + } + + if (weighOffDate && pollinatedDate && weighOffDate < pollinatedDate) { + toast.error("Weigh off date cannot be earlier than pollinated date."); + return; // Stop the form submission + } + // Extract year from the earliest date available const dates = [pumpkin.seedStarted, pumpkin.transplantOut, pumpkin.pollinated, pumpkin.weighOff].filter(Boolean); const earliestDate = dates.sort()[0]; @@ -73,7 +94,7 @@ function EditPumpkin() {
-