revite/src/pages/settings/panes/Feedback.tsx

97 lines
3.4 KiB
TypeScript
Raw Normal View History

2021-06-19 17:37:12 -04:00
import styles from "./Panes.module.scss";
import { Localizer, Text } from "preact-i18n";
2021-07-05 06:23:23 -04:00
import { useState } from "preact/hooks";
2021-07-29 10:11:21 -04:00
import { useClient } from "../../../context/revoltjs/RevoltClient";
2021-07-05 06:23:23 -04:00
2021-06-19 17:37:12 -04:00
import Button from "../../../components/ui/Button";
import InputBox from "../../../components/ui/InputBox";
2021-07-05 06:23:23 -04:00
import Radio from "../../../components/ui/Radio";
2021-06-20 15:30:42 -04:00
import TextArea from "../../../components/ui/TextArea";
2021-06-19 17:37:12 -04:00
export function Feedback() {
2021-07-29 10:11:21 -04:00
const client = useClient();
2021-07-05 06:25:20 -04:00
const [other, setOther] = useState("");
const [description, setDescription] = useState("");
const [state, setState] = useState<"ready" | "sending" | "sent">("ready");
const [checked, setChecked] = useState<
"Bug" | "Feature Request" | "__other_option__"
>("Bug");
2021-06-19 17:37:12 -04:00
2021-07-05 06:25:20 -04:00
async function onSubmit(ev: JSX.TargetedEvent<HTMLFormElement, Event>) {
ev.preventDefault();
setState("sending");
2021-06-19 17:37:12 -04:00
2021-07-05 06:25:20 -04:00
await fetch(`https://workers.revolt.chat/feedback`, {
method: "POST",
body: JSON.stringify({
checked,
other,
description,
2021-07-29 10:11:21 -04:00
name: client.user!.username,
2021-07-05 06:25:20 -04:00
}),
mode: "no-cors",
});
2021-06-19 17:37:12 -04:00
2021-07-05 06:25:20 -04:00
setState("sent");
setChecked("Bug");
setDescription("");
setOther("");
}
2021-06-19 17:37:12 -04:00
2021-07-05 06:25:20 -04:00
return (
<form className={styles.feedback} onSubmit={onSubmit}>
<h3>
<Text id="app.settings.pages.feedback.report" />
</h3>
<div className={styles.options}>
<Radio
checked={checked === "Bug"}
disabled={state === "sending"}
onSelect={() => setChecked("Bug")}>
<Text id="app.settings.pages.feedback.bug" />
</Radio>
<Radio
disabled={state === "sending"}
checked={checked === "Feature Request"}
onSelect={() => setChecked("Feature Request")}>
<Text id="app.settings.pages.feedback.feature" />
</Radio>
<Radio
disabled={state === "sending"}
2021-07-09 11:23:06 -04:00
checked={checked === "__other_option__"}
2021-07-05 06:25:20 -04:00
onSelect={() => setChecked("__other_option__")}>
<Localizer>
<InputBox
value={other}
disabled={state === "sending"}
name="entry.1151440373.other_option_response"
onChange={(e) => setOther(e.currentTarget.value)}
placeholder={
(
<Text id="app.settings.pages.feedback.other" />
) as any
}
/>
</Localizer>
</Radio>
</div>
<h3>
<Text id="app.settings.pages.feedback.describe" />
</h3>
<TextArea
// maxRows={10}
value={description}
id="entry.685672624"
disabled={state === "sending"}
onChange={(ev) => setDescription(ev.currentTarget.value)}
/>
<p>
<Button type="submit" contrast>
<Text id="app.settings.pages.feedback.send" />
</Button>
</p>
</form>
);
2021-06-19 17:37:12 -04:00
}