add ability to set reported user after report creation (#17)
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s
This commit is contained in:
parent
3762872e01
commit
9f5fe25653
@ -1,5 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
type T = $$Generic;
|
type T = $$Generic;
|
||||||
|
|
||||||
export let id: string | null = null;
|
export let id: string | null = null;
|
||||||
@ -10,6 +12,9 @@
|
|||||||
export let required = false;
|
export let required = false;
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
export let size: 'xs' | 'sm' | 'md' | 'lg' = 'md';
|
export let size: 'xs' | 'sm' | 'md' | 'lg' = 'md';
|
||||||
|
export let pickyWidth = true;
|
||||||
|
|
||||||
|
let dispatch = createEventDispatcher();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -24,7 +29,8 @@
|
|||||||
</label>
|
</label>
|
||||||
{/if}
|
{/if}
|
||||||
<select
|
<select
|
||||||
class="select select-bordered w-[100%] sm:max-w-[16rem]"
|
class="select select-bordered w-[100%]"
|
||||||
|
class:sm:max-w-[16rem]={pickyWidth}
|
||||||
class:select-xs={size === 'xs'}
|
class:select-xs={size === 'xs'}
|
||||||
class:select-sm={size === 'sm'}
|
class:select-sm={size === 'sm'}
|
||||||
class:select-md={size === 'md'}
|
class:select-md={size === 'md'}
|
||||||
@ -34,6 +40,7 @@
|
|||||||
{required}
|
{required}
|
||||||
{disabled}
|
{disabled}
|
||||||
bind:value
|
bind:value
|
||||||
|
on:change={(e) => dispatch('change', { value: value })}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</select>
|
</select>
|
||||||
|
@ -23,6 +23,9 @@ export const load: PageServerLoad = async ({ params }) => {
|
|||||||
},
|
},
|
||||||
reported: {
|
reported: {
|
||||||
name: report.reported?.username || null
|
name: report.reported?.username || null
|
||||||
}
|
},
|
||||||
|
users: report.draft
|
||||||
|
? (await User.findAll({ attributes: ['username'] })).map((u) => u.username)
|
||||||
|
: null
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
<ReportDraft
|
<ReportDraft
|
||||||
reason={data.reason}
|
reason={data.reason}
|
||||||
reporterName={data.reporter.name}
|
reporterName={data.reporter.name}
|
||||||
reportedName={data.reported.name}
|
reportedName={data.reported.name ?? undefined}
|
||||||
|
users={data.users ?? []}
|
||||||
on:submit={() => (data.draft = false)}
|
on:submit={() => (data.draft = false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,15 +1,23 @@
|
|||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import { Report } from '$lib/server/database';
|
import { Report, User } from '$lib/server/database';
|
||||||
|
|
||||||
export const POST = (async ({ request, params }) => {
|
export const POST = (async ({ request, params }) => {
|
||||||
const report = await Report.findOne({ where: { url_hash: params.url_hash } });
|
const report = await Report.findOne({ where: { url_hash: params.url_hash } });
|
||||||
|
|
||||||
if (report == null) return new Response(null, { status: 400 });
|
if (report == null) return new Response(null, { status: 400 });
|
||||||
|
|
||||||
const data: { body: string } = await request.json();
|
const data: { reported: string | null; subject: string; body: string } = await request.json();
|
||||||
|
|
||||||
|
const user =
|
||||||
|
data.reported != null ? await User.findOne({ where: { username: data.reported } }) : undefined;
|
||||||
|
if (user === null) {
|
||||||
|
return new Response(null, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
report.draft = false;
|
report.draft = false;
|
||||||
report.body = data.body || '';
|
report.subject = data.subject ?? '';
|
||||||
|
report.body = data.body ?? '';
|
||||||
|
report.reported_id = user?.id;
|
||||||
await report.save();
|
await report.save();
|
||||||
|
|
||||||
return new Response(null, { status: 200 });
|
return new Response(null, { status: 200 });
|
||||||
|
@ -4,34 +4,78 @@
|
|||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
import Search from '$lib/components/Input/Search.svelte';
|
||||||
|
import Select from '$lib/components/Input/Select.svelte';
|
||||||
|
|
||||||
export let reporterName: string;
|
export let reporterName: string;
|
||||||
export let reportedName: string | null;
|
export let reportedName: string | null;
|
||||||
export let reason: string;
|
export let reason: string;
|
||||||
|
export let users: string[];
|
||||||
|
|
||||||
|
let oldReported = reportedName;
|
||||||
|
$: reportedName = oldReported;
|
||||||
|
|
||||||
let body: string;
|
let body: string;
|
||||||
|
let userErrorModal: HTMLDialogElement;
|
||||||
|
let submitModal: HTMLDialogElement;
|
||||||
|
|
||||||
|
let dispatch = createEventDispatcher();
|
||||||
|
|
||||||
async function submitReport() {
|
async function submitReport() {
|
||||||
await fetch(`${env.PUBLIC_BASE_PATH}/report/${$page.params.url_hash}`, {
|
await fetch(`${env.PUBLIC_BASE_PATH}/report/${$page.params.url_hash}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
reported: reportedName || null,
|
||||||
|
subject: reason,
|
||||||
body: body
|
body: body
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let dispatch = createEventDispatcher();
|
async function suggestNames(input: string): Promise<{ name: string; value: string }[]> {
|
||||||
|
let i = 0;
|
||||||
let submitModal: HTMLDialogElement;
|
return users
|
||||||
|
.filter((v) => v.includes(input) && v != reporterName && i++ < 6)
|
||||||
|
.map((v) => {
|
||||||
|
return { name: v, value: v };
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-3xl text-center">
|
<h2 class="text-3xl text-center">
|
||||||
Report von <span class="underline">{reporterName}</span> gegen
|
Report von <span class="underline">{reporterName}</span> gegen
|
||||||
<span class="underline">{reportedName || 'unbekannt'}</span>
|
<span class="underline">{(reportedName ?? 'unbekannt') || oldReported}</span>
|
||||||
</h2>
|
</h2>
|
||||||
<form on:submit|preventDefault={() => submitModal.show()}>
|
<form
|
||||||
|
on:submit|preventDefault={() => {
|
||||||
|
if (reportedName != null && users.findIndex((u) => u === reportedName) === -1) {
|
||||||
|
userErrorModal.show();
|
||||||
|
} else {
|
||||||
|
submitModal.show();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div class="space-y-4 my-4">
|
<div class="space-y-4 my-4">
|
||||||
|
<div class="flex justify-center gap-4">
|
||||||
|
<Select
|
||||||
|
value={+(reportedName === null)}
|
||||||
|
size="sm"
|
||||||
|
pickyWidth={false}
|
||||||
|
on:change={(e) => (reportedName = e.detail.value === 0 ? '' : null)}
|
||||||
|
>
|
||||||
|
<option value={0}>Ich möchte einen bestimmten Spieler reporten</option>
|
||||||
|
<option value={1}>Ich möchte einen unbekannten Spieler reporten</option>
|
||||||
|
</Select>
|
||||||
|
{#if reportedName !== null}
|
||||||
|
<Search
|
||||||
|
size="sm"
|
||||||
|
bind:inputValue={oldReported}
|
||||||
|
suggestionRequired={true}
|
||||||
|
searchSuggestionFunc={suggestNames}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Input type="text" bind:value={reason} required={true} pickyWidth={false}>
|
<Input type="text" bind:value={reason} required={true} pickyWidth={false}>
|
||||||
<span slot="label">Report Grund</span>
|
<span slot="label">Report Grund</span>
|
||||||
@ -52,6 +96,24 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<dialog class="modal" bind:this={userErrorModal}>
|
||||||
|
<form method="dialog" class="modal-box">
|
||||||
|
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-roboto font-medium text-xl">Fehler</h3>
|
||||||
|
<div class="my-4">
|
||||||
|
<p>Der zu reportende Spieler existiert nicht</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-row space-x-1">
|
||||||
|
<Input type="submit" value="Schließen" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="dialog" class="modal-backdrop bg-[rgba(0,0,0,.3)]">
|
||||||
|
<button>close</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
<dialog class="modal" bind:this={submitModal}>
|
<dialog class="modal" bind:this={submitModal}>
|
||||||
<form method="dialog" class="modal-box">
|
<form method="dialog" class="modal-box">
|
||||||
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user