2022-02-05 00:55:57 +00:00
|
|
|
import React, { useCallback, useEffect } from "react";
|
|
|
|
import { Modal, ModalContent } from "../Modal";
|
|
|
|
import { Button } from "../button";
|
|
|
|
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
|
|
|
|
import { useSubmitRageshake, useRageshakeRequest } from "../settings/rageshake";
|
|
|
|
import { Body } from "../typography/Typography";
|
2022-02-07 23:24:43 +00:00
|
|
|
import { randomString } from "matrix-js-sdk/src/randomstring";
|
2022-02-05 00:55:57 +00:00
|
|
|
|
|
|
|
export function FeedbackModal({ inCall, roomId, ...rest }) {
|
|
|
|
const { submitRageshake, sending, sent, error } = useSubmitRageshake();
|
|
|
|
const sendRageshakeRequest = useRageshakeRequest();
|
|
|
|
|
|
|
|
const onSubmitFeedback = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const data = new FormData(e.target);
|
|
|
|
const description = data.get("description");
|
|
|
|
const sendLogs = data.get("sendLogs");
|
2022-02-07 23:24:43 +00:00
|
|
|
const rageshakeRequestId = randomString(16);
|
|
|
|
|
|
|
|
submitRageshake({
|
|
|
|
description,
|
|
|
|
sendLogs,
|
|
|
|
rageshakeRequestId,
|
2022-02-23 23:52:53 +00:00
|
|
|
roomId,
|
2022-02-07 23:24:43 +00:00
|
|
|
});
|
2022-02-05 00:55:57 +00:00
|
|
|
|
|
|
|
if (inCall && sendLogs) {
|
2022-02-07 23:24:43 +00:00
|
|
|
sendRageshakeRequest(roomId, rageshakeRequestId);
|
2022-02-05 00:55:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[inCall, submitRageshake, roomId, sendRageshakeRequest]
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (sent) {
|
|
|
|
rest.onClose();
|
|
|
|
}
|
|
|
|
}, [sent, rest.onClose]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal title="Submit Feedback" isDismissable {...rest}>
|
|
|
|
<ModalContent>
|
2022-02-05 01:00:58 +00:00
|
|
|
<Body>Having trouble? Help us fix it.</Body>
|
2022-02-05 00:55:57 +00:00
|
|
|
<form onSubmit={onSubmitFeedback}>
|
|
|
|
<FieldRow>
|
|
|
|
<InputField
|
|
|
|
id="description"
|
|
|
|
name="description"
|
|
|
|
label="Description (optional)"
|
|
|
|
type="text"
|
|
|
|
/>
|
|
|
|
</FieldRow>
|
|
|
|
<FieldRow>
|
|
|
|
<InputField
|
|
|
|
id="sendLogs"
|
|
|
|
name="sendLogs"
|
|
|
|
label="Include Debug Logs"
|
|
|
|
type="checkbox"
|
|
|
|
defaultChecked
|
|
|
|
/>
|
|
|
|
</FieldRow>
|
|
|
|
{error && (
|
|
|
|
<FieldRow>
|
|
|
|
<ErrorMessage>{error.message}</ErrorMessage>
|
|
|
|
</FieldRow>
|
|
|
|
)}
|
|
|
|
<FieldRow>
|
|
|
|
<Button type="submit" disabled={sending}>
|
|
|
|
{sending ? "Submitting feedback..." : "Submit Feedback"}
|
|
|
|
</Button>
|
|
|
|
</FieldRow>
|
|
|
|
</form>
|
|
|
|
</ModalContent>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|