@openpeepshq/react 0.8.6 → 0.9.1
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/dist/components/conversations/DirectMessageSearch.d.ts +7 -0
- package/dist/components/conversations/DirectMessageSearch.js +46 -0
- package/dist/components/conversations/MessageInThread.d.ts +2 -1
- package/dist/components/conversations/MessageInThread.js +3 -3
- package/dist/components/conversations/index.d.ts +1 -0
- package/dist/components/conversations/index.js +1 -0
- package/dist/components/post/post-form/ReplyModal.js +5 -4
- package/dist/contexts/openpeeps/hooks/conversations.d.ts +3 -2
- package/dist/contexts/openpeeps/hooks/conversations.js +8 -1
- package/dist/hooks/events/useEventComposer.d.ts +1 -0
- package/dist/hooks/events/useEventComposer.js +8 -4
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/community/CommunityAccess.d.ts +6 -0
- package/dist/pages/admin/community/CommunityAccess.js +60 -0
- package/dist/pages/conversations/Index.js +17 -11
- package/dist/pages/conversations/Show.js +67 -15
- package/dist/pages/events/New.js +15 -4
- package/dist/pages/events/New.test.d.ts +1 -0
- package/dist/pages/events/New.test.js +69 -0
- package/dist/pages/index.d.ts +1 -0
- package/dist/pages/index.js +1 -0
- package/dist/pages/resources/Index.js +2 -2
- package/package.json +5 -5
- package/src/components/conversations/DirectMessageSearch.tsx +130 -0
- package/src/components/conversations/MessageInThread.tsx +9 -2
- package/src/components/conversations/index.ts +1 -0
- package/src/components/post/post-form/ReplyModal.tsx +9 -4
- package/src/contexts/openpeeps/hooks/conversations.ts +16 -3
- package/src/hooks/events/useEventComposer.ts +12 -3
- package/src/pages/admin/ConfigurationCommunity.tsx +4 -0
- package/src/pages/admin/community/CommunityAccess.tsx +129 -0
- package/src/pages/conversations/Index.tsx +51 -32
- package/src/pages/conversations/Show.tsx +106 -22
- package/src/pages/events/New.tsx +28 -5
- package/src/pages/index.ts +1 -0
- package/src/pages/resources/Index.tsx +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type DirectMessageSearchHit } from '@openpeepshq/common';
|
|
2
|
+
export declare const DirectMessageSearch: ({ conversationId, autoFocus, onQueryChange, onSelect, }: {
|
|
3
|
+
conversationId?: string;
|
|
4
|
+
autoFocus?: boolean;
|
|
5
|
+
onQueryChange?: (query: string) => void;
|
|
6
|
+
onSelect: (hit: DirectMessageSearchHit) => void;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { conversationLabel, messagePreviewText, profileName, } from '@openpeepshq/common';
|
|
4
|
+
import { Input, UpdatingDate } from '@openpeepshq/react-ui';
|
|
5
|
+
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
6
|
+
import { useT } from '../../i18n/index.js';
|
|
7
|
+
import { useCurrentProfile } from '../layout/IdentityContext.js';
|
|
8
|
+
export const DirectMessageSearch = ({ conversationId, autoFocus, onQueryChange, onSelect, }) => {
|
|
9
|
+
const t = useT();
|
|
10
|
+
const me = useCurrentProfile();
|
|
11
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
12
|
+
const [input, setInput] = useState('');
|
|
13
|
+
const [query, setQuery] = useState('');
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handle = setTimeout(() => setQuery(input.trim()), 300);
|
|
16
|
+
return () => clearTimeout(handle);
|
|
17
|
+
}, [input]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
onQueryChange?.(query);
|
|
20
|
+
}, [query, onQueryChange]);
|
|
21
|
+
const search = openpeepsApi.useSearchDirectMessages(query, conversationId);
|
|
22
|
+
const active = query.length >= 2;
|
|
23
|
+
const hits = search.data ?? [];
|
|
24
|
+
const placeholder = conversationId
|
|
25
|
+
? t('conversations.search.inConversation', {
|
|
26
|
+
defaultValue: 'Search this conversation…',
|
|
27
|
+
})
|
|
28
|
+
: t('conversations.search.placeholder', {
|
|
29
|
+
defaultValue: 'Search all messages…',
|
|
30
|
+
});
|
|
31
|
+
return (_jsxs("form", { role: "search", className: "border-border space-y-2 border-b p-3", onSubmit: (event) => event.preventDefault(), children: [_jsx(Input, { type: "search", value: input, onChange: (event) => setInput(event.target.value), placeholder: placeholder, "aria-label": placeholder, autoFocus: autoFocus, "data-testid": "dm-search-input" }), active && search.isFetching ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('conversations.search.searching', { defaultValue: 'Searching…' }) })) : null, active && search.isError ? (_jsx("p", { className: "text-destructive text-sm", children: t('conversations.search.error', { defaultValue: 'Search failed' }) })) : null, active && !search.isFetching && !search.isError && hits.length === 0 ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('conversations.search.empty', {
|
|
32
|
+
defaultValue: 'No messages match "{{query}}"',
|
|
33
|
+
query,
|
|
34
|
+
}) })) : null, active && hits.length > 0 ? (_jsx("ul", { "aria-label": t('conversations.search.results', {
|
|
35
|
+
defaultValue: 'Message search results',
|
|
36
|
+
}), className: "max-h-64 overflow-y-auto", "data-testid": "dm-search-results", children: hits.map((hit) => {
|
|
37
|
+
const senderId = hit.message.profile.id;
|
|
38
|
+
const sender = senderId === me?.id
|
|
39
|
+
? t('common.you', { defaultValue: 'You' })
|
|
40
|
+
: profileName(hit.message.profile);
|
|
41
|
+
const others = conversationLabel(hit.message, me?.id);
|
|
42
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "hover:bg-surface w-full rounded-md px-2 py-2 text-left", title: t('conversations.search.openResult', {
|
|
43
|
+
defaultValue: 'Show this message',
|
|
44
|
+
}), "data-testid": "dm-search-result", onClick: () => onSelect(hit), children: [!conversationId && others ? (_jsx("span", { className: "block truncate text-sm font-semibold", children: others })) : null, _jsxs("span", { className: "text-muted-foreground block truncate text-sm", children: [sender, ' · ', _jsx(UpdatingDate, { date: hit.message.createdAt })] }), _jsx("span", { className: "line-clamp-2 text-sm", children: messagePreviewText(hit.message) })] }) }, hit.message.id));
|
|
45
|
+
}) })) : null] }));
|
|
46
|
+
};
|
|
@@ -4,10 +4,11 @@ export interface MessageInThreadProps {
|
|
|
4
4
|
message: PublicPost;
|
|
5
5
|
multipleParticipants?: boolean;
|
|
6
6
|
conversationRootId?: string;
|
|
7
|
+
highlighted?: boolean;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Translation of `@openpeepshq/svelte` `MessageInThread.svelte`: renders a single
|
|
10
11
|
* thread message together with the participant system messages (started/added/
|
|
11
12
|
* left/removed) derived from how the audience changed between posts.
|
|
12
13
|
*/
|
|
13
|
-
export declare function MessageInThread({ previous, message, multipleParticipants, conversationRootId, }: MessageInThreadProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function MessageInThread({ previous, message, multipleParticipants, conversationRootId, highlighted, }: MessageInThreadProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { profileName } from '@openpeepshq/common';
|
|
3
3
|
import { useT } from '../../i18n/index.js';
|
|
4
4
|
import { usePostViewRef } from '../../lib/postViewCounter.js';
|
|
@@ -21,7 +21,7 @@ const audienceDiff = (previous, message) => {
|
|
|
21
21
|
* thread message together with the participant system messages (started/added/
|
|
22
22
|
* left/removed) derived from how the audience changed between posts.
|
|
23
23
|
*/
|
|
24
|
-
export function MessageInThread({ previous, message, multipleParticipants = true, conversationRootId, }) {
|
|
24
|
+
export function MessageInThread({ previous, message, multipleParticipants = true, conversationRootId, highlighted = false, }) {
|
|
25
25
|
const t = useT();
|
|
26
26
|
const me = useCurrentProfile();
|
|
27
27
|
const isUnread = isUnreadPostForViewer(message, me?.id);
|
|
@@ -35,7 +35,7 @@ export function MessageInThread({ previous, message, multipleParticipants = true
|
|
|
35
35
|
const removedOthers = removed.filter((p) => p.id !== message.profile.id);
|
|
36
36
|
const name = profileName(message.profile);
|
|
37
37
|
const isMe = message.profile.id === me?.id;
|
|
38
|
-
return (_jsxs(
|
|
38
|
+
return (_jsxs("div", { "data-message-id": message.id, className: highlighted ? 'bg-muted ring-ring rounded-md ring-2' : undefined, children: [!previous && (_jsx("div", { className: "mt-2 w-full text-center text-sm", children: message.inReplyToId
|
|
39
39
|
? t('conversations.messageInThread.addedBy', { name })
|
|
40
40
|
: t('conversations.messageInThread.startedBy', { name }) })), previous &&
|
|
41
41
|
inAudience(previous, message.profile) &&
|
|
@@ -2,6 +2,7 @@ export { CreateNewConversation } from './CreateNewConversation';
|
|
|
2
2
|
export type { CreateNewConversationProps } from './CreateNewConversation';
|
|
3
3
|
export { CreateNewConversationProvider, useCreateNewConversation, } from './CreateNewConversationContext';
|
|
4
4
|
export type { CreateConversationOptions } from './CreateNewConversationContext';
|
|
5
|
+
export { DirectMessageSearch } from './DirectMessageSearch';
|
|
5
6
|
export { DirectMessagesHeaderActions } from './DirectMessagesHeaderActions';
|
|
6
7
|
export { ConversationParticipantsModal } from './ConversationParticipantsModal';
|
|
7
8
|
export type { ConversationParticipantsModalProps } from './ConversationParticipantsModal';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CreateNewConversation } from './CreateNewConversation.js';
|
|
2
2
|
export { CreateNewConversationProvider, useCreateNewConversation, } from './CreateNewConversationContext.js';
|
|
3
|
+
export { DirectMessageSearch } from './DirectMessageSearch.js';
|
|
3
4
|
export { DirectMessagesHeaderActions } from './DirectMessagesHeaderActions.js';
|
|
4
5
|
export { ConversationParticipantsModal } from './ConversationParticipantsModal.js';
|
|
5
6
|
export { ConversationMessageBubble } from './ConversationMessageBubble.js';
|
|
@@ -5,6 +5,7 @@ import { pollOptionsWithinLimit, resolvePollOptionContents, } from '@openpeepshq
|
|
|
5
5
|
import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@openpeepshq/react-ui';
|
|
6
6
|
import { useOpenpeeps } from '../../../contexts/openpeeps/index.js';
|
|
7
7
|
import { useT } from '../../../i18n/index.js';
|
|
8
|
+
import { apiErrorMessage } from '../../../lib/apiErrorMessage.js';
|
|
8
9
|
import { useToast } from '../../layout/ToastProvider.js';
|
|
9
10
|
import { useCurrentProfile } from '../../layout/IdentityContext.js';
|
|
10
11
|
import { defaultNewNote, defaultNewQuestion, resetReplyData, useReplyStore, } from '../../../stores/newPosts.js';
|
|
@@ -137,10 +138,10 @@ export function ReplyModal({ post, onClose }) {
|
|
|
137
138
|
}));
|
|
138
139
|
onClose();
|
|
139
140
|
}
|
|
140
|
-
catch {
|
|
141
|
-
toastError(t('posts.replyModal.errorToast', {
|
|
142
|
-
defaultValue: '
|
|
143
|
-
}));
|
|
141
|
+
catch (err) {
|
|
142
|
+
toastError(apiErrorMessage(err, t, t('posts.replyModal.errorToast', {
|
|
143
|
+
defaultValue: 'An error occurred while creating the reply',
|
|
144
|
+
})));
|
|
144
145
|
}
|
|
145
146
|
finally {
|
|
146
147
|
setSubmitting(false);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { OpenpeepsClient } from '@openpeepshq/client';
|
|
2
|
-
import type { PostCreationData, PublicPost, SuccessFailureResponse, SuccessResponse } from '@openpeepshq/common';
|
|
2
|
+
import type { DirectMessageSearchHit, PostCreationData, PublicPost, SuccessFailureResponse, SuccessResponse } from '@openpeepshq/common';
|
|
3
3
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
type Query<T> = UseQueryResult<T, SuccessFailureResponse>;
|
|
5
5
|
export type ConversationHooks = {
|
|
6
6
|
useConversations: () => Query<PublicPost[][]>;
|
|
7
7
|
useArchivedConversations: () => Query<PublicPost[][]>;
|
|
8
|
-
useConversation: (id: string) => Query<PublicPost[]>;
|
|
8
|
+
useConversation: (id: string, messageId?: string) => Query<PublicPost[]>;
|
|
9
|
+
useSearchDirectMessages: (q: string, conversationId?: string) => Query<DirectMessageSearchHit[]>;
|
|
9
10
|
createConversationPostAction: (defaultPathParams?: {
|
|
10
11
|
id: string;
|
|
11
12
|
}) => (input: PostCreationData) => Promise<PublicPost>;
|
|
@@ -4,7 +4,14 @@ export const conversationHooks = (client) => ({
|
|
|
4
4
|
useArchivedConversations: () => client.conversations.archived
|
|
5
5
|
? apiHook(client.conversations.archived)
|
|
6
6
|
: { data: [], isPending: false },
|
|
7
|
-
useConversation: (id) => apiHook(client.conversations.findById, {
|
|
7
|
+
useConversation: (id, messageId) => apiHook(client.conversations.findById, {
|
|
8
|
+
pathParams: { id },
|
|
9
|
+
queryParams: messageId ? { message: messageId } : undefined,
|
|
10
|
+
}),
|
|
11
|
+
useSearchDirectMessages: (q, conversationId) => apiHook(client.conversations.search, {
|
|
12
|
+
queryParams: conversationId ? { q, conversationId } : { q },
|
|
13
|
+
enabled: q.trim().length >= 2,
|
|
14
|
+
}),
|
|
8
15
|
createConversationPostAction: payloadMutation(client.conversations.newPost, [
|
|
9
16
|
['conversations'],
|
|
10
17
|
]),
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { canAnnouncePosts, isCommunityWideVisibility, } from '@openpeepshq/common';
|
|
3
|
-
import { effectiveEventTimes, normalizeEventDataForSave, upsertEventException, } from '@openpeepshq/common/lib';
|
|
3
|
+
import { canCreatePostTypeIgnoringScopes, effectiveEventTimes, normalizeEventDataForSave, upsertEventException, } from '@openpeepshq/common/lib';
|
|
4
4
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
5
5
|
import { useNavigate } from '../../contexts/router/index.js';
|
|
6
6
|
import { useT } from '../../i18n/context.js';
|
|
7
|
-
import {
|
|
7
|
+
import { useAuthData } from '../../components/layout/IdentityContext.js';
|
|
8
8
|
import { useServerInfo } from '../../components/server-data/context.js';
|
|
9
9
|
import { eventSanitizer, getNewPostStores } from '../../stores/newPosts.js';
|
|
10
|
+
import { AUDIENCE_CHOICE_VALUES } from '../../lib/audienceChoices.js';
|
|
10
11
|
export const useNewEvent = () => {
|
|
11
12
|
const t = useT();
|
|
12
13
|
const navigate = useNavigate();
|
|
13
14
|
const serverInfo = useServerInfo();
|
|
14
|
-
const
|
|
15
|
+
const authData = useAuthData();
|
|
16
|
+
// The form only offers these audiences; other visibilities would dead-end.
|
|
17
|
+
const canCreate = canCreatePostTypeIgnoringScopes(authData, 'event', AUDIENCE_CHOICE_VALUES);
|
|
15
18
|
const { openpeepsApi } = useOpenpeeps();
|
|
16
19
|
const createPost = openpeepsApi.createPostAction();
|
|
17
20
|
const announcePost = openpeepsApi.admin.announcePostAction();
|
|
@@ -21,7 +24,7 @@ export const useNewEvent = () => {
|
|
|
21
24
|
const [notify, setNotify] = useState(false);
|
|
22
25
|
const [submitting, setSubmitting] = useState(false);
|
|
23
26
|
const [error, setError] = useState(null);
|
|
24
|
-
const showNotify = canAnnouncePosts(
|
|
27
|
+
const showNotify = canAnnouncePosts(authData.profile?.roles) &&
|
|
25
28
|
isCommunityWideVisibility(postData.visibility);
|
|
26
29
|
const event = postData.data.type === 'event' ? postData.data : null;
|
|
27
30
|
const canSubmit = !!event?.start &&
|
|
@@ -82,6 +85,7 @@ export const useNewEvent = () => {
|
|
|
82
85
|
return {
|
|
83
86
|
postData,
|
|
84
87
|
setPostData,
|
|
88
|
+
canCreate,
|
|
85
89
|
canSubmit,
|
|
86
90
|
submitting,
|
|
87
91
|
error,
|
|
@@ -3,5 +3,5 @@ import { useSetPageHeader } from '../../index.js';
|
|
|
3
3
|
import { ConfigMenuButton } from '../../components/index.js';
|
|
4
4
|
export function AdminConfigurationCommunity() {
|
|
5
5
|
useSetPageHeader('Community Customization');
|
|
6
|
-
return (_jsxs("div", { className: "p-4", children: [_jsx(ConfigMenuButton, { translationPrefix: "configuration.community.info", action: "/admin/configuration/community/info" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.favicons", action: "/admin/configuration/community/favicons" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.theme", action: "/admin/configuration/community/theme" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomePage", action: "/admin/configuration/community/welcome-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.codeOfConduct", action: "/admin/configuration/community/code-of-conduct" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomeEmail", action: "/admin/configuration/community/welcome-email" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.aboutPage", action: "/admin/configuration/community/about-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.links", action: "/admin/configuration/community/links" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.profileFields", action: "/admin/configuration/community/profile-fields" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.forbiddenUsernames", action: "/admin/configuration/community/forbidden-usernames", testId: "admin-community-forbidden-usernames" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.roles", action: "/admin/configuration/community/roles" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.language", action: "/admin/configuration/community/language" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.timezone", action: "/admin/configuration/community/timezone" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.feed", action: "/admin/configuration/community/feed" })] }));
|
|
6
|
+
return (_jsxs("div", { className: "p-4", children: [_jsx(ConfigMenuButton, { translationPrefix: "configuration.community.info", action: "/admin/configuration/community/info" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.access", action: "/admin/configuration/community/access" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.favicons", action: "/admin/configuration/community/favicons" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.theme", action: "/admin/configuration/community/theme" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomePage", action: "/admin/configuration/community/welcome-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.codeOfConduct", action: "/admin/configuration/community/code-of-conduct" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomeEmail", action: "/admin/configuration/community/welcome-email" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.aboutPage", action: "/admin/configuration/community/about-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.links", action: "/admin/configuration/community/links" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.profileFields", action: "/admin/configuration/community/profile-fields" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.forbiddenUsernames", action: "/admin/configuration/community/forbidden-usernames", testId: "admin-community-forbidden-usernames" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.roles", action: "/admin/configuration/community/roles" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.language", action: "/admin/configuration/community/language" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.timezone", action: "/admin/configuration/community/timezone" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.feed", action: "/admin/configuration/community/feed" })] }));
|
|
7
7
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open signups and public content live in the `openpeeps.core` config under
|
|
3
|
+
* `server.*`, but are surfaced here (under Community Customization) so an
|
|
4
|
+
* admin can update them without opening the raw Server settings tree editor.
|
|
5
|
+
*/
|
|
6
|
+
export declare function AdminConfigurationCommunityAccess(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import {} from '@openpeepshq/common/types';
|
|
4
|
+
import { useT, useSetPageHeader, useOpenpeeps, diffConfigTrees, } from '../../../index.js';
|
|
5
|
+
import { Label, Switch, Toast } from '@openpeepshq/react-ui';
|
|
6
|
+
/**
|
|
7
|
+
* Open signups and public content live in the `openpeeps.core` config under
|
|
8
|
+
* `server.*`, but are surfaced here (under Community Customization) so an
|
|
9
|
+
* admin can update them without opening the raw Server settings tree editor.
|
|
10
|
+
*/
|
|
11
|
+
export function AdminConfigurationCommunityAccess() {
|
|
12
|
+
const t = useT();
|
|
13
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
14
|
+
const configQuery = openpeepsApi.admin.useConfigRead('openpeeps', 'core');
|
|
15
|
+
const updateConfig = openpeepsApi.admin.updateConfigAction({
|
|
16
|
+
namespace: 'openpeeps',
|
|
17
|
+
name: 'core',
|
|
18
|
+
});
|
|
19
|
+
useSetPageHeader(t('configuration.community.access.title', { defaultValue: 'Access' }));
|
|
20
|
+
const base = configQuery.data?.config;
|
|
21
|
+
const [status, setStatus] = useState(null);
|
|
22
|
+
const signUpsOpen = base?.server?.signUpsOpen ?? true;
|
|
23
|
+
const publicContent = base?.server?.publicContent ?? false;
|
|
24
|
+
const persist = async (patch) => {
|
|
25
|
+
if (!base)
|
|
26
|
+
return;
|
|
27
|
+
setStatus(null);
|
|
28
|
+
try {
|
|
29
|
+
const diff = diffConfigTrees(base.server, patch);
|
|
30
|
+
if (Object.keys(diff).length === 0)
|
|
31
|
+
return;
|
|
32
|
+
await updateConfig({
|
|
33
|
+
config: { server: diff },
|
|
34
|
+
});
|
|
35
|
+
setStatus({
|
|
36
|
+
type: 'success',
|
|
37
|
+
message: t('configuration.community.access.updated', {
|
|
38
|
+
defaultValue: 'Access settings updated',
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
setStatus({ type: 'error', message: err.message });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
if (configQuery.isLoading || !base) {
|
|
47
|
+
return (_jsx("div", { className: "text-muted-foreground flex h-32 items-center justify-center text-sm", children: t('common.form.loading', { defaultValue: 'Loading…' }) }));
|
|
48
|
+
}
|
|
49
|
+
return (_jsxs("div", { className: "space-y-6 p-4", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: t('configuration.community.access.description', {
|
|
50
|
+
defaultValue: 'Control who can join your community and who can see it',
|
|
51
|
+
}) }), _jsx(Label, { title: t('configuration.community.openRegistrations.title', {
|
|
52
|
+
defaultValue: 'Open Signups',
|
|
53
|
+
}), description: t('configuration.community.openRegistrations.description', {
|
|
54
|
+
defaultValue: 'Allow visitors to sign up for the community',
|
|
55
|
+
}), forCheckbox: true, children: _jsx(Switch, { checked: signUpsOpen, onCheckedChange: (next) => void persist({ ...base.server, signUpsOpen: next }), "data-testid": "admin-community-access-signups" }) }), _jsx(Label, { title: t('configuration.community.publicContent.title', {
|
|
56
|
+
defaultValue: 'Public content',
|
|
57
|
+
}), description: t('configuration.community.publicContent.description', {
|
|
58
|
+
defaultValue: 'Allow visitors to read public posts without an account',
|
|
59
|
+
}), forCheckbox: true, children: _jsx(Switch, { checked: publicContent, onCheckedChange: (next) => void persist({ ...base.server, publicContent: next }), "data-testid": "admin-community-access-public-content" }) }), status ? (_jsx(Toast, { variant: status.type, testId: "admin-community-access-toast", onDismiss: () => setStatus(null), children: status.message })) : null] }));
|
|
60
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
4
|
import { MessageCircleOff, Calendar, MessageSquarePlus } from 'lucide-react';
|
|
4
5
|
import { canCreatePost, formatBadgeCount, truncateText, } from '@openpeepshq/common';
|
|
5
6
|
import { useT, useOpenpeeps, useSetPlusButtonActions, useSetPageHeader, } from '../../index.js';
|
|
6
|
-
import { Avatar, PostMarkdown, useAuthData, useCurrentProfile, useCreateNewConversation, AccessDeniedLoader, } from '../../components/index.js';
|
|
7
|
+
import { Avatar, DirectMessageSearch, PostMarkdown, useAuthData, useCurrentProfile, useCreateNewConversation, AccessDeniedLoader, } from '../../components/index.js';
|
|
7
8
|
import { UpdatingDate } from '@openpeepshq/react-ui';
|
|
8
9
|
function ChatPreview({ conversation, unreadCount = 0, }) {
|
|
9
10
|
const t = useT();
|
|
@@ -29,6 +30,7 @@ function TabButton({ onClick, className, children, }) {
|
|
|
29
30
|
}
|
|
30
31
|
export function ConversationsIndex() {
|
|
31
32
|
const t = useT();
|
|
33
|
+
const navigate = useNavigate();
|
|
32
34
|
const { openpeepsApi } = useOpenpeeps();
|
|
33
35
|
const { openCreateConversation } = useCreateNewConversation();
|
|
34
36
|
const authData = useAuthData();
|
|
@@ -38,6 +40,8 @@ export function ConversationsIndex() {
|
|
|
38
40
|
const unseenByConversation = unseenCountsQuery.data?.direct ?? {};
|
|
39
41
|
const canCreate = canCreatePost(authData, 'note', 'direct');
|
|
40
42
|
const [tab, setTab] = useState('active');
|
|
43
|
+
const [messageSearch, setMessageSearch] = useState('');
|
|
44
|
+
const searching = messageSearch.trim().length >= 2;
|
|
41
45
|
const conversations = (tab === 'active' ? query.data : archivedQuery.data) ?? [];
|
|
42
46
|
const plusButton = useMemo(() => canCreate
|
|
43
47
|
? {
|
|
@@ -58,14 +62,16 @@ export function ConversationsIndex() {
|
|
|
58
62
|
? 'border-primary border-b-2 font-semibold'
|
|
59
63
|
: 'text-muted-foreground hover:text-foreground', children: t('conversations.tabs.archived', { defaultValue: 'Archived' }) })] })), [tab, t]);
|
|
60
64
|
useSetPageHeader(t('navigation.messages', { defaultValue: 'Messages' }), headerActions, 'conversations-page-heading');
|
|
61
|
-
return (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
return (_jsxs("div", { children: [activeQuery.isError ? null : (_jsx(DirectMessageSearch, { onQueryChange: setMessageSearch, onSelect: (hit) => {
|
|
66
|
+
navigate(`/conversations/${hit.conversationId}?message=${hit.message.id}`);
|
|
67
|
+
} })), searching ? null : (_jsx(AccessDeniedLoader, { queries: [activeQuery], children: conversations.length === 0 ? (_jsxs("div", { className: "flex h-[80vh] items-center justify-center gap-2", children: [_jsx(MessageCircleOff, { size: 40 }), _jsx("p", { className: "text-muted-foreground", children: t('conversations.empty', {
|
|
68
|
+
defaultValue: 'No direct messages here',
|
|
69
|
+
}) })] })) : (_jsx("div", { children: conversations.map((conversation) => {
|
|
70
|
+
const first = conversation[0];
|
|
71
|
+
if (!first)
|
|
72
|
+
return null;
|
|
73
|
+
return (_jsx("a", { href: `/conversations/${first.id}`, className: "hover:bg-surface block text-left transition-all", title: t('conversations.open', {
|
|
74
|
+
defaultValue: 'Open conversation',
|
|
75
|
+
}), children: _jsx(ChatPreview, { conversation: conversation, unreadCount: unseenByConversation[first.id] ?? 0 }) }, first.id));
|
|
76
|
+
}) })) }))] }));
|
|
71
77
|
}
|
|
@@ -1,25 +1,46 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { useParams } from 'react-router-dom';
|
|
4
|
-
import { Info } from 'lucide-react';
|
|
3
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { Info, Search } from 'lucide-react';
|
|
5
5
|
import { useT, useOpenpeeps, useSetPageHeader, usePostViewFlush, adjustUnseenCounts, useNavigate, } from '../../index.js';
|
|
6
6
|
import { canCreatePost } from '@openpeepshq/common';
|
|
7
|
-
import { Avatar, ConversationParticipantsModal, MessageInThread, OpenpeepsMarkdownInput, ProfileCard, useAuthData, useCurrentProfile, useToast, } from '../../components/index.js';
|
|
7
|
+
import { Avatar, ConversationParticipantsModal, DirectMessageSearch, MessageInThread, OpenpeepsMarkdownInput, ProfileCard, useAuthData, useCurrentProfile, useToast, } from '../../components/index.js';
|
|
8
|
+
import { apiErrorMessage } from '../../lib/apiErrorMessage.js';
|
|
8
9
|
import { Button, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
9
10
|
const MAX_LENGTH = 500;
|
|
11
|
+
const isMessageId = (value) => !!value &&
|
|
12
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
10
13
|
export function ConversationShow() {
|
|
11
14
|
const t = useT();
|
|
12
15
|
const { id = '' } = useParams();
|
|
16
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
17
|
+
const messageParam = searchParams.get('message');
|
|
18
|
+
const focusId = isMessageId(messageParam) ? messageParam : undefined;
|
|
13
19
|
const { openpeepsApi, queryClient, client } = useOpenpeeps();
|
|
14
20
|
const me = useCurrentProfile();
|
|
15
21
|
const authData = useAuthData();
|
|
16
22
|
const toast = useToast();
|
|
17
23
|
const endRef = useRef(null);
|
|
18
|
-
const conversationQuery = openpeepsApi.useConversation(id);
|
|
24
|
+
const conversationQuery = openpeepsApi.useConversation(id, focusId);
|
|
19
25
|
const createMessage = openpeepsApi.createConversationPostAction({ id });
|
|
20
26
|
const markPostsSeen = openpeepsApi.markPostsSeenAction();
|
|
21
27
|
const flushPostViews = usePostViewFlush();
|
|
22
|
-
|
|
28
|
+
// Keep the open thread visible while a search hit refetches an older
|
|
29
|
+
// message. Switching conversations clears it so the previous thread
|
|
30
|
+
// does not linger.
|
|
31
|
+
const [shownMessages, setShownMessages] = useState([]);
|
|
32
|
+
const [shownFor, setShownFor] = useState(id);
|
|
33
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
34
|
+
if (shownFor !== id) {
|
|
35
|
+
setShownFor(id);
|
|
36
|
+
setShownMessages([]);
|
|
37
|
+
setSearchOpen(false);
|
|
38
|
+
}
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (conversationQuery.data)
|
|
41
|
+
setShownMessages(conversationQuery.data);
|
|
42
|
+
}, [conversationQuery.data]);
|
|
43
|
+
const messages = shownMessages;
|
|
23
44
|
const lastMessage = messages[messages.length - 1];
|
|
24
45
|
const participants = lastMessage?.audience?.filter((a) => a.id !== me?.id) ?? [];
|
|
25
46
|
const hasLeft = lastMessage?.profile?.id === me?.id &&
|
|
@@ -39,9 +60,16 @@ export function ConversationShow() {
|
|
|
39
60
|
return (_jsx("button", { type: "button", className: "min-w-0 truncate text-left text-xl font-semibold", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", "data-testid": "conversation-participants-open", children: participantNames }));
|
|
40
61
|
}, [multipleParticipants, participantNames, openParticipantsLabel]);
|
|
41
62
|
const navigate = useNavigate();
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
const searchLabel = searchOpen
|
|
64
|
+
? t('common.close', { defaultValue: 'Close' })
|
|
65
|
+
: t('conversations.search.toggle', {
|
|
66
|
+
defaultValue: 'Search this conversation',
|
|
67
|
+
});
|
|
68
|
+
const headerActions = useMemo(() => (_jsxs("div", { className: "flex items-center", children: [_jsx("button", { type: "button", onClick: () => setSearchOpen((open) => !open), title: searchLabel, "aria-label": searchLabel, "aria-expanded": searchOpen, "aria-controls": searchOpen ? 'conversation-message-search' : undefined, "data-testid": "conversation-search-toggle", className: `rounded-md p-1.5 ${searchOpen
|
|
69
|
+
? 'bg-muted text-foreground'
|
|
70
|
+
: 'text-muted-foreground hover:text-foreground'}`, children: _jsx(Search, { size: 18 }) }), _jsx("button", { type: "button", onClick: () => navigate({ type: 'conversation', id, view: 'info' }), title: t('conversations.info.title', {
|
|
71
|
+
defaultValue: 'Conversation info',
|
|
72
|
+
}), className: "text-muted-foreground hover:text-foreground rounded-md p-1.5", children: _jsx(Info, { size: 18 }) })] })), [id, navigate, searchLabel, searchOpen, t]);
|
|
45
73
|
useSetPageHeader(headerTitle, headerActions);
|
|
46
74
|
const [text, setText] = useState('');
|
|
47
75
|
const [sending, setSending] = useState(false);
|
|
@@ -64,18 +92,37 @@ export function ConversationShow() {
|
|
|
64
92
|
refetchType: 'all',
|
|
65
93
|
});
|
|
66
94
|
}
|
|
67
|
-
catch {
|
|
68
|
-
toast.error(t('conversations.sendError', {
|
|
95
|
+
catch (err) {
|
|
96
|
+
toast.error(apiErrorMessage(err, t, t('conversations.sendError', {
|
|
69
97
|
defaultValue: 'Failed to send message',
|
|
70
|
-
}));
|
|
98
|
+
})));
|
|
71
99
|
}
|
|
72
100
|
finally {
|
|
73
101
|
setSending(false);
|
|
74
102
|
}
|
|
75
103
|
};
|
|
76
104
|
useEffect(() => {
|
|
105
|
+
if (focusId)
|
|
106
|
+
return;
|
|
77
107
|
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
78
|
-
}, [messages.length]);
|
|
108
|
+
}, [messages.length, focusId]);
|
|
109
|
+
// The ?message= param sticks around after focusing, so scroll only the
|
|
110
|
+
// first time the message renders — re-scrolling on every messages change
|
|
111
|
+
// would fight the user while they read.
|
|
112
|
+
const scrolledToMessageRef = useRef(null);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!focusId) {
|
|
115
|
+
scrolledToMessageRef.current = null;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (scrolledToMessageRef.current === focusId)
|
|
119
|
+
return;
|
|
120
|
+
const element = document.querySelector(`[data-message-id="${focusId}"]`);
|
|
121
|
+
if (!element)
|
|
122
|
+
return;
|
|
123
|
+
scrolledToMessageRef.current = focusId;
|
|
124
|
+
element.scrollIntoView({ block: 'center' });
|
|
125
|
+
}, [focusId, messages]);
|
|
79
126
|
useEffect(() => {
|
|
80
127
|
if (!id)
|
|
81
128
|
return;
|
|
@@ -106,13 +153,18 @@ export function ConversationShow() {
|
|
|
106
153
|
return;
|
|
107
154
|
void markPostsSeen({ postIds: unseenIds });
|
|
108
155
|
}, [id, me, messages, conversationQuery.isLoading, markPostsSeen]);
|
|
109
|
-
if (conversationQuery.isLoading) {
|
|
156
|
+
if (conversationQuery.isLoading && messages.length === 0) {
|
|
110
157
|
return (_jsx("div", { className: "text-muted-foreground flex h-32 items-center justify-center text-sm", children: _jsx(LoadingSpinner, {}) }));
|
|
111
158
|
}
|
|
112
159
|
const overLimit = text.length > MAX_LENGTH;
|
|
113
|
-
return (_jsxs("div", { className: "flex h-[calc(100vh-8rem)] flex-col", children: [_jsx("header", { className: "border-b", children: participants.length === 1 && participants[0] ? (_jsx(ProfileCard, { profile: participants[0], showAction: false })) : multipleParticipants ? (_jsxs("button", { type: "button", className: "flex w-full min-w-0 items-center gap-2 p-3 text-left", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", children: [_jsx("div", { className: "flex shrink-0 -space-x-2", children: participants.slice(0, 4).map((p) => (_jsx(Avatar, { profile: p, size: 2.25, borderless: true }, p.id))) }), _jsx("div", { className: "min-w-0 truncate text-sm font-medium", children: participantNames })] })) : null }), _jsx(ConversationParticipantsModal, { open: participantsOpen, onOpenChange: setParticipantsOpen, participants: participants }),
|
|
160
|
+
return (_jsxs("div", { className: "flex h-[calc(100vh-8rem)] flex-col", children: [_jsx("header", { className: "border-b", children: participants.length === 1 && participants[0] ? (_jsx(ProfileCard, { profile: participants[0], showAction: false })) : multipleParticipants ? (_jsxs("button", { type: "button", className: "flex w-full min-w-0 items-center gap-2 p-3 text-left", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", children: [_jsx("div", { className: "flex shrink-0 -space-x-2", children: participants.slice(0, 4).map((p) => (_jsx(Avatar, { profile: p, size: 2.25, borderless: true }, p.id))) }), _jsx("div", { className: "min-w-0 truncate text-sm font-medium", children: participantNames })] })) : null }), _jsx(ConversationParticipantsModal, { open: participantsOpen, onOpenChange: setParticipantsOpen, participants: participants }), searchOpen ? (_jsx("div", { id: "conversation-message-search", children: _jsx(DirectMessageSearch, { conversationId: id, autoFocus: true, onSelect: (hit) => {
|
|
161
|
+
const next = new URLSearchParams(searchParams);
|
|
162
|
+
next.set('message', hit.message.id);
|
|
163
|
+
setSearchParams(next);
|
|
164
|
+
setSearchOpen(false);
|
|
165
|
+
} }) })) : null, _jsxs("div", { role: "log", "aria-live": "polite", "aria-label": t('conversations.messageLog', {
|
|
114
166
|
defaultValue: 'Messages',
|
|
115
|
-
}), className: "flex-1 overflow-y-auto px-3", children: [messages.map((m, index) => (_jsx(MessageInThread, { previous: messages[index - 1], message: m, multipleParticipants: multipleParticipants, conversationRootId: id }, m.id))), _jsx("div", { ref: endRef })] }), canCreate && (_jsxs("footer", { className: "space-y-2 border-t p-3", children: [_jsx(OpenpeepsMarkdownInput, { rows: 3, value: text, onChange: setText, maxLength: MAX_LENGTH, placeholder: t('conversations.placeholder', {
|
|
167
|
+
}), className: "flex-1 overflow-y-auto px-3", children: [messages.map((m, index) => (_jsx(MessageInThread, { previous: messages[index - 1], message: m, multipleParticipants: multipleParticipants, conversationRootId: id, highlighted: m.id === focusId }, m.id))), _jsx("div", { ref: endRef })] }), canCreate && (_jsxs("footer", { className: "space-y-2 border-t p-3", children: [_jsx(OpenpeepsMarkdownInput, { rows: 3, value: text, onChange: setText, maxLength: MAX_LENGTH, placeholder: t('conversations.placeholder', {
|
|
116
168
|
defaultValue: 'Write a message…',
|
|
117
169
|
}) }), _jsx("div", { className: "flex justify-end", children: _jsx(Button, { title: "Send", variant: "default", action: send, disabled: sending || !text.trim() || overLimit, children: sending
|
|
118
170
|
? t('common.sending', { defaultValue: 'Sending…' })
|
package/dist/pages/events/New.js
CHANGED
|
@@ -6,10 +6,21 @@ import { EventForm } from '../../components/index.js';
|
|
|
6
6
|
import { Button, Toast } from '@openpeepshq/react-ui';
|
|
7
7
|
export function NewEvent() {
|
|
8
8
|
const t = useT();
|
|
9
|
-
const { postData, setPostData, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewEvent();
|
|
10
|
-
const headerActions = useMemo(() =>
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const { postData, setPostData, canCreate, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewEvent();
|
|
10
|
+
const headerActions = useMemo(() => {
|
|
11
|
+
if (!canCreate)
|
|
12
|
+
return null;
|
|
13
|
+
return (_jsx(Button, { title: t('events.create.title', { defaultValue: 'Create Event' }), variant: "default", action: submit, disabled: submitting || !canSubmit, "data-testid": "events-create-submit", children: submitting
|
|
14
|
+
? t('common.submitting', { defaultValue: 'Creating…' })
|
|
15
|
+
: t('events.create.title', { defaultValue: 'Create Event' }) }));
|
|
16
|
+
}, [canCreate, canSubmit, submit, submitting, t]);
|
|
13
17
|
useSetPageHeader(t('events.create.title', { defaultValue: 'Create Event' }), headerActions);
|
|
18
|
+
if (!canCreate) {
|
|
19
|
+
return (_jsxs("div", { className: "mx-auto flex max-w-md flex-col gap-2 px-6 py-16 text-center", "data-testid": "events-create-not-allowed", role: "status", children: [_jsx("p", { className: "text-xl font-semibold", children: t('events.create.notAllowed.title', {
|
|
20
|
+
defaultValue: "You can't create events",
|
|
21
|
+
}) }), _jsx("p", { className: "text-muted-foreground text-sm", children: t('events.create.notAllowed.description', {
|
|
22
|
+
defaultValue: "Your role isn't allowed to create events. Ask a community owner or moderator if you need to host one.",
|
|
23
|
+
}) })] }));
|
|
24
|
+
}
|
|
14
25
|
return (_jsxs("div", { className: "pb-12", children: [_jsx(EventForm, { postData: postData, onChange: setPostData, showNotify: showNotify, notify: notify, onNotifyChange: setNotify }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
|
|
15
26
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { act, createElement } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { pageHeaderStore, usePageHeader } from '../../stores/pageHeader.js';
|
|
6
|
+
import { NewEvent } from './New.js';
|
|
7
|
+
const state = vi.hoisted(() => ({ canCreate: false }));
|
|
8
|
+
vi.mock('../../hooks/events/useEventComposer', () => ({
|
|
9
|
+
useNewEvent: () => ({
|
|
10
|
+
postData: { type: 'event', visibility: 'local', data: { type: 'event' } },
|
|
11
|
+
setPostData: () => undefined,
|
|
12
|
+
canCreate: state.canCreate,
|
|
13
|
+
canSubmit: true,
|
|
14
|
+
submitting: false,
|
|
15
|
+
error: null,
|
|
16
|
+
clearError: () => undefined,
|
|
17
|
+
submit: () => undefined,
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
vi.mock('../../components', () => ({
|
|
21
|
+
EventForm: () => createElement('div', { 'data-testid': 'events-form' }),
|
|
22
|
+
}));
|
|
23
|
+
vi.mock('../../index', async () => {
|
|
24
|
+
const { useSetPageHeader } = await import('../../stores/pageHeader.js');
|
|
25
|
+
const t = (key, opts) => opts?.defaultValue ?? key;
|
|
26
|
+
return { useT: () => t, useSetPageHeader };
|
|
27
|
+
});
|
|
28
|
+
const Shell = ({ children }) => {
|
|
29
|
+
const header = usePageHeader();
|
|
30
|
+
return createElement('div', null, header?.actions, children);
|
|
31
|
+
};
|
|
32
|
+
const text = (container) => container.textContent ?? '';
|
|
33
|
+
describe('NewEvent page', () => {
|
|
34
|
+
let root;
|
|
35
|
+
let container;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
38
|
+
state.canCreate = false;
|
|
39
|
+
container = document.createElement('div');
|
|
40
|
+
document.body.appendChild(container);
|
|
41
|
+
root = createRoot(container);
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
act(() => {
|
|
45
|
+
root?.unmount();
|
|
46
|
+
});
|
|
47
|
+
container?.remove();
|
|
48
|
+
pageHeaderStore.set(undefined);
|
|
49
|
+
});
|
|
50
|
+
const render = () => {
|
|
51
|
+
act(() => {
|
|
52
|
+
root?.render(createElement(Shell, null, createElement(NewEvent)));
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
it('explains the restriction before showing the form', () => {
|
|
56
|
+
render();
|
|
57
|
+
expect(text(container)).toContain("You can't create events");
|
|
58
|
+
expect(text(container)).toContain("Your role isn't allowed to create events.");
|
|
59
|
+
expect(container.querySelector('[data-testid="events-form"]')).toBeNull();
|
|
60
|
+
expect(container.querySelector('[data-testid="events-create-submit"]')).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
it('shows the form when the profile can create events', () => {
|
|
63
|
+
state.canCreate = true;
|
|
64
|
+
render();
|
|
65
|
+
expect(container.querySelector('[data-testid="events-form"]')).not.toBeNull();
|
|
66
|
+
expect(container.querySelector('[data-testid="events-create-submit"]')).not.toBeNull();
|
|
67
|
+
expect(text(container)).not.toContain("You can't create events");
|
|
68
|
+
});
|
|
69
|
+
});
|
package/dist/pages/index.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export { ConfigurationPluginPage } from './admin/ConfigurationPluginPage';
|
|
|
76
76
|
export { AdminConfigurationCommunity } from './admin/ConfigurationCommunity';
|
|
77
77
|
export { AdminConfigEditor } from './admin/ConfigEditor';
|
|
78
78
|
export { AdminConfigurationI18n } from './admin/ConfigurationI18n';
|
|
79
|
+
export { AdminConfigurationCommunityAccess } from './admin/community/CommunityAccess';
|
|
79
80
|
export { AdminConfigurationCommunityInfo } from './admin/community/CommunityInfo';
|
|
80
81
|
export { AdminConfigurationCommunityLinks } from './admin/community/CommunityLinks';
|
|
81
82
|
export { CommunityMarkdownPage } from './admin/community/CommunityMarkdownPage';
|