@open-commune/web 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.config.ts +7 -0
- package/components/audience/audience-bar-list.vue +29 -0
- package/components/audience/audience-panel.vue +230 -0
- package/components/data/lists/data-table.vue +203 -0
- package/components/data/lists/row-actions.vue +41 -0
- package/components/elements/badges/status-badge.vue +23 -0
- package/components/elements/media/media-image.vue +26 -0
- package/components/forms/fields/input-files-media.vue +87 -0
- package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
- package/components/forms/{inputs → fields}/input-search.vue +8 -2
- package/components/forms/fields/input-text-area.vue +86 -0
- package/components/forms/fields/input-text.vue +47 -0
- package/components/forms/fields/select-enum.vue +69 -0
- package/components/forms/handlers/handler-collections.vue +100 -170
- package/components/forms/handlers/handler-list.vue +187 -0
- package/components/forms/handlers/handler-members.vue +171 -0
- package/components/forms/handlers/handler-password-reset.vue +45 -0
- package/components/forms/handlers/handler-roles.vue +28 -166
- package/components/forms/handlers/handler-sessions.vue +77 -0
- package/components/forms/handlers/handler-tokens.vue +54 -69
- package/components/forms/layouts/form-default.vue +99 -0
- package/components/forms/layouts/form.vue +4 -0
- package/components/forms/layouts/forms-layout.vue +236 -0
- package/components/forms/layouts/forms-section.vue +186 -0
- package/components/forms/layouts/layout.vue +4 -0
- package/components/forms/layouts/modal.vue +4 -0
- package/components/forms/layouts/section.vue +4 -0
- package/components/layout/shell/shell-account-menu.vue +10 -2
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-audience.ts +26 -0
- package/composables/core/domains/use-auth.ts +56 -2
- package/composables/core/domains/use-definitions.ts +18 -5
- package/composables/core/domains/use-entries.ts +125 -3
- package/composables/core/domains/use-media.ts +24 -1
- package/composables/core/domains/use-members.ts +68 -0
- package/composables/core/domains/use-organization.ts +53 -0
- package/composables/use-models.js +1 -7
- package/constants/errors.ts +29 -0
- package/constants/forms/account.ts +62 -0
- package/constants/forms/collections.ts +39 -0
- package/constants/forms/members.ts +40 -0
- package/constants/forms/organization.ts +188 -0
- package/constants/forms/tokens.ts +15 -0
- package/constants/roles.ts +57 -0
- package/constants/settings.ts +26 -0
- package/constants/statuses.ts +8 -5
- package/nuxt.config.ts +4 -1
- package/package.json +4 -3
- package/pages/[collection]/[record]/index.vue +7 -0
- package/pages/[collection]/index.vue +117 -97
- package/pages/account.vue +40 -0
- package/pages/overview.vue +106 -2
- package/pages/settings.vue +26 -181
- package/plugins/01.validation.client.ts +23 -0
- package/store/layout/workspace.js +4 -28
- package/utils/colors.ts +26 -0
- package/utils/errors.ts +13 -0
- package/utils/forms.ts +67 -0
- package/utils/list-columns.ts +90 -0
- package/utils/settings.ts +38 -0
- package/utils/statuses.ts +4 -0
- package/models/role.js +0 -66
- package/models/token.js +0 -56
- package/models/user.js +0 -97
- package/pages/management/index.vue +0 -15
- package/pages/management/members.vue +0 -176
- package/pages/management/organizations.vue +0 -192
- package/pages/management/roles.vue +0 -183
- /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<!-- Former form engine: only the record page renders it now. The settings use
|
|
2
|
+
forms-layout / forms-section / form-default and the fields under
|
|
3
|
+
components/forms/fields. Deleted with forms/inputs and forms/selects when
|
|
4
|
+
the record page is ported (A6). -->
|
|
1
5
|
<template>
|
|
2
6
|
<form class="border border-gray-200 sm:rounded-md" @submit.prevent="">
|
|
3
7
|
<div class="py-6 px-4 space-y-6 sm:p-6">
|
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
<p class="mt-0.5 truncate text-[13px] text-muted">{{ user?.email }}</p>
|
|
20
20
|
</div>
|
|
21
21
|
|
|
22
|
+
<NuxtLink
|
|
23
|
+
to="/account"
|
|
24
|
+
class="block px-4 py-2.5 text-[13px] text-highlighted hover:bg-muted"
|
|
25
|
+
@click="open = false"
|
|
26
|
+
>
|
|
27
|
+
Mon compte
|
|
28
|
+
</NuxtLink>
|
|
29
|
+
|
|
22
30
|
<button
|
|
23
31
|
type="button"
|
|
24
32
|
class="w-full cursor-pointer px-4 py-2.5 text-left text-[13px] text-error hover:bg-muted"
|
|
@@ -33,8 +41,8 @@
|
|
|
33
41
|
|
|
34
42
|
<script setup>
|
|
35
43
|
/**
|
|
36
|
-
* What concerns the signed-in person, in one place: who they are
|
|
37
|
-
* out. Help sits beside it in the header. A theme choice joins them when the
|
|
44
|
+
* What concerns the signed-in person, in one place: who they are, their account
|
|
45
|
+
* and signing out. Help sits beside it in the header. A theme choice joins them when the
|
|
38
46
|
* admin leaves the light mode it is held to (`middleware/00.light-mode.global.ts`).
|
|
39
47
|
* Without a name, the avatar's initial is the email's first letter.
|
|
40
48
|
*/
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* API tokens — what a theme's build uses to read the content.
|
|
5
|
+
*
|
|
6
|
+
* They are stored HASHED: the plaintext exists once, in the create response.
|
|
7
|
+
* A deliberate difference from the legacy, which kept them in clear and could
|
|
8
|
+
* therefore show them again.
|
|
9
|
+
*
|
|
10
|
+
* A write owns everything around it — its invalidation AND its toast, success
|
|
11
|
+
* or failure. It is a mutation factory: the screen calls it in its setup, then
|
|
12
|
+
* `mutate`, and has nothing left to write.
|
|
13
|
+
*/
|
|
14
|
+
export default function useApiTokens() {
|
|
15
|
+
const trpc = useTrpc()
|
|
16
|
+
const queryClient = useQueryClient()
|
|
17
|
+
|
|
18
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: ['api-tokens'] })
|
|
19
|
+
|
|
20
|
+
/** The tokens in service — a revoked one has no business on screen. */
|
|
21
|
+
const list = () =>
|
|
22
|
+
useQuery({
|
|
23
|
+
queryKey: ['api-tokens'],
|
|
24
|
+
queryFn: async () => (await trpc.apiTokens.list.query()).filter(({ revokedAt }) => !revokedAt),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates one, and SHOWS it.
|
|
29
|
+
*
|
|
30
|
+
* The plaintext exists ONLY in this answer: the server keeps a hash and can
|
|
31
|
+
* never give it back. So it is said at the moment it exists, said to be the
|
|
32
|
+
* only time, and the toast never expires — closing it is the agent's move,
|
|
33
|
+
* not a timer's.
|
|
34
|
+
*/
|
|
35
|
+
const create = () => {
|
|
36
|
+
const toast = useToast()
|
|
37
|
+
return useMutation({
|
|
38
|
+
mutationFn: (name: string) => trpc.apiTokens.create.mutate({ name }),
|
|
39
|
+
onSuccess: ({ token }) => {
|
|
40
|
+
invalidate()
|
|
41
|
+
toast.add({
|
|
42
|
+
color: 'success',
|
|
43
|
+
title: 'Token créé',
|
|
44
|
+
description: `${token} — copiez-le maintenant, il ne sera plus affiché.`,
|
|
45
|
+
duration: 0,
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
onError: (_error, name) => toast.add({
|
|
49
|
+
color: 'error',
|
|
50
|
+
title: `Le token « ${name} » n'a pas pu être créé`,
|
|
51
|
+
description: 'Le serveur a refusé la création. Réessayez dans un instant.',
|
|
52
|
+
}),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Revokes one, and says so either way: a refused revocation leaves a live
|
|
58
|
+
* token behind a screen that would otherwise show nothing.
|
|
59
|
+
*
|
|
60
|
+
* The NAME travels beside the id for the sentence alone — « le token » tout
|
|
61
|
+
* court ne dit pas lequel est resté actif.
|
|
62
|
+
*/
|
|
63
|
+
const revoke = () => {
|
|
64
|
+
const toast = useToast()
|
|
65
|
+
return useMutation({
|
|
66
|
+
mutationFn: ({ id }: { id: string; name: string }) => trpc.apiTokens.revoke.mutate({ id }),
|
|
67
|
+
onSuccess: (_result, { name }) => {
|
|
68
|
+
invalidate()
|
|
69
|
+
toast.add({ title: `Token « ${name} » révoqué.` })
|
|
70
|
+
},
|
|
71
|
+
onError: (_error, { name }) => toast.add({
|
|
72
|
+
color: 'error',
|
|
73
|
+
title: `Le token « ${name} » n'a pas pu être révoqué`,
|
|
74
|
+
description: 'Il reste actif. Réessayez, et prévenez un administrateur si cela persiste.',
|
|
75
|
+
}),
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { list, create, revoke }
|
|
80
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AudienceAsk } from '@open-commune/core/dtos'
|
|
2
|
+
import { keepPreviousData, useQuery } from '@tanstack/vue-query'
|
|
3
|
+
import { computed, toValue, type MaybeRefOrGetter } from 'vue'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The audience panels' data surface. The instance asks its configured source
|
|
7
|
+
* and keeps the answer a minute itself, so the cache here only spares a
|
|
8
|
+
* screen that comes back. A refusal is final: the panel hides, no retry.
|
|
9
|
+
*/
|
|
10
|
+
export default function useAudience() {
|
|
11
|
+
const trpc = useTrpc()
|
|
12
|
+
|
|
13
|
+
const summary = (ask: MaybeRefOrGetter<AudienceAsk>) =>
|
|
14
|
+
useQuery({
|
|
15
|
+
queryKey: computed(() => {
|
|
16
|
+
const { period, collection, entry } = toValue(ask)
|
|
17
|
+
return ['audience', period, collection ?? null, entry ?? null]
|
|
18
|
+
}),
|
|
19
|
+
queryFn: () => trpc.audience.summary.query(toValue(ask)),
|
|
20
|
+
placeholderData: keepPreviousData,
|
|
21
|
+
staleTime: 60_000,
|
|
22
|
+
retry: false,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return { summary }
|
|
26
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import type { PublicUser } from '@open-commune/core'
|
|
3
|
+
|
|
4
|
+
/** Prefix invalidated by every write on the sessions of this member. */
|
|
5
|
+
const SESSIONS_KEY = ['auth', 'sessions']
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
|
-
* The entrance flows that need no session
|
|
3
|
-
* a password reset, defining the new password
|
|
8
|
+
* The entrance flows that need no session (accepting an invitation, asking for
|
|
9
|
+
* a password reset, defining the new password), and what a signed-in member
|
|
10
|
+
* changes on their own account: their name, their open sessions.
|
|
4
11
|
*
|
|
5
12
|
* A write owns what surrounds it, whole: its `catch`, its `is…` pending flag,
|
|
6
13
|
* the sentence it puts on screen and the redirection that follows — none of
|
|
@@ -97,7 +104,54 @@ export default function useAuth() {
|
|
|
97
104
|
return true
|
|
98
105
|
}
|
|
99
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A member renames themself. Not their email — it identifies the account —
|
|
109
|
+
* nor their role, which the server's DTO REFUSES rather than ignores.
|
|
110
|
+
*
|
|
111
|
+
* The session carries the name shown everywhere else, so it follows here:
|
|
112
|
+
* every caller would otherwise have to remember to keep it in step.
|
|
113
|
+
*/
|
|
114
|
+
const updateOwnProfile = () =>
|
|
115
|
+
useMutation({
|
|
116
|
+
mutationFn: async (name: string): Promise<PublicUser> =>
|
|
117
|
+
(await trpc.users.updateOwnProfile.mutate({ name })).user,
|
|
118
|
+
onSuccess: (user) => { useSession().user.value = user },
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* This member's open sessions — the current one is flagged. A query and not
|
|
123
|
+
* a bare call: the list carries its own `isLoading`, and `revoke` invalidates
|
|
124
|
+
* it, so no screen reloads it by hand. Call it from a setup.
|
|
125
|
+
*/
|
|
126
|
+
const sessions = () => {
|
|
127
|
+
const queryClient = useQueryClient()
|
|
128
|
+
|
|
129
|
+
const query = useQuery({
|
|
130
|
+
queryKey: SESSIONS_KEY,
|
|
131
|
+
queryFn: () => trpc.auth.sessions.list.query(),
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
/** Closes one session remotely. The server refuses other people's. */
|
|
135
|
+
const toast = useToast()
|
|
136
|
+
const { mutate: revoke, isPending: isRevoking } = useMutation({
|
|
137
|
+
mutationFn: (id: string) => trpc.auth.sessions.revoke.mutate({ id }),
|
|
138
|
+
onSuccess: async () => {
|
|
139
|
+
await queryClient.invalidateQueries({ queryKey: SESSIONS_KEY })
|
|
140
|
+
toast.add({ title: 'Session fermée.' })
|
|
141
|
+
},
|
|
142
|
+
onError: () => toast.add({
|
|
143
|
+
color: 'error',
|
|
144
|
+
title: 'La session n\'a pas pu être fermée.',
|
|
145
|
+
description: 'Réessayez dans un instant.',
|
|
146
|
+
}),
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
return { ...query, revoke, isRevoking }
|
|
150
|
+
}
|
|
151
|
+
|
|
100
152
|
return {
|
|
153
|
+
updateOwnProfile,
|
|
154
|
+
sessions,
|
|
101
155
|
acceptInvitation,
|
|
102
156
|
isAcceptingInvitation: readonly(isAcceptingInvitation),
|
|
103
157
|
requestPasswordReset,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
2
2
|
import { buildDataSchema, type FieldDefinition } from '@open-commune/core/collections/utils'
|
|
3
|
-
import { computed, unref, type MaybeRef } from 'vue'
|
|
3
|
+
import { computed, toValue, unref, type MaybeRef, type MaybeRefOrGetter } from 'vue'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Collection-definition domain composable — the only data surface pages use.
|
|
@@ -18,15 +18,28 @@ export default function useDefinitions() {
|
|
|
18
18
|
queryFn: () => trpc.collections.list.query(),
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* One definition, by id or by slug: the server takes either. A getter is
|
|
23
|
+
* welcome, because a page is reused from one collection to the next. While
|
|
24
|
+
* it travels, the list already in cache answers, so a screen that opens on
|
|
25
|
+
* a collection the navigation has listed never waits.
|
|
26
|
+
*/
|
|
27
|
+
const get = (idOrSlug: MaybeRefOrGetter<string | undefined>) =>
|
|
22
28
|
useQuery({
|
|
23
|
-
queryKey: computed(() => ['definitions',
|
|
24
|
-
queryFn: () => trpc.collections.get.query({ idOrSlug:
|
|
29
|
+
queryKey: computed(() => ['definitions', toValue(idOrSlug)]),
|
|
30
|
+
queryFn: () => trpc.collections.get.query({ idOrSlug: toValue(idOrSlug)! }),
|
|
31
|
+
enabled: computed(() => Boolean(toValue(idOrSlug))),
|
|
32
|
+
placeholderData: () =>
|
|
33
|
+
queryClient
|
|
34
|
+
.getQueryData<Awaited<ReturnType<typeof trpc.collections.list.query>>>(['definitions'])
|
|
35
|
+
?.find(({ id, slug }) => [id, slug].includes(toValue(idOrSlug)!)),
|
|
25
36
|
})
|
|
26
37
|
|
|
38
|
+
// A write invalidates the list: the settings' collection table refreshes
|
|
39
|
+
// through its key. Call the factory in a setup, then `mutateAsync`.
|
|
27
40
|
const create = () =>
|
|
28
41
|
useMutation({
|
|
29
|
-
mutationFn: (input:
|
|
42
|
+
mutationFn: (input: Parameters<typeof trpc.collections.create.mutate>[0]) => trpc.collections.create.mutate(input),
|
|
30
43
|
onSuccess: invalidate,
|
|
31
44
|
})
|
|
32
45
|
|
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { PublicationStatus } from '@open-commune/core/collections/constants'
|
|
2
|
+
import { keepPreviousData, useInfiniteQuery, useMutation, useQueries, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
3
|
+
import { computed, toValue, unref, type MaybeRef, type MaybeRefOrGetter } from 'vue'
|
|
4
|
+
|
|
5
|
+
type ListOptions = {
|
|
6
|
+
status?: PublicationStatus[]
|
|
7
|
+
search?: string
|
|
8
|
+
skip?: number
|
|
9
|
+
limit?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** What NARROWS a listing, as opposed to what windows it. */
|
|
13
|
+
type Filters = Omit<ListOptions, 'skip' | 'limit'>
|
|
14
|
+
|
|
15
|
+
type Entry = Record<string, unknown>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The filters alone, the window dropped. The count is taken under them and
|
|
19
|
+
* only them, or the total would describe another set than the rows beside it.
|
|
20
|
+
*/
|
|
21
|
+
const filtersOf = ({ skip: _skip, limit: _limit, ...filters }: ListOptions): Filters => filters
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An entry has columns (title, slug, status…) and a bag of `data` holding the
|
|
25
|
+
* fields its collection declares. A listing sees one flat object.
|
|
26
|
+
*/
|
|
27
|
+
const flatten = (entry: Entry | null | undefined) => {
|
|
28
|
+
if (!entry) return entry
|
|
29
|
+
const { data, ...columns } = entry as { data?: Entry }
|
|
30
|
+
return { ...columns, ...data }
|
|
31
|
+
}
|
|
3
32
|
|
|
4
33
|
/**
|
|
5
34
|
* Entries domain composable. Keys: ['entries', collectionId] for lists,
|
|
@@ -14,6 +43,7 @@ export default function useEntries() {
|
|
|
14
43
|
const invalidateCollection = (collectionId: string) => {
|
|
15
44
|
queryClient.invalidateQueries({ queryKey: ['entries', collectionId] })
|
|
16
45
|
queryClient.invalidateQueries({ queryKey: ['entries', 'byId'] })
|
|
46
|
+
queryClient.invalidateQueries({ queryKey: ['entries', 'recent'] })
|
|
17
47
|
}
|
|
18
48
|
|
|
19
49
|
const list = (
|
|
@@ -30,6 +60,91 @@ export default function useEntries() {
|
|
|
30
60
|
enabled: computed(() => Boolean(unref(collectionId))),
|
|
31
61
|
})
|
|
32
62
|
|
|
63
|
+
/**
|
|
64
|
+
* A listing that grows: TanStack's infinite query holds the slices, fetches
|
|
65
|
+
* the next one, and refetches them all when a write invalidates the
|
|
66
|
+
* collection. Collection and filters are in the key, so moving either
|
|
67
|
+
* starts the window over; the rows on screen are kept while the next ones
|
|
68
|
+
* travel, which lets `isPending` mean the first load and nothing else.
|
|
69
|
+
*
|
|
70
|
+
* The total is the server's own count under the same filters, and only
|
|
71
|
+
* them, or it would describe another set than the rows beside it.
|
|
72
|
+
*/
|
|
73
|
+
const infinite = (
|
|
74
|
+
collectionId: MaybeRefOrGetter<string | undefined>,
|
|
75
|
+
options: MaybeRefOrGetter<Filters & { limit?: number }> = {},
|
|
76
|
+
) => {
|
|
77
|
+
const id = computed(() => toValue(collectionId))
|
|
78
|
+
const enabled = computed(() => Boolean(id.value))
|
|
79
|
+
const limit = computed(() => toValue(options).limit ?? 20)
|
|
80
|
+
const filters = computed(() => filtersOf(toValue(options)))
|
|
81
|
+
|
|
82
|
+
const pages = useInfiniteQuery({
|
|
83
|
+
queryKey: computed(() => ['entries', id.value, 'pages', filters.value, limit.value]),
|
|
84
|
+
queryFn: async ({ pageParam }) =>
|
|
85
|
+
(await trpc.collections.entries.list.query({
|
|
86
|
+
collectionId: id.value as string,
|
|
87
|
+
...filters.value,
|
|
88
|
+
skip: pageParam,
|
|
89
|
+
limit: limit.value,
|
|
90
|
+
})).map(flatten) as Entry[],
|
|
91
|
+
initialPageParam: 0,
|
|
92
|
+
// A slice shorter than asked is the last one.
|
|
93
|
+
getNextPageParam: (last, all) => (last.length < limit.value ? undefined : all.flat().length),
|
|
94
|
+
enabled,
|
|
95
|
+
placeholderData: keepPreviousData,
|
|
96
|
+
})
|
|
97
|
+
const counted = useQuery({
|
|
98
|
+
queryKey: computed(() => ['entries', id.value, 'count', filters.value]),
|
|
99
|
+
queryFn: () => trpc.collections.entries.count.query({ collectionId: id.value as string, ...filters.value }),
|
|
100
|
+
enabled,
|
|
101
|
+
placeholderData: keepPreviousData,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const records = computed(() => pages.data.value?.pages.flat() ?? [])
|
|
105
|
+
const total = computed(() => counted.data.value ?? null)
|
|
106
|
+
return {
|
|
107
|
+
records,
|
|
108
|
+
total,
|
|
109
|
+
isPending: computed(() => pages.isPending.value || counted.isPending.value),
|
|
110
|
+
isFetching: pages.isFetching,
|
|
111
|
+
isFetchingNextPage: pages.isFetchingNextPage,
|
|
112
|
+
// The count settles the one case the slices cannot: a total that is an
|
|
113
|
+
// exact multiple of the slice.
|
|
114
|
+
hasNextPage: computed(() => Boolean(pages.hasNextPage.value) && (total.value === null || records.value.length < total.value)),
|
|
115
|
+
fetchNextPage: pages.fetchNextPage,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Several entries by id: a relation column shows titles, the server sends
|
|
121
|
+
* ids. Same keys as `get`, so an entry is not asked for twice.
|
|
122
|
+
*/
|
|
123
|
+
const getMany = (ids: MaybeRefOrGetter<string[] | string | undefined>) => {
|
|
124
|
+
const wanted = computed(() => {
|
|
125
|
+
const value = toValue(ids)
|
|
126
|
+
return (Array.isArray(value) ? value : [value]).filter(Boolean) as string[]
|
|
127
|
+
})
|
|
128
|
+
return useQueries({
|
|
129
|
+
queries: computed(() => wanted.value.map(id => ({
|
|
130
|
+
queryKey: ['entries', 'byId', id],
|
|
131
|
+
queryFn: () => trpc.collections.entries.get.query({ id }),
|
|
132
|
+
}))),
|
|
133
|
+
combine: results => results.map(({ data }) => data).filter(Boolean) as Entry[],
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The entries last touched, whatever their collection. Under the `entries`
|
|
139
|
+
* prefix, so any write to a collection refreshes it.
|
|
140
|
+
*/
|
|
141
|
+
const recent = (limit = 5, { enabled = true } = {}) =>
|
|
142
|
+
useQuery({
|
|
143
|
+
queryKey: ['entries', 'recent', limit],
|
|
144
|
+
queryFn: () => trpc.collections.entries.recent.query({ limit }),
|
|
145
|
+
enabled,
|
|
146
|
+
})
|
|
147
|
+
|
|
33
148
|
const get = (id: MaybeRef<string>) =>
|
|
34
149
|
useQuery({
|
|
35
150
|
queryKey: computed(() => ['entries', 'byId', unref(id)]),
|
|
@@ -58,5 +173,12 @@ export default function useEntries() {
|
|
|
58
173
|
onSuccess: (_result, { collectionId }) => invalidateCollection(collectionId),
|
|
59
174
|
})
|
|
60
175
|
|
|
61
|
-
|
|
176
|
+
/** How many entries a collection holds, counted on the server. */
|
|
177
|
+
const count = (collectionId: string) =>
|
|
178
|
+
queryClient.fetchQuery({
|
|
179
|
+
queryKey: ['entries', 'count', collectionId],
|
|
180
|
+
queryFn: () => trpc.collections.entries.count.query({ collectionId }),
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
return { list, infinite, recent, get, getMany, count, create, update, remove, invalidateCollection }
|
|
62
184
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OpenCommuneEditorMedia } from '@open-commune/editor'
|
|
2
|
+
import { readonly, ref, toValue, watch, type MaybeRefOrGetter } from 'vue'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Media domain composable: tRPC calls plus the direct-to-S3 upload step.
|
|
@@ -78,5 +79,27 @@ export default function useMedia() {
|
|
|
78
79
|
/** The upload/resolve pair in the shape the editor extensions expect. */
|
|
79
80
|
const forEditor = (): OpenCommuneEditorMedia => ({ upload, fetch: resolve })
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
/**
|
|
83
|
+
* A media followed reactively: turning an id into an image took the same
|
|
84
|
+
* ref, watch and catch in every component that shows one. The source is a
|
|
85
|
+
* ref or a getter, so a thumbnail changes media without being remounted.
|
|
86
|
+
*/
|
|
87
|
+
const asset = (source: MaybeRefOrGetter<string | undefined>) => {
|
|
88
|
+
const src = ref('')
|
|
89
|
+
const title = ref('')
|
|
90
|
+
|
|
91
|
+
watch(() => toValue(source), async (id) => {
|
|
92
|
+
if (!id) {
|
|
93
|
+
src.value = title.value = ''
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
const media = await resolve({ id }).catch(() => undefined)
|
|
97
|
+
src.value = media?.src ?? ''
|
|
98
|
+
title.value = media?.title ?? ''
|
|
99
|
+
}, { immediate: true })
|
|
100
|
+
|
|
101
|
+
return { src: readonly(src), title: readonly(title) }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { upload, resolve, asset, forEditor }
|
|
82
105
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { computed, toValue, type MaybeRefOrGetter } from 'vue'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Members: who reaches this administration space, and with which role.
|
|
6
|
+
*
|
|
7
|
+
* There is no direct creation — one INVITES. The server sends the mail and
|
|
8
|
+
* returns the link, which stays the fallback when the mail does not arrive.
|
|
9
|
+
*/
|
|
10
|
+
export default function useMembers() {
|
|
11
|
+
const trpc = useTrpc()
|
|
12
|
+
const queryClient = useQueryClient()
|
|
13
|
+
|
|
14
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: ['members'] })
|
|
15
|
+
|
|
16
|
+
const list = () =>
|
|
17
|
+
useQuery({ queryKey: ['members'], queryFn: () => trpc.users.list.query() })
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Invitations sent and not yet accepted. Nothing else shows them: an invited
|
|
21
|
+
* person becomes a member only once they have opened their link.
|
|
22
|
+
*/
|
|
23
|
+
const pending = () =>
|
|
24
|
+
useQuery({
|
|
25
|
+
queryKey: ['members', 'pending'],
|
|
26
|
+
queryFn: () => trpc.invitations.list.query(),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Who is who, readable by any signed-in member: a listing shows the name of
|
|
31
|
+
* whoever last touched an entry, and the server sends an id.
|
|
32
|
+
*/
|
|
33
|
+
const directory = () =>
|
|
34
|
+
useQuery({
|
|
35
|
+
queryKey: ['members', 'directory'],
|
|
36
|
+
queryFn: () => trpc.users.directory.query(),
|
|
37
|
+
staleTime: 5 * 60 * 1000,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Writes are mutation factories: call one in a setup, then `mutateAsync`.
|
|
41
|
+
const invite = () =>
|
|
42
|
+
useMutation({
|
|
43
|
+
mutationFn: ({ email, role = 'redacteur' }: { email: string; role?: 'admin' | 'redacteur' }) =>
|
|
44
|
+
trpc.invitations.create.mutate({ email, role }),
|
|
45
|
+
onSuccess: invalidate,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const revokeInvitation = () =>
|
|
49
|
+
useMutation({
|
|
50
|
+
mutationFn: (id: string) => trpc.invitations.revoke.mutate({ id }),
|
|
51
|
+
onSuccess: invalidate,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const update = () =>
|
|
55
|
+
useMutation({
|
|
56
|
+
mutationFn: ({ id, data }: { id: string; data: { name?: string; role?: 'admin' | 'redacteur' } }) =>
|
|
57
|
+
trpc.users.update.mutate({ id, data }),
|
|
58
|
+
onSuccess: invalidate,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const remove = () =>
|
|
62
|
+
useMutation({
|
|
63
|
+
mutationFn: (id: string) => trpc.users.remove.mutate({ id }),
|
|
64
|
+
onSuccess: invalidate,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return { list, pending, directory, invite, update, remove, revokeInvitation }
|
|
68
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { useWorkspaceStore } from '~/store/layout/workspace'
|
|
3
|
+
|
|
4
|
+
/** What the settings screen may change; the rest is derived. */
|
|
5
|
+
const UPDATABLE = ['name', 'type', 'slug', 'description', 'address', 'deployment', 'settings'] as const
|
|
6
|
+
|
|
7
|
+
type Organization = Awaited<ReturnType<ReturnType<typeof useTrpc>['organization']['get']['query']>>
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The organization — there is exactly one per instance (single-tenant).
|
|
11
|
+
*
|
|
12
|
+
* The logo is stored in `settings.logo`; the settings form edits it as a field
|
|
13
|
+
* of its own, `logo`, so it is lifted out on read and put back on write.
|
|
14
|
+
*/
|
|
15
|
+
export default function useOrganization() {
|
|
16
|
+
const trpc = useTrpc()
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
|
|
19
|
+
const query = () =>
|
|
20
|
+
useQuery({
|
|
21
|
+
queryKey: ['organization'],
|
|
22
|
+
queryFn: () => trpc.organization.get.query(),
|
|
23
|
+
select: (organization: Organization) => organization && {
|
|
24
|
+
...organization,
|
|
25
|
+
logo: (organization.settings as { logo?: unknown } | null)?.logo ?? null,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/** A mutation factory: call it in a setup, then `mutateAsync(changes)`. */
|
|
30
|
+
const update = () =>
|
|
31
|
+
useMutation({
|
|
32
|
+
mutationFn: (changes: Record<string, unknown>) => {
|
|
33
|
+
const payload: Record<string, unknown> = {}
|
|
34
|
+
for (const key of UPDATABLE) {
|
|
35
|
+
if (changes[key] !== undefined) payload[key] = changes[key]
|
|
36
|
+
}
|
|
37
|
+
if (changes.logo !== undefined) {
|
|
38
|
+
const current = queryClient.getQueryData<Organization>(['organization'])
|
|
39
|
+
payload.settings = { ...(current?.settings ?? {}), ...((payload.settings as object) ?? {}), logo: changes.logo }
|
|
40
|
+
}
|
|
41
|
+
return trpc.organization.update.mutate(payload)
|
|
42
|
+
},
|
|
43
|
+
onSuccess: async () => {
|
|
44
|
+
await queryClient.invalidateQueries({ queryKey: ['organization'] })
|
|
45
|
+
// The shell still reads the organization from the Pinia store, until the
|
|
46
|
+
// store goes (A8): it is refreshed here so a new name or logo shows at once.
|
|
47
|
+
const [legacy] = await useModels().Organization.list()
|
|
48
|
+
if (legacy) useWorkspaceStore().organization = legacy
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return { query, update }
|
|
53
|
+
}
|
|
@@ -2,9 +2,6 @@ import Organization from '~/models/organization'
|
|
|
2
2
|
import Collection from '~/models/collection'
|
|
3
3
|
import Media from '~/models/media'
|
|
4
4
|
import Record from '~/models/record'
|
|
5
|
-
import Role from '~/models/role'
|
|
6
|
-
import Token from '~/models/token'
|
|
7
|
-
import User from '~/models/user'
|
|
8
5
|
|
|
9
6
|
// @review on pourrait pas déplacer le dossier models dans le dossier composables pour ajouter plus de clareté ? Aussi cette factory me semble un peu alambiquée, pourquoi a t on besoin de passer le model + api url dans un objet exporté par le model lui meme
|
|
10
7
|
// bref, je pense que qu'il y a de l'overengineering ici aussi non ?
|
|
@@ -17,9 +14,6 @@ export default () => {
|
|
|
17
14
|
Organization: new Organization.api(Organization.model, apiURL),
|
|
18
15
|
Collection: new Collection.api(Collection.model, apiURL),
|
|
19
16
|
Media: new Media.api(Media.model, apiURL),
|
|
20
|
-
Record: new Record.api(Record.model, apiURL)
|
|
21
|
-
Role: new Role.api(Role.model, apiURL),
|
|
22
|
-
Token: new Token.api(Token.model, apiURL),
|
|
23
|
-
User: new User.api(User.model, apiURL)
|
|
17
|
+
Record: new Record.api(Record.model, apiURL)
|
|
24
18
|
}
|
|
25
19
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ERROR_TYPES, type ErrorType } from '@open-commune/core/dtos';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The core's refusals, worded. A domain error travels as a `type` and never
|
|
5
|
+
* as a sentence: the core identifies, the interface says. The keys are the
|
|
6
|
+
* core's own catalogue and the record is exhaustive: a refusal the core adds
|
|
7
|
+
* stops this file compiling until it has its sentence.
|
|
8
|
+
*/
|
|
9
|
+
export const REFUSALS: Record<ErrorType, string> = {
|
|
10
|
+
[ERROR_TYPES.AUDIENCE_UNAVAILABLE]: "La fréquentation n'est pas disponible pour le moment.",
|
|
11
|
+
[ERROR_TYPES.COLLECTION_NOT_FOUND]: "Cette collection n'existe plus.",
|
|
12
|
+
[ERROR_TYPES.ENTRY_NOT_FOUND]: "Cette entrée n'existe plus.",
|
|
13
|
+
[ERROR_TYPES.INVALID_ENTRY_DATA]:
|
|
14
|
+
'Certaines valeurs ne correspondent pas aux champs de la collection.',
|
|
15
|
+
[ERROR_TYPES.DUPLICATE_SLUG]: 'Cet identifiant (slug) est déjà utilisé. Choisissez-en un autre.',
|
|
16
|
+
[ERROR_TYPES.MEDIA_NOT_FOUND]: "Ce fichier n'existe plus.",
|
|
17
|
+
[ERROR_TYPES.UNSUPPORTED_MIME]: "Ce type de fichier n'est pas accepté.",
|
|
18
|
+
[ERROR_TYPES.UPLOAD_INCOMPLETE]: "Le fichier n'a pas été reçu en entier. Réessayez.",
|
|
19
|
+
[ERROR_TYPES.ORGANIZATION_NOT_INITIALIZED]: "Cette instance n'est pas encore initialisée.",
|
|
20
|
+
[ERROR_TYPES.ORGANIZATION_ALREADY_INITIALIZED]: 'Cette instance est déjà initialisée.',
|
|
21
|
+
[ERROR_TYPES.DEPLOY_HOOK_MISSING]:
|
|
22
|
+
"La publication du site n'est pas configurée sur cette instance.",
|
|
23
|
+
[ERROR_TYPES.DEPLOY_FAILED]: 'La publication du site a échoué. Réessayez dans un instant.',
|
|
24
|
+
[ERROR_TYPES.USER_NOT_FOUND]: "Ce compte n'existe plus.",
|
|
25
|
+
[ERROR_TYPES.SESSION_NOT_FOUND]: "Cette session n'existe plus.",
|
|
26
|
+
[ERROR_TYPES.INVITATION_INVALID]: "Cette invitation n'est plus valide.",
|
|
27
|
+
[ERROR_TYPES.CANNOT_REMOVE_SELF]: 'Vous ne pouvez pas retirer votre propre compte.',
|
|
28
|
+
[ERROR_TYPES.TOO_MANY_ATTEMPTS]: 'Trop de tentatives. Réessayez dans quelques minutes.',
|
|
29
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FormTab } from '~/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The account screen, described the way the settings are — same envelope,
|
|
5
|
+
* same `forms-layout` rendering it.
|
|
6
|
+
*
|
|
7
|
+
* Three sections, two of which save nothing: they host a control managing its
|
|
8
|
+
* own data, which `noAction` already names.
|
|
9
|
+
*
|
|
10
|
+
* One TAB per section, not one tab holding three: the account has its own rail
|
|
11
|
+
* now (it left the settings on the 27/08), and a rail lists what it can reach.
|
|
12
|
+
* Stacked in a single tab, the three sections scrolled past one another and
|
|
13
|
+
* the rail had nothing to point at.
|
|
14
|
+
*/
|
|
15
|
+
export const ACCOUNT_FORM: { layout: FormTab[] } = {
|
|
16
|
+
layout: [
|
|
17
|
+
{
|
|
18
|
+
title: 'Profil',
|
|
19
|
+
sections: [
|
|
20
|
+
{
|
|
21
|
+
componentOptions: {
|
|
22
|
+
title: 'Votre nom',
|
|
23
|
+
description: 'Il apparaît dans votre menu de compte et dans la liste des membres.',
|
|
24
|
+
attributes: [
|
|
25
|
+
{
|
|
26
|
+
property: 'name',
|
|
27
|
+
component: 'input-text',
|
|
28
|
+
componentOptions: { name: 'name', label: 'Nom affiché' },
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: 'Mot de passe',
|
|
37
|
+
sections: [
|
|
38
|
+
{
|
|
39
|
+
componentOptions: {
|
|
40
|
+
title: 'Mot de passe',
|
|
41
|
+
description: 'Nous vous envoyons un lien pour en choisir un nouveau.',
|
|
42
|
+
noAction: true,
|
|
43
|
+
attributes: [{ componentOptions: {}, component: 'handler-password-reset' }],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
title: 'Appareils connectés',
|
|
50
|
+
sections: [
|
|
51
|
+
{
|
|
52
|
+
componentOptions: {
|
|
53
|
+
title: 'Appareils connectés',
|
|
54
|
+
description: 'Les sessions ouvertes avec votre compte.',
|
|
55
|
+
noAction: true,
|
|
56
|
+
attributes: [{ componentOptions: {}, component: 'handler-sessions' }],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|