Skip to content

Commit

Permalink
fix: enforced non-empty travel details if applying for travel reimbur…
Browse files Browse the repository at this point in the history
…sement
  • Loading branch information
mzhou08 committed Dec 24, 2024
1 parent 2c69abd commit dd9ba12
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/form/ApplicationForm/TravelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ const TravelSection = ({
const [wantsTravelReimbursement, setWantsTravelReimbursement] = useState<boolean>(false);
const [travelDetails, setTravelDetails] = useState<string>('');

// Error fields
const [travelInfoErrorStatus, setTravelInfoErrorStatus] = useState(false);
const [travelInfoHelper, setTravelInfoHelper] = useState<string>('');

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);
};

Expand Down Expand Up @@ -81,6 +93,8 @@ const TravelSection = ({
<TextField
label="Travel details"
variant="outlined"
error={travelInfoErrorStatus}
helperText={travelInfoHelper}
fullWidth
multiline
value={travelDetails}
Expand Down

0 comments on commit dd9ba12

Please sign in to comment.