From dd9ba1250c7b4516d35484b9dfaf689cafc7c21c Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Tue, 24 Dec 2024 02:18:12 -0500 Subject: [PATCH] fix: enforced non-empty travel details if applying for travel reimbursement --- .../form/ApplicationForm/TravelSection.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/form/ApplicationForm/TravelSection.tsx b/src/components/form/ApplicationForm/TravelSection.tsx index c077562..b6ab261 100644 --- a/src/components/form/ApplicationForm/TravelSection.tsx +++ b/src/components/form/ApplicationForm/TravelSection.tsx @@ -31,10 +31,22 @@ const TravelSection = ({ const [wantsTravelReimbursement, setWantsTravelReimbursement] = useState(false); const [travelDetails, setTravelDetails] = useState(''); + // Error fields + const [travelInfoErrorStatus, setTravelInfoErrorStatus] = useState(false); + const [travelInfoHelper, setTravelInfoHelper] = useState(''); + const validateForm = async () => { const data: TravelFields = { wantsTravelReimbursement, travelDetails }; await dispatch(actions.application.saveTravel(data)); - setValid(true); + + let valid = true; + if (wantsTravelReimbursement && travelDetails.length === 0) { + setTravelInfoErrorStatus(true); + setTravelInfoHelper('Please provide travel details if you want to apply for travel reimbursement'); + valid = false; + } + + setValid(valid); setValidate(false); }; @@ -81,6 +93,8 @@ const TravelSection = ({