diff --git a/src/components/AddSenior.tsx b/src/components/AddSenior.tsx index 2ddbbcfa..c8d20732 100644 --- a/src/components/AddSenior.tsx +++ b/src/components/AddSenior.tsx @@ -31,6 +31,18 @@ type AddSeniorTileProps = { setSeniorPatch: Dispatch>; }; +type SeniorData = Pick< + z.infer, + "firstname" | "lastname" | "location" | "description" +>; + +const EMPTY_SENIOR: SeniorData = { + firstname: "", + lastname: "", + location: "", + description: "", +}; + export const AddSeniorTile = ({ showAddSeniorPopUp, setShowAddSeniorPopUp, @@ -92,11 +104,6 @@ const StudentSelector = ({ ); }; -type SeniorData = Pick< - z.infer, - "firstname" | "lastname" | "location" | "description" ->; - const AddSenior = ({ seniors, students, @@ -106,15 +113,7 @@ const AddSenior = ({ seniorPatch, setSeniorPatch, }: AddSeniorProps) => { - const emptySenior = useMemo(() => { - return { - firstname: "", - lastname: "", - location: "", - description: "", - }; - }, []); - const [seniorData, setSeniorData] = useState(emptySenior); + const [seniorData, setSeniorData] = useState(EMPTY_SENIOR); const [selectedStudents, setSelectedStudents] = useState([]); const [currentImage, setCurrentImage] = useState( ImageIcon @@ -135,7 +134,7 @@ const AddSenior = ({ location: initialSenior.location, description: initialSenior.description, }); - }, [initialSenior, emptySenior]); + }, [initialSenior]); useEffect(() => { if (initialSenior) { @@ -149,7 +148,7 @@ const AddSenior = ({ const handlePopUp = () => { setShowAddSeniorPopUp(!showAddSeniorPopUp); - setSeniorData(emptySenior); + setSeniorData(EMPTY_SENIOR); setSelectedStudents([]); setCurrentImage(ImageIcon); setSeniorPatch(""); // empty string used as falsey value to indicate update or patch diff --git a/src/components/SeniorView.tsx b/src/components/SeniorView.tsx index a5368ad6..cd2f8036 100644 --- a/src/components/SeniorView.tsx +++ b/src/components/SeniorView.tsx @@ -34,7 +34,7 @@ export const SeniorView = ({ seniors, students }: SeniorViewProps) => { setSeniorPatch={setSeniorPatch} /> } - elements={seniorsState ? seniorsState : []} + elements={seniorsState} display={(senior) => { const options: Parameters[0]["options"] = []; @@ -43,9 +43,6 @@ export const SeniorView = ({ seniors, students }: SeniorViewProps) => { onClick: (e) => { e.stopPropagation(); e.preventDefault(); - if (!setSeniorPatch || !setShowAddSeniorPopUp) { - return; - } setSeniorPatch(senior.id); setShowAddSeniorPopUp(true); },