Files
element-call/src/room/InviteModal.tsx

85 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022 - 2023 New Vector Ltd
2022-05-04 17:09:48 +01:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2023-09-27 17:34:41 -04:00
import { FC, MouseEvent, useCallback, useMemo, useState } from "react";
2022-10-10 09:19:10 -04:00
import { useTranslation } from "react-i18next";
import { Room } from "matrix-js-sdk";
2023-09-27 17:34:41 -04:00
import { Button, Text } from "@vector-im/compound-web";
import { ReactComponent as LinkIcon } from "@vector-im/compound-design-tokens/icons/link.svg";
import { ReactComponent as CheckIcon } from "@vector-im/compound-design-tokens/icons/check.svg";
import useClipboard from "react-use-clipboard";
2022-08-02 00:46:16 +02:00
import { Modal } from "../Modal";
import { getAbsoluteRoomUrl } from "../matrix-utils";
import styles from "./InviteModal.module.css";
import { useRoomSharedKey } from "../e2ee/sharedKeyManagement";
2023-09-27 17:34:41 -04:00
import { Toast } from "../Toast";
2021-12-03 11:45:29 -08:00
interface Props {
room: Room;
open: boolean;
onDismiss: () => void;
2021-12-03 11:45:29 -08:00
}
2022-08-05 16:16:59 -04:00
export const InviteModal: FC<Props> = ({ room, open, onDismiss }) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
const roomSharedKey = useRoomSharedKey(room.roomId);
2023-09-27 17:34:41 -04:00
const url = useMemo(
() =>
getAbsoluteRoomUrl(room.roomId, room.name, roomSharedKey ?? undefined),
[room, roomSharedKey]
);
const [, setCopied] = useClipboard(url);
const [toastOpen, setToastOpen] = useState(false);
const onToastDismiss = useCallback(() => setToastOpen(false), [setToastOpen]);
const onButtonClick = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
setCopied();
onDismiss();
setToastOpen(true);
},
[setCopied, onDismiss]
);
2022-10-10 09:19:10 -04:00
return (
2023-09-27 17:34:41 -04:00
<>
<Modal title={t("Invite to this call")} open={open} onDismiss={onDismiss}>
<Text className={styles.url} size="sm" weight="semibold">
{url}
</Text>
<Button
className={styles.button}
Icon={LinkIcon}
onClick={onButtonClick}
data-testid="modal_inviteLink"
>
{t("Copy link")}
</Button>
</Modal>
<Toast
open={toastOpen}
onDismiss={onToastDismiss}
autoDismiss={2000}
Icon={CheckIcon}
>
{t("Link copied to clipboard")}
</Toast>
</>
2022-10-10 09:19:10 -04:00
);
};