2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2022-2024 New Vector Ltd.
|
2022-05-04 17:09:48 +01: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.
|
2022-05-04 17:09:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type FC, useEffect } from "react";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-09-11 13:44:43 -04:00
|
|
|
import { Button, Text } from "@vector-im/compound-web";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { Modal, type Props as ModalProps } from "../Modal";
|
2022-02-04 16:55:57 -08:00
|
|
|
import { FieldRow, ErrorMessage } from "../input/Input";
|
2022-04-07 14:22:36 -07:00
|
|
|
import { useSubmitRageshake } from "../settings/submit-rageshake";
|
2022-02-04 16:55:57 -08:00
|
|
|
|
2022-08-05 16:16:59 -04:00
|
|
|
interface Props extends Omit<ModalProps, "title" | "children"> {
|
2022-08-02 00:46:16 +02:00
|
|
|
rageshakeRequestId: string;
|
2023-07-04 18:46:27 +01:00
|
|
|
roomId: string;
|
2023-09-17 14:35:35 -04:00
|
|
|
open: boolean;
|
|
|
|
|
onDismiss: () => void;
|
2022-08-05 16:16:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const RageshakeRequestModal: FC<Props> = ({
|
2022-07-27 16:14:05 -04:00
|
|
|
rageshakeRequestId,
|
2023-07-04 18:46:27 +01:00
|
|
|
roomId,
|
2023-09-17 14:35:35 -04:00
|
|
|
open,
|
|
|
|
|
onDismiss,
|
2022-08-05 16:16:59 -04:00
|
|
|
}) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2022-02-04 16:55:57 -08:00
|
|
|
const { submitRageshake, sending, sent, error } = useSubmitRageshake();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-09-17 14:35:35 -04:00
|
|
|
if (sent) onDismiss();
|
|
|
|
|
}, [sent, onDismiss]);
|
2022-02-04 16:55:57 -08:00
|
|
|
|
|
|
|
|
return (
|
2023-11-20 13:38:01 +00:00
|
|
|
<Modal
|
|
|
|
|
title={t("rageshake_request_modal.title")}
|
|
|
|
|
open={open}
|
|
|
|
|
onDismiss={onDismiss}
|
|
|
|
|
>
|
2024-09-11 13:44:43 -04:00
|
|
|
<Text>{t("rageshake_request_modal.body")}</Text>
|
2023-09-17 14:35:35 -04:00
|
|
|
<FieldRow>
|
|
|
|
|
<Button
|
2024-08-28 08:44:39 -04:00
|
|
|
onClick={(): void =>
|
2023-09-22 18:05:13 -04:00
|
|
|
void submitRageshake({
|
2023-09-17 14:35:35 -04:00
|
|
|
sendLogs: true,
|
|
|
|
|
rageshakeRequestId,
|
|
|
|
|
roomId,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
disabled={sending}
|
|
|
|
|
>
|
2023-11-20 13:00:43 +00:00
|
|
|
{sending ? t("rageshake_sending_logs") : t("rageshake_send_logs")}
|
2023-09-17 14:35:35 -04:00
|
|
|
</Button>
|
|
|
|
|
</FieldRow>
|
|
|
|
|
{error && (
|
2022-02-04 16:55:57 -08:00
|
|
|
<FieldRow>
|
2023-09-17 14:35:35 -04:00
|
|
|
<ErrorMessage error={error} />
|
2022-02-04 16:55:57 -08:00
|
|
|
</FieldRow>
|
2023-09-17 14:35:35 -04:00
|
|
|
)}
|
2022-02-04 16:55:57 -08:00
|
|
|
</Modal>
|
|
|
|
|
);
|
2022-08-05 16:16:59 -04:00
|
|
|
};
|