feat: add admin application viewing
This commit is contained in:
1 parent
bfc4ef6ffe
commit
01b4102c73
11 files changed
+199
-11
No files matched your search
@@ -23,7 +23,7 @@
|
|||||||
? 'pb-1'
|
? 'pb-1'
|
||||||
: 'bg-slate-100 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 rounded-lg p-1'
|
: 'bg-slate-100 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 rounded-lg p-1'
|
||||||
}
|
}
|
||||||
gap-2
|
gap-1
|
||||||
${$$props.class}
|
${$$props.class}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
type CardColor = 'default' | 'warning' | 'error'
|
type CardColor = 'default' | 'warning' | 'error'
|
||||||
export let cardColor: CardColor = 'default'
|
export let cardColor: CardColor = 'default'
|
||||||
|
|
||||||
|
export let elevation: 0 | 1 = 1
|
||||||
|
|
||||||
const getColor = (color: CardColor) => {
|
const getColor = (color: CardColor) => {
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case 'default':
|
case 'default':
|
||||||
return 'border border-slate-200 dark:border-zinc-800 dark:bg-zinc-900'
|
return elevation == 0
|
||||||
|
? 'border border-slate-200 dark:border-zinc-900 bg-slate-100 dark:bg-zinc-950'
|
||||||
|
: 'border border-slate-200 dark:border-zinc-800 bg-white dark:bg-zinc-900'
|
||||||
case 'warning':
|
case 'warning':
|
||||||
return 'border border-yellow-300 dark:bg-yellow-950/30 dark:border-yellow-900 bg-yellow-50'
|
return 'border border-yellow-300 dark:bg-yellow-950/30 dark:border-yellow-900 bg-yellow-50'
|
||||||
}
|
}
|
||||||
@@ -16,7 +20,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="bg-white break-words
|
class="break-words
|
||||||
{getColor(cardColor)} rounded-md {clazz}"
|
{getColor(cardColor)} rounded-md {clazz}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
>
|
>
|
||||||
<slot name="icon" />
|
<slot name="icon" />
|
||||||
{#if $$slots.title}
|
{#if $$slots.title}
|
||||||
<h1 class="font-bold text-2xl"><slot name="title" /></h1>{/if}
|
<h1 class="font-bold text-2xl"><slot name="title" /></h1>
|
||||||
|
{/if}
|
||||||
|
{#if $$slots.description}
|
||||||
|
<p><slot name="description" /></p>
|
||||||
|
{/if}
|
||||||
<slot name="action" />
|
<slot name="action" />
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<span class="text-sm font-bold text-slate-600 dark:text-zinc-400">
|
||||||
|
<slot />
|
||||||
|
</span>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4 h-full">
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
headless
|
headless
|
||||||
options={['/admin/config', '/admin/applications']}
|
options={['/admin/config', '/admin/applications']}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
hey
|
You're not supposed to be here. You somehow avoided the redirect, nice.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
|
export const load = () => {
|
||||||
|
throw redirect(300, '/admin/config')
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
|
import { searchParam } from '$lib/util.js'
|
||||||
|
import { ClipboardDocumentCheck, Icon } from 'svelte-hero-icons'
|
||||||
|
import Application from './Application.svelte'
|
||||||
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1 class="font-bold text-2xl">Applications</h1>
|
||||||
|
<MultiSelect
|
||||||
|
options={[false, true]}
|
||||||
|
selected={data.unreadOnly ?? true}
|
||||||
|
optionNames={['All', 'Unread']}
|
||||||
|
on:select={(e) =>
|
||||||
|
searchParam($page.url, 'unreadOnly', e.detail.toString(), 'page')}
|
||||||
|
/>
|
||||||
|
{#if data.applications && data.applications.length > 0}
|
||||||
|
<div class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-900">
|
||||||
|
{#each data.applications as application (application.registration_application.id)}
|
||||||
|
<Application {application} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{#if data.applications.length >= 40}
|
||||||
|
<div class="mt-auto">
|
||||||
|
<Pageination
|
||||||
|
page={data.page}
|
||||||
|
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Placeholder>
|
||||||
|
<Icon src={ClipboardDocumentCheck} size="32" slot="icon" />
|
||||||
|
<span slot="title">No applications</span>
|
||||||
|
<span slot="description">You're all caught up for now.</span>
|
||||||
|
</Placeholder>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
export async function load({ data, fetch, url }) {
|
||||||
|
if (!get(profile)) return
|
||||||
|
|
||||||
|
const { jwt } = get(profile)!
|
||||||
|
if (!jwt) return
|
||||||
|
|
||||||
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
const unreadOnly = (url.searchParams.get('unreadOnly') || 'true') == 'true'
|
||||||
|
|
||||||
|
const res = await getClient(undefined, fetch).listRegistrationApplications({
|
||||||
|
auth: jwt,
|
||||||
|
page: page,
|
||||||
|
limit: 40,
|
||||||
|
unread_only: unreadOnly,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
unreadOnly: unreadOnly,
|
||||||
|
page: page,
|
||||||
|
applications: res.registration_applications,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
|
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import type { RegistrationApplicationView } from 'lemmy-js-client'
|
||||||
|
import { Check, Icon, XMark } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let application: RegistrationApplicationView
|
||||||
|
|
||||||
|
let approving = false
|
||||||
|
let denying = false
|
||||||
|
|
||||||
|
async function review(approve: boolean) {
|
||||||
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
|
if (approve) {
|
||||||
|
approving = true
|
||||||
|
} else {
|
||||||
|
denying = true
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getClient().approveRegistrationApplication({
|
||||||
|
approve: approve,
|
||||||
|
auth: $profile.jwt,
|
||||||
|
id: application.registration_application.id,
|
||||||
|
})
|
||||||
|
toast({
|
||||||
|
content: `Successfully ${
|
||||||
|
approve ? 'approved' : 'denied'
|
||||||
|
} that application.`,
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
application.creator_local_user.accepted_application = approve
|
||||||
|
application.admin = $profile.user!.local_user_view.person
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
approving = false
|
||||||
|
denying = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card elevation={0} class="p-4 flex flex-col gap-2">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<SectionTitle>User</SectionTitle>
|
||||||
|
<span class="text-sm">
|
||||||
|
<UserLink user={application.creator} avatar avatarSize={20} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<SectionTitle>Application</SectionTitle>
|
||||||
|
<p>{application.registration_application.answer}</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col md:flex-row gap-2 md:items-center">
|
||||||
|
{#if application.admin}
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<SectionTitle>
|
||||||
|
{application.creator_local_user.accepted_application
|
||||||
|
? 'Approved'
|
||||||
|
: 'Denied'} by
|
||||||
|
</SectionTitle>
|
||||||
|
<UserLink avatar user={application.admin} />
|
||||||
|
</div>
|
||||||
|
<div class="md:ml-auto" />
|
||||||
|
{/if}
|
||||||
|
<div class="ml-auto">
|
||||||
|
<Button
|
||||||
|
size="square-md"
|
||||||
|
class="hover:bg-slate-200 {!application.creator_local_user
|
||||||
|
.accepted_application
|
||||||
|
? 'text-red-500'
|
||||||
|
: ''}"
|
||||||
|
aria-label="Deny"
|
||||||
|
on:click={() => review(false)}
|
||||||
|
loading={denying}
|
||||||
|
disabled={approving || denying}
|
||||||
|
>
|
||||||
|
<Icon src={XMark} mini size="16" slot="icon" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="square-md"
|
||||||
|
class="hover:bg-slate-200 {application.creator_local_user
|
||||||
|
.accepted_application
|
||||||
|
? 'text-green-500'
|
||||||
|
: ''}"
|
||||||
|
aria-label="Approve"
|
||||||
|
on:click={() => review(true)}
|
||||||
|
loading={approving}
|
||||||
|
disabled={approving || denying}
|
||||||
|
>
|
||||||
|
<Icon src={Check} mini size="16" slot="icon" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import { profile } from '$lib/auth.js'
|
|
||||||
import { getClient, site as siteStore } from '$lib/lemmy.js'
|
|
||||||
import { get } from 'svelte/store'
|
|
||||||
|
|
||||||
export async function load({ fetch }) {}
|
|
||||||
Reference in new issue
Block a user