diff --git a/backend/app.py b/backend/app.py
index eb4d4ac..2b34ea2 100644
--- a/backend/app.py
+++ b/backend/app.py
@@ -85,9 +85,9 @@ def api_dashboard():
None
Returns:
- JSON: user information provided by CAS, all the rides, and
- a mapping of available and upcoming rideshares, sorted by
- upcoming date
+ JSON: user information provided by CAS, all upcoming rideshares
+ (including full ones), sorted by upcoming date, and a mapping
+ of the user's ride request statuses
"""
user_info = _cas.authenticate()
@@ -112,12 +112,12 @@ def api_dashboard():
"updated_at": ride[9],
"current_riders": ride[10],
"note": ride[11],
+ "departure_start": ride[12],
+ "departure_end": ride[13],
}
- if (
- updated_ride["arrival_time"] > current_time
- and len(updated_ride["current_riders"]) < updated_ride["max_capacity"]
- ):
+ # full rides are included too; Home shows them with a "Full" button
+ if updated_ride["arrival_time"] > current_time:
updated_rides.append(updated_ride)
updated_rides.sort(key=lambda ride: ride["arrival_time"])
@@ -170,6 +170,8 @@ def get_my_rides():
"current_riders": ride[11],
"requested_riders": ride[12],
"phone_number": ride[13],
+ "departure_start": ride[14],
+ "departure_end": ride[15],
}
if updated_ride["arrival_time"] > current_time:
@@ -197,6 +199,8 @@ def get_my_rides():
"request_status": ride[12],
# only accepted riders get the poster's phone number
"phone_number": ride[13] if ride[12] == "accepted" else None,
+ "departure_start": ride[14],
+ "departure_end": ride[15],
}
if updated_ride["arrival_time"] > current_time:
@@ -236,9 +240,11 @@ def addride():
arrival_time: a datetime object with the arrival date & time
phone_number: the poster's US phone number, shown to accepted riders
note (optional): note with the rideshare
+ departure_start, departure_end (optional): ISO times for the window
+ the ride leaves in; both or neither, ending by the arrival time
Returns:
- JSON: a success message
+ JSON: a success message and the new ride's ride_id
400: if the phone number or note is invalid, or unable to create rideshare
"""
user_info = _cas.authenticate()
@@ -283,11 +289,21 @@ def addride():
arrival_time = data.get("arrival_time")
+ departure_start, departure_end, window_error = parse_departure_window(
+ data.get("departure_start"), data.get("departure_end"), arrival_time
+ )
+ if window_error:
+ return jsonify({"success": False, "message": window_error}), 400
+
origin_json = Json(origin)
dest_json = Json(dest)
+ failed = (
+ jsonify({"success": False, "message": "Failed to create rideshare."}),
+ 400,
+ )
try:
- database.create_ride(
+ ride_id = database.create_ride(
user_info["netid"],
user_info["displayname"],
user_info["mail"],
@@ -297,13 +313,63 @@ def addride():
arrival_time,
note,
phone_number,
+ departure_start,
+ departure_end,
)
- return jsonify({"success": True, "message": "Rideshare successfully created!"})
- except:
- return (
- jsonify({"success": False, "message": "Failed to create rideshare."}),
- 400,
- )
+ except Exception:
+ return failed
+ if ride_id is None:
+ return failed
+ return jsonify(
+ {
+ "success": True,
+ "message": "Rideshare successfully created!",
+ "ride_id": ride_id,
+ }
+ )
+
+
+def parse_iso_time(value):
+ """
+ Parses an ISO 8601 time like "2026-11-20T21:00:00.000Z" into a UTC
+ datetime, or returns None if it's missing or invalid.
+ """
+ if not isinstance(value, str) or not value:
+ return None
+ try:
+ parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
+ except ValueError:
+ return None
+ if parsed.tzinfo is None:
+ parsed = parsed.replace(tzinfo=timezone.utc)
+ return parsed.astimezone(timezone.utc)
+
+
+def parse_departure_window(start, end, arrival_time):
+ """
+ Checks an optional departure window. Both ends or neither must be set;
+ the window must start before it ends, end by the arrival time, and not
+ be over already.
+
+ Returns:
+ (start, end, error): ISO strings to store (or None, None), and an
+ error message if the window is invalid
+ """
+ if not start and not end:
+ return None, None, None
+
+ start_time = parse_iso_time(start)
+ end_time = parse_iso_time(end)
+ if not start_time or not end_time:
+ return None, None, "Please give both a start and end for the departure window."
+ if start_time >= end_time:
+ return None, None, "The departure window must start before it ends."
+ arrival = parse_iso_time(arrival_time)
+ if arrival and end_time > arrival:
+ return None, None, "The departure window must end by the arrival time."
+ if end_time <= datetime.now(timezone.utc):
+ return None, None, "The departure window can't be in the past."
+ return start, end, None
def normalize_phone_number(phone_number):
@@ -494,6 +560,8 @@ def searchrides():
"updated_at": ride[9],
"current_riders": ride[10],
"note": ride[11],
+ "departure_start": ride[12],
+ "departure_end": ride[13],
}
if (
diff --git a/backend/database.py b/backend/database.py
index 540a171..133fc50 100644
--- a/backend/database.py
+++ b/backend/database.py
@@ -148,17 +148,25 @@ def create_ride(
arrival_time,
note="",
phone_number=None,
+ departure_start=None,
+ departure_end=None,
):
"""
- Adds a ride to the Rides database
+ Adds a ride to the Rides database. departure_start / departure_end are
+ an optional window for when the ride leaves.
+
+ Returns:
+ int: the new ride's id, or None if the ride could not be added
"""
current_riders = []
sql_command = f"""
INSERT INTO Rides (admin_netid, admin_name, admin_email, max_capacity, current_riders,
- origin_dict, destination_dict, arrival_time, note, phone_number, updated_at) VALUES (%s, %s, %s, %s,
- %s, %s, %s, %s, %s, %s, CURRENT_TIMESTAMP);
+ origin_dict, destination_dict, arrival_time, note, phone_number, departure_start,
+ departure_end, updated_at) VALUES (%s, %s, %s, %s,
+ %s, %s, %s, %s, %s, %s, %s, %s, CURRENT_TIMESTAMP)
+ RETURNING id;
"""
values = (
@@ -172,8 +180,11 @@ def create_ride(
arrival_time,
note,
phone_number,
+ departure_start,
+ departure_end,
)
+ ride_id = None
conn = connect()
# if it was successful connection, execute SQL commands to database & commit
@@ -181,15 +192,19 @@ def create_ride(
try:
with conn.cursor() as cursor:
cursor.execute(sql_command, values)
+ ride_id = cursor.fetchone()[0]
conn.commit()
print("Ride addded successfully!")
except Exception as e:
+ ride_id = None
print(f"Error adding ride: {e}")
finally:
conn.close()
else:
print("Connection not established.")
+ return ride_id
+
def delete_ride(netid, ride_id):
"""
@@ -441,7 +456,9 @@ def get_users_rides(netid):
ELSE ARRAY[RideRequests.netid, RideRequests.full_name, RideRequests.mail, RideRequests.note]
END
) FILTER (WHERE RideRequests.netid IS NOT NULL), ARRAY[]::text[][]) AS riderequesters,
- Rides.phone_number
+ Rides.phone_number,
+ Rides.departure_start,
+ Rides.departure_end
FROM
Rides
LEFT JOIN
@@ -461,7 +478,9 @@ def get_users_rides(netid):
Rides.updated_at,
Rides.note,
Rides.current_riders,
- Rides.phone_number;
+ Rides.phone_number,
+ Rides.departure_start,
+ Rides.departure_end;
"""
values = (str(netid),)
@@ -488,7 +507,8 @@ def get_all_rides():
sql_command = """
SELECT id, admin_netid, admin_name, admin_email, max_capacity, origin_dict,
- destination_dict, arrival_time, creation_time, updated_at, current_riders, note FROM Rides
+ destination_dict, arrival_time, creation_time, updated_at, current_riders, note,
+ departure_start, departure_end FROM Rides
"""
conn = connect()
@@ -516,7 +536,8 @@ def search_rides(
):
query = """
SELECT id, admin_netid, admin_name, admin_email, max_capacity, origin_dict,
- destination_dict, arrival_time, creation_time, updated_at, current_riders, note FROM Rides
+ destination_dict, arrival_time, creation_time, updated_at, current_riders, note,
+ departure_start, departure_end FROM Rides
WHERE 1=1
"""
@@ -572,7 +593,8 @@ def get_users_requested_rides(netid):
sql_command = """
SELECT Rides.id, admin_netid, admin_name, admin_email, max_capacity, origin_dict, destination_dict,
arrival_time, creation_time, updated_at, Rides.note,
- current_riders, RideRequests.status as ride_request_status, Rides.phone_number
+ current_riders, RideRequests.status as ride_request_status, Rides.phone_number,
+ Rides.departure_start, Rides.departure_end
FROM Rides
JOIN RideRequests ON Rides.id = RideRequests.ride_id
WHERE RideRequests.netid = %s;
diff --git a/backend/migrations/002_ride_departure_window.sql b/backend/migrations/002_ride_departure_window.sql
new file mode 100644
index 0000000..26ce83f
--- /dev/null
+++ b/backend/migrations/002_ride_departure_window.sql
@@ -0,0 +1,6 @@
+-- Adds an optional departure window to rides ("leave between 4:00 and
+-- 5:30PM"). Both columns are nullable, so existing rides without a window
+-- still load.
+
+ALTER TABLE Rides ADD COLUMN IF NOT EXISTS departure_start TIMESTAMP;
+ALTER TABLE Rides ADD COLUMN IF NOT EXISTS departure_end TIMESTAMP;
diff --git a/backend/schema.sql b/backend/schema.sql
index bb4fd7f..3bf23df 100644
--- a/backend/schema.sql
+++ b/backend/schema.sql
@@ -11,7 +11,9 @@ CREATE TABLE Rides (
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
current_riders TEXT[][],
note VARCHAR(300),
- phone_number VARCHAR(20)
+ phone_number VARCHAR(20),
+ departure_start TIMESTAMP,
+ departure_end TIMESTAMP
);
CREATE TABLE IF NOT EXISTS RideRequests (
diff --git a/backend/tests/test_add_ride.py b/backend/tests/test_add_ride.py
new file mode 100644
index 0000000..351e5a4
--- /dev/null
+++ b/backend/tests/test_add_ride.py
@@ -0,0 +1,75 @@
+"""
+Tests for posting a ride: /api/addride returns the new ride's id, rejects
+invalid input without creating a ride, and both posted and requested rides
+show up under the user's /api/myrides.
+"""
+
+from datetime import datetime, timedelta, timezone
+
+
+def place(name):
+ return {
+ "formatted_address": "1 Main St, Princeton, NJ 08540, USA",
+ "name": name,
+ "place_id": "place-" + name,
+ }
+
+
+def ride_body(**overrides):
+ body = {
+ "capacity": 3,
+ "origin": place("Frist"),
+ "destination": place("PHL"),
+ "arrival_time": (datetime.now(timezone.utc) + timedelta(days=2)).isoformat(),
+ "note": "Meet at the front steps",
+ "phone_number": "(609) 555-1234",
+ }
+ body.update(overrides)
+ return body
+
+
+def test_addride_returns_new_ride_id(api):
+ response = api.as_user("poster").post("/api/addride", json=ride_body())
+
+ assert response.status_code == 200
+ data = response.get_json()
+ assert data["success"] is True
+ assert isinstance(data["ride_id"], int)
+
+ my_rides = api.as_user("poster").get("/api/myrides").get_json()
+ posted_ids = [ride["id"] for ride in my_rides["upcoming_posted_rides"]]
+ assert data["ride_id"] in posted_ids
+
+
+def test_addride_rejects_invalid_phone(api):
+ response = api.as_user("poster").post(
+ "/api/addride", json=ride_body(phone_number="123")
+ )
+
+ assert response.status_code == 400
+ data = response.get_json()
+ assert data["success"] is False
+ assert "ride_id" not in data
+
+ my_rides = api.as_user("poster").get("/api/myrides").get_json()
+ assert my_rides["upcoming_posted_rides"] == []
+
+
+def test_requested_ride_shows_under_my_rides(api, ride_id):
+ api.as_user("rider").post(
+ "/api/requestride",
+ json={
+ "rideid": ride_id,
+ "origin_name": "Frist",
+ "destination_name": "EWR",
+ "formatted_arrival_time": "soon",
+ "note": "",
+ },
+ )
+
+ my_rides = api.as_user("rider").get("/api/myrides").get_json()
+ requested = [
+ ride for ride in my_rides["upcoming_requested_rides"] if ride["id"] == ride_id
+ ]
+ assert len(requested) == 1
+ assert requested[0]["request_status"] == "pending"
diff --git a/backend/tests/test_departure_window.py b/backend/tests/test_departure_window.py
new file mode 100644
index 0000000..7a62479
--- /dev/null
+++ b/backend/tests/test_departure_window.py
@@ -0,0 +1,109 @@
+"""
+Tests for a ride's optional departure window ("leave between 4:00 and
+5:30PM"), set when creating a ride.
+"""
+
+from datetime import datetime, timedelta, timezone
+
+import pytest
+
+
+def iso(dt):
+ return dt.isoformat().replace("+00:00", "Z")
+
+
+def create_ride(api, **extra):
+ place = lambda name: {
+ "formatted_address": "1 Main St, Princeton, NJ 08540, USA",
+ "name": name,
+ "place_id": "place-" + name,
+ }
+ return api.as_user("poster").post(
+ "/api/addride",
+ json={
+ "capacity": 2,
+ "origin": place("Frist"),
+ "destination": place("EWR"),
+ "note": "",
+ "phone_number": "6095551234",
+ **extra,
+ },
+ )
+
+
+@pytest.fixture
+def arrival():
+ return (datetime.now(timezone.utc) + timedelta(days=3)).replace(
+ microsecond=0
+ )
+
+
+def test_ride_with_departure_window_is_returned(api, arrival):
+ start, end = arrival - timedelta(hours=2), arrival - timedelta(hours=1)
+
+ response = create_ride(
+ api,
+ arrival_time=iso(arrival),
+ departure_start=iso(start),
+ departure_end=iso(end),
+ )
+
+ assert response.get_json()["success"]
+ for netid, path, key in [
+ ("rider", "/api/dashboard", "rides"),
+ ("poster", "/api/myrides", "upcoming_posted_rides"),
+ ]:
+ ride = api.as_user(netid).get(path).get_json()[key][0]
+ assert parse(ride["departure_start"]) == start
+ assert parse(ride["departure_end"]) == end
+
+
+def test_ride_without_departure_window_still_works(api, arrival):
+ response = create_ride(api, arrival_time=iso(arrival))
+
+ assert response.get_json()["success"]
+ ride = api.as_user("rider").get("/api/dashboard").get_json()["rides"][0]
+ assert ride["departure_start"] is None
+ assert ride["departure_end"] is None
+
+
+@pytest.mark.parametrize(
+ "start_offset, end_offset, message",
+ [
+ (-2, None, "both a start and end"), # only a start
+ (-1, -2, "start before it ends"), # backwards
+ (-2, 1, "end by the arrival time"), # ends after arriving
+ ],
+)
+def test_invalid_departure_window_is_rejected(
+ api, arrival, start_offset, end_offset, message
+):
+ window = {"departure_start": iso(arrival + timedelta(hours=start_offset))}
+ if end_offset is not None:
+ window["departure_end"] = iso(arrival + timedelta(hours=end_offset))
+
+ response = create_ride(api, arrival_time=iso(arrival), **window)
+
+ assert response.status_code == 400
+ assert message in response.get_json()["message"]
+ assert api.as_user("rider").get("/api/dashboard").get_json()["rides"] == []
+
+
+def test_past_departure_window_is_rejected(api):
+ now = datetime.now(timezone.utc)
+ response = create_ride(
+ api,
+ arrival_time=iso(now + timedelta(hours=1)),
+ departure_start=iso(now - timedelta(hours=2)),
+ departure_end=iso(now - timedelta(hours=1)),
+ )
+
+ assert response.status_code == 400
+ assert "past" in response.get_json()["message"]
+
+
+def parse(http_date):
+ """Flask returns datetimes as RFC 1123 strings in UTC."""
+ return datetime.strptime(http_date, "%a, %d %b %Y %H:%M:%S %Z").replace(
+ tzinfo=timezone.utc
+ )
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 94644e1..4ebbb63 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -1,8 +1,10 @@
import { useState, useEffect } from "react";
import { Navigate, Routes, Route } from "react-router-dom";
import { ConfigProvider } from "antd";
-import AllRides from "./pages/AllRides";
+import Home from "./pages/Home";
+import RideDetails from "./pages/RideDetails";
import MyRides from "./pages/MyRides";
+import ScheduleRide from "./pages/ScheduleRide";
import NotFound from "./pages/NotFound";
import Navbar from "./components/Navbar";
import tailwindConfig from "../tailwind.config.js";
@@ -61,8 +63,13 @@ function App() {
} />
- } />
+ } />
+ } />
} />
+ }
+ />
} />
diff --git a/frontend/src/assets/figma/alert-circle.svg b/frontend/src/assets/figma/alert-circle.svg
new file mode 100644
index 0000000..38dc8e0
--- /dev/null
+++ b/frontend/src/assets/figma/alert-circle.svg
@@ -0,0 +1,7 @@
+
diff --git a/frontend/src/assets/figma/arrow-40.svg b/frontend/src/assets/figma/arrow-40.svg
new file mode 100644
index 0000000..e354877
--- /dev/null
+++ b/frontend/src/assets/figma/arrow-40.svg
@@ -0,0 +1,3 @@
+
diff --git a/frontend/src/assets/figma/arrow-left.svg b/frontend/src/assets/figma/arrow-left.svg
new file mode 100644
index 0000000..6c200cf
--- /dev/null
+++ b/frontend/src/assets/figma/arrow-left.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/assets/figma/avatar.svg b/frontend/src/assets/figma/avatar.svg
new file mode 100644
index 0000000..c2f1019
--- /dev/null
+++ b/frontend/src/assets/figma/avatar.svg
@@ -0,0 +1,3 @@
+
diff --git a/frontend/src/assets/figma/car.svg b/frontend/src/assets/figma/car.svg
new file mode 100644
index 0000000..a8a23d6
--- /dev/null
+++ b/frontend/src/assets/figma/car.svg
@@ -0,0 +1,9 @@
+
diff --git a/frontend/src/assets/figma/chevron-down.svg b/frontend/src/assets/figma/chevron-down.svg
new file mode 100644
index 0000000..a0e69f4
--- /dev/null
+++ b/frontend/src/assets/figma/chevron-down.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/assets/figma/menu.svg b/frontend/src/assets/figma/menu.svg
new file mode 100644
index 0000000..76b1c97
--- /dev/null
+++ b/frontend/src/assets/figma/menu.svg
@@ -0,0 +1,7 @@
+
diff --git a/frontend/src/assets/figma/minus.svg b/frontend/src/assets/figma/minus.svg
new file mode 100644
index 0000000..8f437fc
--- /dev/null
+++ b/frontend/src/assets/figma/minus.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/assets/figma/plus.svg b/frontend/src/assets/figma/plus.svg
new file mode 100644
index 0000000..e1c38a7
--- /dev/null
+++ b/frontend/src/assets/figma/plus.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/assets/figma/search.svg b/frontend/src/assets/figma/search.svg
new file mode 100644
index 0000000..b297c27
--- /dev/null
+++ b/frontend/src/assets/figma/search.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/assets/figma/switch.svg b/frontend/src/assets/figma/switch.svg
new file mode 100644
index 0000000..c254cc4
--- /dev/null
+++ b/frontend/src/assets/figma/switch.svg
@@ -0,0 +1,5 @@
+
diff --git a/frontend/src/components/CreateRideModal.jsx b/frontend/src/components/CreateRideModal.jsx
new file mode 100644
index 0000000..558b94d
--- /dev/null
+++ b/frontend/src/components/CreateRideModal.jsx
@@ -0,0 +1,356 @@
+import { useRef, useState } from "react";
+import Autocomplete from "react-google-autocomplete";
+import { Input, TimePicker } from "antd";
+import Modal from "./Modal.jsx";
+import Dropdown from "./Dropdown.jsx";
+import IconButton from "./IconButton.jsx";
+import DateTimePicker from "./DateTimePicker.jsx";
+import CustomTextArea from "./TextArea.jsx";
+import WarningModal from "./WarningModal.jsx";
+import LiftButton from "./lift/LiftButton.jsx";
+import {
+ MAX_CAPACITY,
+ NOTE_MAX_LENGTH,
+ autocompleteStyling,
+ flipFields,
+ normalizePhoneNumber,
+ placeToLocation,
+ renderToAndFrom,
+} from "../utils/utils";
+
+// autocomplete options for location input
+const autocompleteOptions = {
+ fields: ["formatted_address", "geometry", "name", "place_id"],
+ types: ["establishment", "geocode"], // This will show both businesses and addresses
+};
+
+// make capacity dropdown options
+const capacityOptions = Array.from({ length: MAX_CAPACITY }, (_, i) => ({
+ value: i + 1,
+ label: i + 1,
+}));
+
+// "Create a Rideshare" form. Opened from the navbar on any page.
+// onCreated(responseData) is called after the server responds.
+export default function CreateRideModal({ isOpen, onClose, onCreated }) {
+ const google_api_key = import.meta.env.VITE_GOOGLE_API_KEY; // Google API key from environment variables
+
+ const originRef = useRef(null);
+ const destinationRef = useRef(null);
+
+ const [origin, setOrigin] = useState(null);
+ const [capacity, setCapacity] = useState("");
+ const [dest, setDest] = useState(null);
+ const [date, setDate] = useState("");
+ const [time, setTime] = useState("");
+ // optional departure window, on the arrival date
+ const [departStart, setDepartStart] = useState(null);
+ const [departEnd, setDepartEnd] = useState(null);
+ const [rideNote, setRideNote] = useState("");
+ const [phoneNumber, setPhoneNumber] = useState("");
+ const [isCreatingRide, setIsCreatingRide] = useState(false);
+
+ // validation warning, e.g. for a missing field
+ const [validationModal, setValidationModal] = useState(null); // { title, message }
+
+ // Closes the modal and resets the form
+ const handleClose = () => {
+ setCapacity("");
+ setOrigin(null);
+ setDest(null);
+ setDate("");
+ setTime("");
+ setDepartStart(null);
+ setDepartEnd(null);
+ setRideNote("");
+ setPhoneNumber("");
+ originRef.current = null;
+ destinationRef.current = null;
+ onClose();
+ };
+
+ const onChange = (e, setFunction) => {
+ if (!e.target.value) {
+ setFunction(null);
+ }
+ };
+
+ // Checks if all necessary fields are filled in before creating the ride
+ const checkCreateRideParams = () => {
+ let arrivalTime = null;
+ if (date && time) {
+ arrivalTime = new Date(
+ `${date.format("YYYY-MM-DD")}T${time.format("HH:mm:ss")}`
+ );
+ }
+
+ if (arrivalTime && Date.now() >= arrivalTime.getTime()) {
+ setValidationModal({
+ title: "Invalid Input",
+ message: "Cannot enter a date in the past.",
+ });
+ return;
+ }
+
+ if (
+ !capacity ||
+ !origin ||
+ !dest ||
+ !date ||
+ !time ||
+ !phoneNumber.trim() ||
+ !date.isValid() ||
+ !time.isValid()
+ ) {
+ setValidationModal({
+ title: "Missing fields",
+ message: "You must provide all fields to create a ride.",
+ });
+ return;
+ }
+
+ if (!normalizePhoneNumber(phoneNumber)) {
+ setValidationModal({
+ title: "Invalid Input",
+ message: "Please enter a valid 10-digit phone number.",
+ });
+ return;
+ }
+
+ // optional departure window: both times or neither, on the arrival
+ // date, starting before it ends and ending by the arrival time
+ let departureWindow = null;
+ if (departStart || departEnd) {
+ const onArrivalDate = (t) =>
+ new Date(`${date.format("YYYY-MM-DD")}T${t.format("HH:mm:00")}`);
+ const windowError =
+ !departStart || !departEnd
+ ? "Please give both a start and end for the departure window, or leave both empty."
+ : onArrivalDate(departStart) >= onArrivalDate(departEnd)
+ ? "The departure window must start before it ends."
+ : onArrivalDate(departEnd) > arrivalTime
+ ? "The departure window must end by the arrival time."
+ : onArrivalDate(departEnd) <= new Date()
+ ? "The departure window can't be in the past."
+ : null;
+ if (windowError) {
+ setValidationModal({ title: "Invalid Input", message: windowError });
+ return;
+ }
+ departureWindow = {
+ start: onArrivalDate(departStart),
+ end: onArrivalDate(departEnd),
+ };
+ }
+
+ createRide(arrivalTime, departureWindow);
+ };
+
+ // Creates ride by making API call to /addride
+ const createRide = async (arrivalTime, departureWindow) => {
+ setIsCreatingRide(true);
+ let responseData = {
+ success: false,
+ message: "Failed to create rideshare.",
+ };
+ try {
+ const response = await fetch("/api/addride", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ capacity: capacity["label"],
+ origin: origin,
+ destination: dest,
+ arrival_time: arrivalTime.toISOString(),
+ note: rideNote,
+ phone_number: phoneNumber,
+ departure_start: departureWindow?.start.toISOString() ?? null,
+ departure_end: departureWindow?.end.toISOString() ?? null,
+ }),
+ });
+ responseData = await response.json();
+ } catch (error) {
+ console.error("Error during fetch:", error);
+ }
+ setIsCreatingRide(false);
+ if (responseData.success) {
+ handleClose();
+ }
+ onCreated(responseData);
+ };
+
+ return (
+ <>
+ {/* Modal returns early before its hooks when closed, so only mount it
+ while open */}
+ {isOpen && (
+
+
+
+
+
Capacity
+
+ Number of people you'd like to rideshare with, not
+ including yourself
+
+
+
+
+
Origin & Destination
+
+
{
+ setOrigin(place); // Store selected place details in state
+ }}
+ onChange={(e) => onChange(e, setOrigin)}
+ options={autocompleteOptions}
+ ref={originRef}
+ />
+
+ flipFields(
+ origin,
+ dest,
+ originRef,
+ destinationRef,
+ setOrigin,
+ setDest
+ )
+ }
+ >
+ {
+ setDest(place); // Store selected place details in state
+ }}
+ onChange={(e) => onChange(e, setDest)}
+ options={autocompleteOptions}
+ ref={destinationRef}
+ />
+
+ {/* preview so riders can confirm e.g. PHL vs EWR before posting */}
+ {origin?.formatted_address && dest?.formatted_address && (
+
+ {renderToAndFrom({
+ origin: placeToLocation(origin),
+ destination: placeToLocation(dest),
+ })}
+
+ )}
+
+
+
Arrival Time (in ET)
+
+
+
+
Departure Window (optional)
+
+ When you're planning to leave, on the arrival date
+
+
+
+ to
+
+
+
+
+
Phone Number
+
+ Only shown to riders you accept
+
+
setPhoneNumber(e.target.value)}
+ maxLength={20}
+ />
+
+
+
Optional Note to Riders
+
+
+
+
+ Create rideshare
+
+
+
+ )}
+ {validationModal && (
+ setValidationModal(null)}
+ title={validationModal.title}
+ >
+
+
{validationModal.message}
+
setValidationModal(null)}
+ >
+ Okay
+
+
+
+ )}
+ >
+ );
+}
diff --git a/frontend/src/components/DateTimePicker.jsx b/frontend/src/components/DateTimePicker.jsx
index 2e201a7..fa80909 100644
--- a/frontend/src/components/DateTimePicker.jsx
+++ b/frontend/src/components/DateTimePicker.jsx
@@ -9,6 +9,19 @@ export default function MyDateTimePicker({
time,
setTime,
allowClear = true,
+ // Optional, for pages that restyle or label the pickers (e.g. the
+ // "lift-picker" look on Schedule a Ride). Defaults keep the old look.
+ className = "",
+ datePlaceholder = "Select date",
+ timePlaceholder = "Select time",
+ dateId,
+ timeId,
+ status,
+ suffixIcon,
+ // extra props for each picker, e.g. aria-label / aria-describedby /
+ // format / popupClassName
+ dateProps = {},
+ timeProps = {},
}) {
// on phones, tapping opens the picker without the on-screen keyboard
const isMobile = useIsMobile();
@@ -55,18 +68,25 @@ export default function MyDateTimePicker({
};
return (
-
+
);
diff --git a/frontend/src/components/IconButton.jsx b/frontend/src/components/IconButton.jsx
index 469531e..fe6c2f3 100644
--- a/frontend/src/components/IconButton.jsx
+++ b/frontend/src/components/IconButton.jsx
@@ -24,6 +24,24 @@ export default function IconButton({
/>
);
+ case "arrowLeft":
+ return (
+
+ );
case "checkmark":
return (