2023-03-23 15:20:07 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import type { APIError } from "$lib/api/entities";
|
2023-03-30 16:05:40 +02:00
|
|
|
import { fastFetchClient } from "$lib/api/fetch";
|
2023-03-23 15:20:07 +01:00
|
|
|
import ErrorAlert from "$lib/components/ErrorAlert.svelte";
|
|
|
|
import { addToast } from "$lib/toast";
|
|
|
|
import { Button, FormGroup, Icon, Modal, ModalBody, ModalFooter } from "sveltestrap";
|
|
|
|
|
|
|
|
export let subject: string;
|
|
|
|
export let reportUrl: string;
|
|
|
|
|
|
|
|
const MAX_REASON_LENGTH = 2000;
|
|
|
|
let reason = "";
|
|
|
|
|
|
|
|
let error: APIError | null = null;
|
|
|
|
|
|
|
|
let isOpen = false;
|
|
|
|
const toggle = () => (isOpen = !isOpen);
|
|
|
|
|
|
|
|
const doReport = async () => {
|
|
|
|
try {
|
2023-03-30 16:05:40 +02:00
|
|
|
await fastFetchClient(reportUrl, "POST", { reason: reason });
|
2023-03-23 15:20:07 +01:00
|
|
|
error = null;
|
|
|
|
addToast({ header: "Sent report", body: "Successfully sent report!" });
|
|
|
|
toggle();
|
|
|
|
} catch (e) {
|
|
|
|
error = e as APIError;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2023-04-22 15:04:38 +02:00
|
|
|
<Button color="danger" outline on:click={toggle}
|
|
|
|
><Icon name="exclamation-triangle-fill" /> Report {subject}</Button
|
|
|
|
>
|
2023-03-23 15:20:07 +01:00
|
|
|
|
|
|
|
<Modal header="Report {subject}" {isOpen} {toggle}>
|
|
|
|
<ModalBody>
|
|
|
|
{#if error}
|
|
|
|
<ErrorAlert {error} />
|
|
|
|
{/if}
|
|
|
|
<FormGroup floating label="Reason" class="mt-2">
|
|
|
|
<textarea style="min-height: 100px;" class="form-control" bind:value={reason} />
|
|
|
|
</FormGroup>
|
|
|
|
<p class="text-muted mt-3">
|
|
|
|
<Icon name="info-circle-fill" aria-hidden /> Please only report {subject}s for violating the
|
|
|
|
<a class="text-reset" href="/page/terms" target="_blank" rel="noopener noreferrer"
|
|
|
|
>terms of service</a
|
|
|
|
>.
|
|
|
|
</p>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<Button
|
|
|
|
color="danger"
|
|
|
|
disabled={!reason || reason.length > MAX_REASON_LENGTH}
|
|
|
|
on:click={doReport}>Report</Button
|
|
|
|
>
|
|
|
|
<Button color="secondary" on:click={toggle}>Cancel</Button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|