Skip to content

Commit

Permalink
Add help function to verify whether any of the properties in modalCon…
Browse files Browse the repository at this point in the history
…tent is provided.
  • Loading branch information
jonasbrunvoll committed Nov 12, 2024
1 parent 53de17d commit b21b3a6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/page-modules/contact/components/form/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const Input = ({
}: InputProps) => {
const { t } = useTranslation();
const [isModalOpen, setIsModalOpen] = useState(false);
const displayDescriptionModal = modalContent && isModalOpen; // Condition to avoid rendering of useEffect inside DescriptionModal before opened.

const isModalContentProvided = hasModalContent(modalContent);
const displayDescriptionModal = isModalOpen && isModalContentProvided;
const toggleModalState = () => {
setIsModalOpen(!isModalOpen);
};
Expand All @@ -49,7 +49,7 @@ export const Input = ({
<Typo.span textType="body__primary">{t(label)}</Typo.span>
</label>

{modalContent && (
{isModalContentProvided && (
<Button
className={style.iconButton}
onClick={toggleModalState}
Expand Down Expand Up @@ -78,7 +78,7 @@ export const Input = ({
{displayDescriptionModal && (
<DescriptionModal
title={t(label)}
modalContent={modalContent}
modalContent={modalContent || {}}
isModalOpen={isModalOpen}
closeModal={toggleModalState}
/>
Expand All @@ -88,3 +88,16 @@ export const Input = ({
};

export default Input;

function hasModalContent(content?: {
description?: string;
instruction?: string;
bulletPoints?: string[];
}): boolean {
return !!(
content &&
(content.description ||
content.instruction ||
(content.bulletPoints && content.bulletPoints?.length > 0))
);
}

0 comments on commit b21b3a6

Please sign in to comment.