2023-06-09 19:18:30 +02:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2023, 2024 New Vector Ltd.
|
2023-06-09 19:18:30 +02:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2023-06-09 19:18:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import classNames from "classnames";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type FC, type HTMLAttributes, type ReactNode } from "react";
|
2023-06-12 10:14:11 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-06-09 19:18:30 +02:00
|
|
|
|
|
|
|
|
import styles from "./DisconnectedBanner.module.css";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type ValidClientState, useClientState } from "./ClientContext";
|
2023-06-09 19:18:30 +02:00
|
|
|
|
2023-09-22 18:05:13 -04:00
|
|
|
interface Props extends HTMLAttributes<HTMLElement> {
|
2023-06-09 19:18:30 +02:00
|
|
|
children?: ReactNode;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 18:05:13 -04:00
|
|
|
export const DisconnectedBanner: FC<Props> = ({
|
2023-06-09 19:18:30 +02:00
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
...rest
|
2023-09-22 18:05:13 -04:00
|
|
|
}) => {
|
2023-06-12 10:14:11 +02:00
|
|
|
const { t } = useTranslation();
|
2023-07-21 20:03:37 +01:00
|
|
|
const clientState = useClientState();
|
|
|
|
|
let shouldShowBanner = false;
|
|
|
|
|
|
|
|
|
|
if (clientState?.state === "valid") {
|
|
|
|
|
const validClientState = clientState as ValidClientState;
|
|
|
|
|
shouldShowBanner = validClientState.disconnected;
|
|
|
|
|
}
|
2023-06-12 10:14:11 +02:00
|
|
|
|
2023-06-09 19:18:30 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2023-07-21 20:03:37 +01:00
|
|
|
{shouldShowBanner && (
|
2023-06-12 10:14:11 +02:00
|
|
|
<div className={classNames(styles.banner, className)} {...rest}>
|
|
|
|
|
{children}
|
2023-11-20 13:00:43 +00:00
|
|
|
{t("disconnected_banner")}
|
2023-06-12 10:14:11 +02:00
|
|
|
</div>
|
2023-06-09 19:18:30 +02:00
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|