feat(32.2-02): My account item rows with per-row actions; connect screen docs
- AccountContributions renders a section's items as list rows (title,
subtitle, meta joined with ' · ') with one button per item action, or
the dashed empty block; sections without items render as before
- item actions confirm with :title filled as text, post to
/account/contribution-items/{name}/{item}/actions/{action}, reload and
focus the section heading; 404 toasts item_gone and reloads
- myaccount.items_empty, item_gone, item_action_named in en and pl
- docs/backend/admin-spa.md: the /connect screen and My account item rows
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { nextTick, onMounted, ref } from 'vue'
|
||||
import { Ban } from '@lucide/vue'
|
||||
import { api } from '../../api/client'
|
||||
import type { AccountContribution, AccountContributionAction } from '../../api/types'
|
||||
import { t } from '../../app/i18n'
|
||||
import type { AccountContribution, AccountContributionAction, AccountItem } from '../../api/types'
|
||||
import { interpolate, t } from '../../app/i18n'
|
||||
import Button from '../ui/Button.vue'
|
||||
import type { useConfirm } from '../ui/confirm'
|
||||
import { showToast } from '../../state/useToasts'
|
||||
@@ -13,6 +14,9 @@ import { showToast } from '../../state/useToasts'
|
||||
// applies to them; labels, descriptions, statuses and messages arrive
|
||||
// translated and render as text. Nothing renders while the list is empty.
|
||||
// Shares AccountView's useConfirm() so ConfirmDialog stays at z-[90].
|
||||
// A section with an Items function also lists the admin's rows, each with
|
||||
// its item actions (32.2 UI-SPEC C3); a section without one sends items null
|
||||
// and renders exactly as before.
|
||||
const props = defineProps<{
|
||||
confirm: ReturnType<typeof useConfirm>
|
||||
}>()
|
||||
@@ -96,6 +100,82 @@ async function post(section: AccountContribution, action: AccountContributionAct
|
||||
}
|
||||
}
|
||||
|
||||
/** The section's rows, or null for a section without an Items function. */
|
||||
function itemsOf(section: AccountContribution): AccountItem[] | null {
|
||||
return Array.isArray(section.items) ? section.items : null
|
||||
}
|
||||
|
||||
/** After an item action the row may be gone: focus moves to its section heading. */
|
||||
async function focusSection(name: string): Promise<void> {
|
||||
await nextTick()
|
||||
const card = document.querySelector<HTMLElement>(`[data-account-contribution="${CSS.escape(name)}"]`)
|
||||
card?.querySelector<HTMLElement>('h2')?.focus()
|
||||
}
|
||||
|
||||
async function postItem(section: AccountContribution, item: AccountItem, action: AccountContributionAction): Promise<void> {
|
||||
running.value = `${section.name}/${item.id}/${action.name}`
|
||||
try {
|
||||
const result = await api.POST('/account/contribution-items/{name}/{item}/actions/{action}', {
|
||||
params: { path: { name: section.name, item: item.id, action: action.name } },
|
||||
})
|
||||
if (result.data) {
|
||||
const answer = result.data.data
|
||||
showToast(answer.message || t('backend::lang.form.action_done'))
|
||||
const url = safeUrl(answer.url ?? '')
|
||||
if (url) {
|
||||
links.value = { ...links.value, [section.name]: url }
|
||||
window.open(url, '_blank', 'noopener')
|
||||
}
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
const status = result.response.status
|
||||
if (status === 404) {
|
||||
showToast(t('backend::lang.myaccount.item_gone'), 'danger')
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
if (status === 409) {
|
||||
showToast(t('backend::lang.myaccount.action_stale'), 'danger')
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
if (status === 403) {
|
||||
showToast(result.error?.error.message || t('backend::lang.list.action_forbidden'), 'danger')
|
||||
return
|
||||
}
|
||||
showToast(result.error?.error.message || t('backend::lang.extension.action_failed'), 'danger')
|
||||
} catch {
|
||||
showToast(t('backend::lang.extension.action_failed'), 'danger')
|
||||
} finally {
|
||||
running.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function runItem(section: AccountContribution, item: AccountItem, action: AccountContributionAction): Promise<void> {
|
||||
if (running.value) {
|
||||
return
|
||||
}
|
||||
if (!action.confirm && !action.danger) {
|
||||
await postItem(section, item, action)
|
||||
return
|
||||
}
|
||||
// :title is filled with the row's title as text, never as HTML.
|
||||
await props.confirm.ask(
|
||||
{
|
||||
message: action.confirm
|
||||
? interpolate(action.confirm, { title: item.title })
|
||||
: t('backend::lang.myaccount.action_confirm', { action: action.label }),
|
||||
confirmLabel: action.label,
|
||||
danger: action.danger,
|
||||
},
|
||||
() => postItem(section, item, action),
|
||||
)
|
||||
}
|
||||
|
||||
async function run(section: AccountContribution, action: AccountContributionAction): Promise<void> {
|
||||
if (running.value) {
|
||||
return
|
||||
@@ -127,13 +207,61 @@ onMounted(() => {
|
||||
class="flex flex-col gap-4 rounded-card border border-border bg-surface p-7 shadow-card"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<h2 class="text-[18px] font-bold">{{ section.label }}</h2>
|
||||
<h2 tabindex="-1" class="text-[18px] font-bold">{{ section.label }}</h2>
|
||||
<p v-if="section.description" class="max-w-[640px] text-[13px] text-muted">{{ section.description }}</p>
|
||||
</div>
|
||||
<p v-if="section.status" data-account-contribution-status class="font-medium">{{ section.status }}</p>
|
||||
<p v-if="section.error" data-account-contribution-error class="text-[13px] text-muted">
|
||||
{{ t('backend::lang.myaccount.section_error') }}
|
||||
</p>
|
||||
<template v-else-if="itemsOf(section) !== null">
|
||||
<div
|
||||
v-if="itemsOf(section)!.length > 0"
|
||||
role="list"
|
||||
data-account-items
|
||||
class="flex flex-col overflow-hidden rounded-inner border border-border"
|
||||
>
|
||||
<div
|
||||
v-for="item in itemsOf(section)!"
|
||||
:key="item.id"
|
||||
role="listitem"
|
||||
:data-account-item="item.id"
|
||||
class="flex items-start justify-between gap-4 border-t border-border px-4 py-3.5 first:border-t-0 max-sm:flex-col"
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||
<span class="font-semibold [overflow-wrap:anywhere]">{{ item.title }}</span>
|
||||
<span v-if="item.subtitle" class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ item.subtitle }}</span>
|
||||
<span
|
||||
v-if="(item.meta ?? []).length > 0"
|
||||
class="text-[13px] text-muted tabular-nums [overflow-wrap:anywhere]"
|
||||
>{{ (item.meta ?? []).join(' · ') }}</span
|
||||
>
|
||||
</div>
|
||||
<div v-if="(section.item_actions ?? []).length > 0" class="flex flex-wrap gap-2 max-sm:self-start">
|
||||
<Button
|
||||
v-for="action in section.item_actions ?? []"
|
||||
:key="action.name"
|
||||
:variant="action.danger ? 'danger' : 'outline'"
|
||||
size="sm"
|
||||
:icon="action.danger ? Ban : undefined"
|
||||
:data-account-item-action="action.name"
|
||||
:aria-label="t('backend::lang.myaccount.item_action_named', { action: action.label, title: item.title })"
|
||||
:disabled="running !== ''"
|
||||
@click="runItem(section, item, action)"
|
||||
>
|
||||
{{ action.label }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
data-account-items-empty
|
||||
class="rounded-inner border border-dashed border-border-strong px-6 py-8 text-center"
|
||||
>
|
||||
<p class="text-[13px] text-muted">{{ section.items_empty || t('backend::lang.myaccount.items_empty') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<a
|
||||
v-if="safeUrl(links[section.name] ?? '')"
|
||||
data-account-contribution-url
|
||||
|
||||
Reference in New Issue
Block a user