Skip to content

Commit

Permalink
disable form when required fields are not present
Browse files Browse the repository at this point in the history
  • Loading branch information
zhammer committed Feb 24, 2024
1 parent 658efa5 commit a7d23fb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Autocomplete from '@mui/material/Autocomplete';
import Stack from '@mui/material/Stack';
import { Award } from '@seatgeek/backstage-plugin-awards-common';
import { isEmpty, random } from 'lodash';
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import useAsync from 'react-use/lib/useAsync';
import { awardsApiRef } from '../../api';
Expand Down Expand Up @@ -87,6 +87,10 @@ export const AwardEditCard = ({ award = emptyAward }: AwardEditCardProps) => {
};
}),
);
const hasRequiredFields = useMemo(() => {
return awardName !== '' && awardDescription !== '' && awardImage !== '';
}, [awardName, awardDescription, awardImage]);

const [allUsers, setAllUsers] = useState(new Array<User>());

useAsync(async () => {
Expand Down Expand Up @@ -287,6 +291,7 @@ export const AwardEditCard = ({ award = emptyAward }: AwardEditCardProps) => {
color="primary"
variant="contained"
startIcon={<CreateComponentIcon />}
disabled={!hasRequiredFields}
onClick={saveAward}
>
Save
Expand Down

0 comments on commit a7d23fb

Please sign in to comment.