Added function to access imprint with "#imprint"

This commit is contained in:
phntxx 2020-12-15 14:11:15 +01:00
parent 759ceac608
commit aaeeb54b73
2 changed files with 24 additions and 8 deletions

View file

@ -82,6 +82,13 @@ const useImprintData = () => {
return { imprintData, fetchImprintData };
};
const onClose = () => {
if (window.location.href.endsWith("#imprint")) {
let location = window.location.href.replace("#imprint", "");
window.location.href = location;
}
};
const Imprint = () => {
const {
imprintData: { name, address, phone, email, url, error },
@ -99,7 +106,12 @@ const Imprint = () => {
<ItemList>
<ItemContainer>
<SHl>Imprint</SHl>
<Modal element="text" text="View Imprint">
<Modal
element="text"
text="View Imprint"
condition={!window.location.href.endsWith("#imprint")}
onClose={() => onClose()}
>
<Headline>Legal Disclosure</Headline>
{error && <ErrorMessage>{error}</ErrorMessage>}
<ModalSubHeadline>

View file

@ -34,27 +34,31 @@ interface IModalInterface {
element: string;
icon?: string;
text?: string;
condition?: boolean;
onClose?: () => void;
children: React.ReactNode;
}
const Modal = (props: IModalInterface) => {
const [modalHidden, setModalHidden] = useState(true);
const [modalHidden, setModalHidden] = useState(props.condition ?? true);
const closeModal = () => {
if (props.onClose) props.onClose();
setModalHidden(!modalHidden);
};
return (
<>
{props.element === "icon" && (
<IconButton
icon={props.icon ? props.icon : ""}
onClick={() => setModalHidden(!modalHidden)}
/>
<IconButton icon={props.icon ?? ""} onClick={() => closeModal()} />
)}
{props.element === "text" && (
<Text onClick={() => setModalHidden(!modalHidden)}>{props.text}</Text>
<Text onClick={() => closeModal()}>{props.text}</Text>
)}
<ModalContainer hidden={modalHidden}>
<IconButton icon="close" onClick={() => setModalHidden(!modalHidden)} />
<IconButton icon="close" onClick={() => closeModal()} />
{props.children}
</ModalContainer>
</>