waveterm/frontend/app/modals/modalsrenderer.tsx

38 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
2024-08-30 01:06:15 +02:00
import { atoms, globalStore } from "@/store/global";
import { modalsModel } from "@/store/modalmodel";
import * as jotai from "jotai";
2024-08-30 01:06:15 +02:00
import { useEffect } from "react";
import { getModalComponent } from "./modalregistry";
import { TosModal } from "./tos";
const ModalsRenderer = () => {
const clientData = jotai.useAtomValue(atoms.client);
2024-09-17 08:45:47 +02:00
const [tosOpen, setTosOpen] = jotai.useAtom(modalsModel.tosOpen);
const [modals] = jotai.useAtom(modalsModel.modalsAtom);
const rtn: JSX.Element[] = [];
for (const modal of modals) {
const ModalComponent = getModalComponent(modal.displayName);
if (ModalComponent) {
rtn.push(<ModalComponent key={modal.displayName} {...modal.props} />);
}
}
2024-09-17 08:45:47 +02:00
if (tosOpen) {
rtn.push(<TosModal key={TosModal.displayName} />);
}
2024-09-17 08:45:47 +02:00
useEffect(() => {
if (!clientData.tosagreed) {
setTosOpen(true);
}
}, [clientData]);
2024-08-30 01:06:15 +02:00
useEffect(() => {
globalStore.set(atoms.modalOpen, rtn.length > 0);
2024-09-17 08:45:47 +02:00
}, [rtn]);
return <>{rtn}</>;
};
export { ModalsRenderer };