Application Denial Reason Modal + Inclusion in Denial Process
This commit is contained in:
2 files changed
+107
-32
No files matched your search
@@ -0,0 +1,40 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import type { Person } from 'lemmy-js-client'
|
||||||
|
import { Button, Modal, toast } from 'mono-svelte'
|
||||||
|
|
||||||
|
export let open: boolean = false
|
||||||
|
export let user: Person
|
||||||
|
|
||||||
|
export let denying: boolean
|
||||||
|
|
||||||
|
export let denyReason = ''
|
||||||
|
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
function deny() {
|
||||||
|
denying = true
|
||||||
|
open = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal bind:open>
|
||||||
|
<h1 class="text-2xl font-bold" slot="title">Deny Application</h1>
|
||||||
|
<form on:submit|preventDefault={() => deny()} class="flex flex-col gap-4">
|
||||||
|
<p class="inline-flex flex-row gap-2 items-center">
|
||||||
|
Denying <UserLink avatar {user} />'s Application
|
||||||
|
</p>
|
||||||
|
<MarkdownEditor
|
||||||
|
bind:value={denyReason}
|
||||||
|
label="Deny Reason (optional)"
|
||||||
|
placeholder="Application Reason breaks rule #3"
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
<Button color="primary" size="lg" submit {loading} disabled={loading}>
|
||||||
|
Deny
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
@@ -4,31 +4,45 @@
|
|||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
import { Material, toast } from 'mono-svelte'
|
import { Material, toast } from 'mono-svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { RegistrationApplicationView } from 'lemmy-js-client'
|
import type {ApproveRegistrationApplication, RegistrationApplicationView} from 'lemmy-js-client'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import { Check, Icon, XMark } from 'svelte-hero-icons'
|
import { Check, Icon, XMark } from 'svelte-hero-icons'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date'
|
import { publishedToDate } from '$lib/components/util/date'
|
||||||
|
import ApplicationDenyModal from "$lib/components/lemmy/modal/ApplicationDenyModal.svelte";
|
||||||
|
|
||||||
export let application: RegistrationApplicationView
|
export let application: RegistrationApplicationView
|
||||||
|
|
||||||
let approving = false
|
let approving = false
|
||||||
let denying = false
|
let denying = false
|
||||||
|
let denyReason = ''
|
||||||
|
let reviewing = false
|
||||||
|
|
||||||
async function review(approve: boolean) {
|
async function review(approve: boolean) {
|
||||||
if (!$profile?.jwt) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
|
let registrationApplicationAnswer: ApproveRegistrationApplication = {
|
||||||
|
approve: approve,
|
||||||
|
id: application.registration_application.id,
|
||||||
|
}
|
||||||
|
|
||||||
if (approve) {
|
if (approve) {
|
||||||
approving = true
|
approving = true
|
||||||
} else {
|
} else {
|
||||||
denying = true
|
reviewing = true
|
||||||
|
while (reviewing) {
|
||||||
|
await new Promise(res => setTimeout(res, 1000))
|
||||||
|
}
|
||||||
|
if (!denying) return
|
||||||
|
if (denyReason != "") {
|
||||||
|
registrationApplicationAnswer.deny_reason = denyReason
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().approveRegistrationApplication({
|
await getClient().approveRegistrationApplication(registrationApplicationAnswer)
|
||||||
approve: approve,
|
|
||||||
id: application.registration_application.id,
|
|
||||||
})
|
|
||||||
toast({
|
toast({
|
||||||
content: `Successfully ${
|
content: `Successfully ${
|
||||||
approve ? 'approved' : 'denied'
|
approve ? 'approved' : 'denied'
|
||||||
@@ -37,6 +51,7 @@
|
|||||||
})
|
})
|
||||||
application.creator_local_user.accepted_application = approve
|
application.creator_local_user.accepted_application = approve
|
||||||
application.admin = $profile.user!.local_user_view.person
|
application.admin = $profile.user!.local_user_view.person
|
||||||
|
application.registration_application.deny_reason = denyReason
|
||||||
|
|
||||||
$profile.user!.notifications.applications -= 1
|
$profile.user!.notifications.applications -= 1
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -48,9 +63,13 @@
|
|||||||
|
|
||||||
approving = false
|
approving = false
|
||||||
denying = false
|
denying = false
|
||||||
|
denyReason = ''
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if reviewing}
|
||||||
|
<ApplicationDenyModal bind:open={reviewing} bind:denying bind:denyReason user={application.creator}/>
|
||||||
|
{/if}
|
||||||
<Material class="flex flex-col gap-2">
|
<Material class="flex flex-col gap-2">
|
||||||
<div class="flex flex-col gap-1">
|
<div class="flex flex-col gap-1">
|
||||||
<span class="text-slate-600 dark:text-zinc-400">
|
<span class="text-slate-600 dark:text-zinc-400">
|
||||||
@@ -70,40 +89,56 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col md:flex-row gap-2 md:items-center">
|
<div class="flex flex-col md:flex-row gap-2 md:items-center">
|
||||||
{#if application.admin}
|
{#if application.admin}
|
||||||
<div class="flex items-center gap-1 text-sm">
|
{#if typeof application.registration_application.deny_reason !== 'undefined' && application.registration_application.deny_reason !== ''}
|
||||||
<SectionTitle>
|
<div>
|
||||||
|
<div class="flex items-center gap-1 text-sm">
|
||||||
|
<SectionTitle>
|
||||||
|
{application.creator_local_user.accepted_application
|
||||||
|
? 'Approved'
|
||||||
|
: 'Denied'} by
|
||||||
|
</SectionTitle>
|
||||||
|
<UserLink avatar user={application.admin} />
|
||||||
|
<SectionTitle>:</SectionTitle>
|
||||||
|
</div>
|
||||||
|
<p>{application.registration_application.deny_reason}</p>
|
||||||
|
</div>
|
||||||
|
<div class="md:ml-auto" />
|
||||||
|
{:else}
|
||||||
|
<div class="flex items-center gap-1 text-sm">
|
||||||
|
<SectionTitle>
|
||||||
{application.creator_local_user.accepted_application
|
{application.creator_local_user.accepted_application
|
||||||
? 'Approved'
|
? 'Approved'
|
||||||
: 'Denied'} by
|
: 'Denied'} by
|
||||||
</SectionTitle>
|
</SectionTitle>
|
||||||
<UserLink avatar user={application.admin} />
|
<UserLink avatar user={application.admin} />
|
||||||
</div>
|
</div>
|
||||||
<div class="md:ml-auto" />
|
<div class="md:ml-auto" />
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<div class="ml-auto">
|
<div class="ml-auto">
|
||||||
<Button
|
<Button
|
||||||
size="square-md"
|
size="square-md"
|
||||||
class="hover:bg-slate-200 {application.creator_local_user
|
class="hover:bg-slate-200 {application.creator_local_user
|
||||||
.accepted_application === false && application.admin
|
.accepted_application === false && application.admin
|
||||||
? '!text-red-500'
|
? '!text-red-500'
|
||||||
: ''}"
|
: ''}"
|
||||||
aria-label="Deny"
|
aria-label="Deny"
|
||||||
on:click={() => review(false)/* Instead of finishing the review add a Textbox and transform the X into a "Deny"*/}
|
on:click={() => review(false)}
|
||||||
loading={denying}
|
loading={denying || reviewing}
|
||||||
disabled={approving || denying}
|
disabled={approving || denying || reviewing}
|
||||||
>
|
>
|
||||||
<Icon src={XMark} mini size="16" slot="prefix" />
|
<Icon src={XMark} mini size="16" slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="square-md"
|
size="square-md"
|
||||||
class="hover:bg-slate-200 {application.creator_local_user
|
class="hover:bg-slate-200 {application.creator_local_user
|
||||||
.accepted_application
|
.accepted_application
|
||||||
? '!text-green-500'
|
? '!text-green-500'
|
||||||
: ''}"
|
: ''}"
|
||||||
aria-label="Approve"
|
aria-label="Approve"
|
||||||
on:click={() => review(true)}
|
on:click={() => review(true)}
|
||||||
loading={approving}
|
loading={approving}
|
||||||
disabled={approving || denying}
|
disabled={approving || denying || reviewing}
|
||||||
>
|
>
|
||||||
<Icon src={Check} mini size="16" slot="prefix" />
|
<Icon src={Check} mini size="16" slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in new issue
Block a user