@openpeepshq/react 0.8.5 → 0.9.0
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/pieces/modals/DeletePostModal.js +4 -4
- package/dist/components/post/post-form/ArticleForm.d.ts +4 -1
- package/dist/components/post/post-form/ArticleForm.js +8 -3
- package/dist/components/post/post-form/EventForm.d.ts +4 -1
- package/dist/components/post/post-form/EventForm.js +8 -4
- package/dist/components/post/post-form/NewPostModal.js +4 -5
- package/dist/components/post/post-form/OpenpeepsMarkdownInput.js +7 -1
- package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.d.ts +1 -0
- package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.js +64 -0
- 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 +3 -0
- package/dist/hooks/events/useEventComposer.js +24 -1
- package/dist/hooks/posts/useArticleComposer.d.ts +3 -0
- package/dist/hooks/posts/useArticleComposer.js +24 -1
- 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/articles/New.js +2 -2
- package/dist/pages/conversations/Index.js +17 -11
- package/dist/pages/conversations/Show.js +63 -12
- package/dist/pages/events/New.js +2 -2
- package/dist/pages/groups/Index.js +1 -1
- package/dist/pages/index.d.ts +1 -0
- package/dist/pages/index.js +1 -0
- 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/pieces/modals/DeletePostModal.tsx +11 -9
- package/src/components/post/post-form/ArticleForm.tsx +28 -1
- package/src/components/post/post-form/EventForm.tsx +28 -2
- package/src/components/post/post-form/NewPostModal.tsx +5 -11
- package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +8 -1
- package/src/contexts/openpeeps/hooks/conversations.ts +16 -3
- package/src/hooks/events/useEventComposer.ts +29 -1
- package/src/hooks/posts/useArticleComposer.ts +29 -1
- package/src/pages/admin/ConfigurationCommunity.tsx +4 -0
- package/src/pages/admin/community/CommunityAccess.tsx +129 -0
- package/src/pages/articles/New.tsx +10 -1
- package/src/pages/conversations/Index.tsx +51 -32
- package/src/pages/conversations/Show.tsx +97 -18
- package/src/pages/events/New.tsx +10 -1
- package/src/pages/groups/Index.tsx +1 -1
- package/src/pages/index.ts +1 -0
|
@@ -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';
|
|
@@ -12,11 +12,11 @@ export function DeletePostModal({ post, open, onClose, deleteCallback, }) {
|
|
|
12
12
|
deleteCallback?.();
|
|
13
13
|
onClose();
|
|
14
14
|
};
|
|
15
|
-
return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "max-w-lg overflow-x-hidden", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.deleteModal.deletePostTitle', {
|
|
15
|
+
return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "flex max-h-[90vh] max-w-lg flex-col overflow-x-hidden", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.deleteModal.deletePostTitle', {
|
|
16
16
|
defaultValue: 'Delete post',
|
|
17
|
-
}) }) }), _jsxs("article", { className: "min-w-0 overflow-x-hidden", children: [_jsx(FeedPost, { post: post, noReactionHeader: true }), _jsx("p", { className: "my-4 text-sm", children: t('posts.delete.confirm', {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
}) }) }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: _jsxs("article", { className: "min-w-0 overflow-x-hidden", children: [_jsx(FeedPost, { post: post, noReactionHeader: true }), _jsx("p", { className: "my-4 text-sm", children: t('posts.delete.confirm', {
|
|
18
|
+
defaultValue: 'Are you sure you want to delete this post?',
|
|
19
|
+
}) })] }) }), _jsx(DialogActions, { cancelLabel: t('posts.deleteModal.cancel', {
|
|
20
20
|
defaultValue: 'Cancel',
|
|
21
21
|
}), onCancel: onClose, actionLabel: t('posts.deleteModal.delete', {
|
|
22
22
|
defaultValue: 'Delete',
|
|
@@ -3,5 +3,8 @@ export interface ArticleFormProps {
|
|
|
3
3
|
postData: PostCreationData;
|
|
4
4
|
onChange: (data: PostCreationData) => void;
|
|
5
5
|
isEdit?: boolean;
|
|
6
|
+
showNotify?: boolean;
|
|
7
|
+
notify?: boolean;
|
|
8
|
+
onNotifyChange?: (value: boolean) => void;
|
|
6
9
|
}
|
|
7
|
-
export declare function ArticleForm({ postData, onChange, isEdit, }: ArticleFormProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function ArticleForm({ postData, onChange, isEdit, showNotify, notify, onNotifyChange, }: ArticleFormProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { Megaphone } from 'lucide-react';
|
|
4
|
+
import { Input, Label, Switch } from '@openpeepshq/react-ui';
|
|
4
5
|
import { useT } from '../../../i18n/index.js';
|
|
5
6
|
import { useCurrentProfile } from '../../layout/IdentityContext.js';
|
|
6
7
|
import { applyAudienceSetting } from '../../../lib/audienceSetting.js';
|
|
@@ -9,7 +10,7 @@ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
|
|
|
9
10
|
import { ComposePreviewLinks } from './ComposePreviewLinks.js';
|
|
10
11
|
import { PostAudienceSelector } from './PostAudienceSelector.js';
|
|
11
12
|
import { VisibilitySelector } from './VisibilitySelector.js';
|
|
12
|
-
export function ArticleForm({ postData, onChange, isEdit = false, }) {
|
|
13
|
+
export function ArticleForm({ postData, onChange, isEdit = false, showNotify = false, notify = false, onNotifyChange, }) {
|
|
13
14
|
const t = useT();
|
|
14
15
|
const me = useCurrentProfile();
|
|
15
16
|
const article = postData.data;
|
|
@@ -29,5 +30,9 @@ export function ArticleForm({ postData, onChange, isEdit = false, }) {
|
|
|
29
30
|
defaultValue: 'Who can see this (Required)',
|
|
30
31
|
}), description: t('articles.form.visibilityNotChangeable', {
|
|
31
32
|
defaultValue: "Once you post your article, you can't change the visibility",
|
|
32
|
-
}), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) })
|
|
33
|
+
}), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), showNotify ? (_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Megaphone, { className: "size-5" }), _jsx("p", { className: "text-base", children: t('posts.form.notifyEveryone', {
|
|
34
|
+
defaultValue: 'Notify everyone',
|
|
35
|
+
}) })] }), _jsx(Switch, { checked: notify, onCheckedChange: (checked) => onNotifyChange?.(checked), "aria-label": t('posts.form.notifyEveryone', {
|
|
36
|
+
defaultValue: 'Notify everyone',
|
|
37
|
+
}) })] })) : null] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "article", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
|
|
33
38
|
}
|
|
@@ -4,5 +4,8 @@ export interface EventFormProps {
|
|
|
4
4
|
onChange: (data: PostCreationData) => void;
|
|
5
5
|
isEdit?: boolean;
|
|
6
6
|
occurrenceEdit?: boolean;
|
|
7
|
+
showNotify?: boolean;
|
|
8
|
+
notify?: boolean;
|
|
9
|
+
onNotifyChange?: (value: boolean) => void;
|
|
7
10
|
}
|
|
8
|
-
export declare const EventForm: ({ postData, onChange, isEdit, occurrenceEdit, }: EventFormProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const EventForm: ({ postData, onChange, isEdit, occurrenceEdit, showNotify, notify, onNotifyChange, }: EventFormProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { X } from 'lucide-react';
|
|
3
|
+
import { Megaphone, X } from 'lucide-react';
|
|
4
4
|
import { EVENT_HEADER_ASPECT_RATIO, parseEventMaxAttendeesInput, parseEventWaitlistOfferMinutesInput, utcIsoToZonedDateTime, zonedDateTimeToUtcIso, } from '@openpeepshq/common/lib';
|
|
5
|
-
import { Input, Label } from '@openpeepshq/react-ui';
|
|
5
|
+
import { Input, Label, Switch } from '@openpeepshq/react-ui';
|
|
6
6
|
import { useT } from '../../../i18n/index.js';
|
|
7
7
|
import { EVENT_WEEKDAYS, useEventForm, } from '../../../hooks/events/useEventForm.js';
|
|
8
8
|
import { ImageInput } from '../../form/ImageInput.js';
|
|
@@ -16,7 +16,7 @@ const toIso = (value, timeZone) => zonedDateTimeToUtcIso(value, timeZone);
|
|
|
16
16
|
const TIMEZONES = typeof Intl !== 'undefined' && 'supportedValuesOf' in Intl
|
|
17
17
|
? Intl.supportedValuesOf('timeZone')
|
|
18
18
|
: [Intl.DateTimeFormat().resolvedOptions().timeZone];
|
|
19
|
-
export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, }) => {
|
|
19
|
+
export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, showNotify = false, notify = false, onNotifyChange, }) => {
|
|
20
20
|
const t = useT();
|
|
21
21
|
const [audienceOpen, setAudienceOpen] = useState(false);
|
|
22
22
|
const [endBeforeStart, setEndBeforeStart] = useState(false);
|
|
@@ -88,7 +88,11 @@ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit =
|
|
|
88
88
|
.join(', '),
|
|
89
89
|
}) })) : null] })) : null] })) : null, _jsx("h2", { className: "text-lg", children: t('events.form.location', { defaultValue: 'Location' }) }), _jsx(EventTypeSwitcher, { event: event, isEdit: isEdit, onChange: setEvent }), _jsx("h2", { className: "text-lg", children: t('events.form.people', { defaultValue: 'People' }) }), _jsx(Label, { title: t('events.form.visibility', { defaultValue: 'Visibility' }), description: t('events.form.visibilityNotChangeable', {
|
|
90
90
|
defaultValue: "Note: The event visibility cannot be changed once the event is published. Make sure you're adding the right people or group.",
|
|
91
|
-
}), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), _jsx(
|
|
91
|
+
}), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), showNotify ? (_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Megaphone, { className: "size-5" }), _jsx("p", { className: "text-base", children: t('posts.form.notifyEveryone', {
|
|
92
|
+
defaultValue: 'Notify everyone',
|
|
93
|
+
}) })] }), _jsx(Switch, { checked: notify, onCheckedChange: (checked) => onNotifyChange?.(checked), "aria-label": t('posts.form.notifyEveryone', {
|
|
94
|
+
defaultValue: 'Notify everyone',
|
|
95
|
+
}) })] })) : null, _jsx(Label, { description: t('events.form.attendeeListPublic', {
|
|
92
96
|
defaultValue: 'Let an attendee see others attending this event',
|
|
93
97
|
}), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: event.attendeeListPublic ?? false, onChange: (e) => patchEvent({ attendeeListPublic: e.target.checked }) }) }), _jsx(Label, { title: t('events.form.maxAttendees', {
|
|
94
98
|
defaultValue: 'Maximum attendees',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { AudioLines, ChevronDown, Image, Megaphone, Paperclip, } from 'lucide-react';
|
|
4
|
-
import {
|
|
4
|
+
import { canAnnouncePosts, isCommunityWideVisibility, pollOptionsWithinLimit, resolvePollOptionContents, } from '@openpeepshq/common';
|
|
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';
|
|
@@ -130,8 +130,8 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
|
|
|
130
130
|
groupId,
|
|
131
131
|
audience,
|
|
132
132
|
]);
|
|
133
|
-
const canNotify = useMemo(() =>
|
|
134
|
-
|
|
133
|
+
const canNotify = useMemo(() => canAnnouncePosts(me?.roles), [me?.roles]);
|
|
134
|
+
const showNotify = canNotify && isCommunityWideVisibility(visibility);
|
|
135
135
|
const selectedGroupName = useMemo(() => {
|
|
136
136
|
if (!groupId)
|
|
137
137
|
return undefined;
|
|
@@ -224,7 +224,7 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
|
|
|
224
224
|
await joinGroup({ id: targetGroupId });
|
|
225
225
|
}
|
|
226
226
|
const response = await createPost(payload);
|
|
227
|
-
if (notify &&
|
|
227
|
+
if (notify && showNotify && response?.id) {
|
|
228
228
|
await announcePost({ id: response.id });
|
|
229
229
|
}
|
|
230
230
|
if (composerType === 'question') {
|
|
@@ -254,7 +254,6 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
|
|
|
254
254
|
setSubmitting(false);
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
|
-
const showNotify = canNotify && (visibility === 'public' || visibility === 'local');
|
|
258
257
|
return (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(DialogContent, { className: "flex max-h-[90vh] max-w-xl flex-col gap-0 overflow-hidden p-0", children: [_jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-6 pb-4 pt-6", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.newPost.title', { defaultValue: 'New post' }) }) }), !group && me ? (_jsxs("button", { type: "button", title: t('posts.form.changeAudience', {
|
|
259
258
|
defaultValue: 'Change audience',
|
|
260
259
|
}), className: "hover:bg-surface rounded-button flex w-full items-center gap-3 border p-3 text-left", onClick: () => setAudienceOpen(true), children: [_jsx(Avatar, { profile: me, size: 3, borderless: true }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("span", { className: "flex items-center gap-1 font-medium capitalize", children: [me.displayName ?? me.handle, _jsx(ChevronDown, { className: "text-muted-foreground size-4" })] }), _jsx("span", { className: "text-muted-foreground text-sm", children: visibility === 'direct' && audience.length > 0 ? (_jsx("span", { className: "flex flex-wrap gap-1", children: audience.map((profile) => (_jsx(ProfileBadge, { profile: profile }, profile.id))) })) : (audienceSummary(visibility, t, selectedGroupName, audience.length)) })] })] })) : null, _jsx(OpenpeepsMarkdownInput, { rows: 5, value: content, onChange: setContent, testId: "posts-composer-content", placeholder: composerType === 'question'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Button, Popover, PopoverAnchor, PopoverContent, Textarea, cn, } from '@openpeepshq/react-ui';
|
|
4
4
|
import { useT } from '../../../i18n/index.js';
|
|
5
5
|
import { useOpenpeeps } from '../../../contexts/openpeeps/index.js';
|
|
@@ -17,6 +17,12 @@ export function OpenpeepsMarkdownInput({ value, onChange, maxLength = 500, place
|
|
|
17
17
|
const [open, setOpen] = useState(false);
|
|
18
18
|
const [showPreview, setShowPreview] = useState(false);
|
|
19
19
|
const textareaRef = useRef(null);
|
|
20
|
+
// Preview is local state. Clearing the text after send has to leave an
|
|
21
|
+
// editable field, not the preview overlay.
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
if (value.length === 0)
|
|
24
|
+
setShowPreview(false);
|
|
25
|
+
}, [value]);
|
|
20
26
|
const anchorRef = useRef(null);
|
|
21
27
|
const profilesQuery = openpeepsApi.useSearchProfiles(query);
|
|
22
28
|
const profiles = useMemo(() => (profilesQuery.data?.pages ?? [])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
|
|
6
|
+
vi.mock('../../../i18n', () => ({
|
|
7
|
+
useT: () => (key, opts) => opts?.defaultValue ?? key,
|
|
8
|
+
}));
|
|
9
|
+
vi.mock('../../../contexts/openpeeps', () => ({
|
|
10
|
+
useOpenpeeps: () => ({
|
|
11
|
+
openpeepsApi: {
|
|
12
|
+
useSearchProfiles: () => ({ data: undefined }),
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('../../markdown', () => ({
|
|
17
|
+
OpenpeepsMarkdown: ({ source }) => createElement('div', { 'data-testid': 'markdown-preview' }, source),
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('../../profile', () => ({
|
|
20
|
+
ProfileCard: () => null,
|
|
21
|
+
}));
|
|
22
|
+
const renderInput = (root, props) => {
|
|
23
|
+
act(() => {
|
|
24
|
+
root.render(createElement(OpenpeepsMarkdownInput, props));
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
describe('OpenpeepsMarkdownInput', () => {
|
|
28
|
+
let root;
|
|
29
|
+
let container;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
act(() => {
|
|
35
|
+
root?.unmount();
|
|
36
|
+
});
|
|
37
|
+
container?.remove();
|
|
38
|
+
root = undefined;
|
|
39
|
+
container = undefined;
|
|
40
|
+
});
|
|
41
|
+
const mount = () => {
|
|
42
|
+
container = document.createElement('div');
|
|
43
|
+
document.body.appendChild(container);
|
|
44
|
+
root = createRoot(container);
|
|
45
|
+
return { container, root };
|
|
46
|
+
};
|
|
47
|
+
it('returns to the empty editor after the text is cleared from preview', async () => {
|
|
48
|
+
const { container, root } = mount();
|
|
49
|
+
const onChange = vi.fn();
|
|
50
|
+
renderInput(root, { value: '[TEST] `code` check', onChange });
|
|
51
|
+
const preview = [...container.querySelectorAll('button')].find((button) => button.textContent === 'Preview');
|
|
52
|
+
expect(preview).toBeTruthy();
|
|
53
|
+
await act(async () => {
|
|
54
|
+
preview?.click();
|
|
55
|
+
});
|
|
56
|
+
expect(container.textContent).toContain('Back to Editing');
|
|
57
|
+
expect(container.querySelector('[data-testid="markdown-preview"]')?.textContent).toBe('[TEST] `code` check');
|
|
58
|
+
renderInput(root, { value: '', onChange });
|
|
59
|
+
expect(container.textContent).not.toContain('Back to Editing');
|
|
60
|
+
const textarea = container.querySelector('textarea');
|
|
61
|
+
expect(textarea).toBeTruthy();
|
|
62
|
+
expect(textarea?.value).toBe('');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -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
|
]),
|
|
@@ -364,6 +364,9 @@ export declare const useNewEvent: () => {
|
|
|
364
364
|
submitting: boolean;
|
|
365
365
|
error: string | null;
|
|
366
366
|
clearError: () => void;
|
|
367
|
+
notify: boolean;
|
|
368
|
+
setNotify: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
369
|
+
showNotify: boolean;
|
|
367
370
|
submit: () => Promise<void>;
|
|
368
371
|
};
|
|
369
372
|
export declare const useEditEvent: (eventId: string, occurrence?: string) => {
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { canAnnouncePosts, isCommunityWideVisibility, } from '@openpeepshq/common';
|
|
2
3
|
import { effectiveEventTimes, normalizeEventDataForSave, upsertEventException, } from '@openpeepshq/common/lib';
|
|
3
4
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
4
5
|
import { useNavigate } from '../../contexts/router/index.js';
|
|
5
6
|
import { useT } from '../../i18n/context.js';
|
|
7
|
+
import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
|
|
6
8
|
import { useServerInfo } from '../../components/server-data/context.js';
|
|
7
9
|
import { eventSanitizer, getNewPostStores } from '../../stores/newPosts.js';
|
|
8
10
|
export const useNewEvent = () => {
|
|
9
11
|
const t = useT();
|
|
10
12
|
const navigate = useNavigate();
|
|
11
13
|
const serverInfo = useServerInfo();
|
|
14
|
+
const me = useCurrentProfile();
|
|
12
15
|
const { openpeepsApi } = useOpenpeeps();
|
|
13
16
|
const createPost = openpeepsApi.createPostAction();
|
|
17
|
+
const announcePost = openpeepsApi.admin.announcePostAction();
|
|
14
18
|
const stores = getNewPostStores();
|
|
15
19
|
const sanitize = useMemo(() => eventSanitizer(serverInfo.publicContent), [serverInfo.publicContent]);
|
|
16
20
|
const [postData, setPostDataState] = useState(() => sanitize(stores.event));
|
|
21
|
+
const [notify, setNotify] = useState(false);
|
|
17
22
|
const [submitting, setSubmitting] = useState(false);
|
|
18
23
|
const [error, setError] = useState(null);
|
|
24
|
+
const showNotify = canAnnouncePosts(me?.roles) &&
|
|
25
|
+
isCommunityWideVisibility(postData.visibility);
|
|
19
26
|
const event = postData.data.type === 'event' ? postData.data : null;
|
|
20
27
|
const canSubmit = !!event?.start &&
|
|
21
28
|
!!event?.name?.trim() &&
|
|
@@ -49,6 +56,9 @@ export const useNewEvent = () => {
|
|
|
49
56
|
type: 'event',
|
|
50
57
|
data: normalizeEventDataForSave(event),
|
|
51
58
|
});
|
|
59
|
+
if (notify && showNotify && created.id) {
|
|
60
|
+
await announcePost({ id: created.id });
|
|
61
|
+
}
|
|
52
62
|
stores.resetNewEventState();
|
|
53
63
|
navigate({ type: 'post', id: created.id });
|
|
54
64
|
}
|
|
@@ -58,7 +68,17 @@ export const useNewEvent = () => {
|
|
|
58
68
|
finally {
|
|
59
69
|
setSubmitting(false);
|
|
60
70
|
}
|
|
61
|
-
}, [
|
|
71
|
+
}, [
|
|
72
|
+
announcePost,
|
|
73
|
+
createPost,
|
|
74
|
+
event,
|
|
75
|
+
navigate,
|
|
76
|
+
notify,
|
|
77
|
+
postData,
|
|
78
|
+
showNotify,
|
|
79
|
+
stores,
|
|
80
|
+
t,
|
|
81
|
+
]);
|
|
62
82
|
return {
|
|
63
83
|
postData,
|
|
64
84
|
setPostData,
|
|
@@ -66,6 +86,9 @@ export const useNewEvent = () => {
|
|
|
66
86
|
submitting,
|
|
67
87
|
error,
|
|
68
88
|
clearError: () => setError(null),
|
|
89
|
+
notify,
|
|
90
|
+
setNotify,
|
|
91
|
+
showNotify,
|
|
69
92
|
submit,
|
|
70
93
|
};
|
|
71
94
|
};
|
|
@@ -364,6 +364,9 @@ export declare const useNewArticle: () => {
|
|
|
364
364
|
submitting: boolean;
|
|
365
365
|
error: string | null;
|
|
366
366
|
clearError: () => void;
|
|
367
|
+
notify: boolean;
|
|
368
|
+
setNotify: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
369
|
+
showNotify: boolean;
|
|
367
370
|
submit: () => Promise<void>;
|
|
368
371
|
};
|
|
369
372
|
export declare const useEditArticle: (articleId: string) => {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { canAnnouncePosts, isCommunityWideVisibility, } from '@openpeepshq/common';
|
|
2
3
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
3
4
|
import { useNavigate } from '../../contexts/router/index.js';
|
|
4
5
|
import { useT } from '../../i18n/context.js';
|
|
6
|
+
import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
|
|
5
7
|
import { useServerInfo } from '../../components/server-data/index.js';
|
|
6
8
|
import { defaultNewArticle, getNewPostStores } from '../../stores/index.js';
|
|
7
9
|
export const useNewArticle = () => {
|
|
8
10
|
const t = useT();
|
|
9
11
|
const navigate = useNavigate();
|
|
10
12
|
const serverInfo = useServerInfo();
|
|
13
|
+
const me = useCurrentProfile();
|
|
11
14
|
const { openpeepsApi } = useOpenpeeps();
|
|
12
15
|
const createPost = openpeepsApi.createPostAction();
|
|
16
|
+
const announcePost = openpeepsApi.admin.announcePostAction();
|
|
13
17
|
const stores = getNewPostStores();
|
|
14
18
|
const [postData, setPostDataState] = useState(() => {
|
|
15
19
|
const stored = stores.article;
|
|
@@ -18,8 +22,11 @@ export const useNewArticle = () => {
|
|
|
18
22
|
}
|
|
19
23
|
return defaultNewArticle(serverInfo.publicContent);
|
|
20
24
|
});
|
|
25
|
+
const [notify, setNotify] = useState(false);
|
|
21
26
|
const [submitting, setSubmitting] = useState(false);
|
|
22
27
|
const [error, setError] = useState(null);
|
|
28
|
+
const showNotify = canAnnouncePosts(me?.roles) &&
|
|
29
|
+
isCommunityWideVisibility(postData.visibility);
|
|
23
30
|
const article = postData.data.type === 'article' ? postData.data : null;
|
|
24
31
|
const canSubmit = !!article?.title?.trim() &&
|
|
25
32
|
!(postData.visibility === 'direct' && !postData.audience?.length);
|
|
@@ -42,6 +49,9 @@ export const useNewArticle = () => {
|
|
|
42
49
|
setSubmitting(true);
|
|
43
50
|
try {
|
|
44
51
|
const created = await createPost({ ...postData, type: 'article' });
|
|
52
|
+
if (notify && showNotify && created.id) {
|
|
53
|
+
await announcePost({ id: created.id });
|
|
54
|
+
}
|
|
45
55
|
stores.resetNewArticleState();
|
|
46
56
|
navigate({ type: 'post', id: created.id });
|
|
47
57
|
}
|
|
@@ -51,7 +61,17 @@ export const useNewArticle = () => {
|
|
|
51
61
|
finally {
|
|
52
62
|
setSubmitting(false);
|
|
53
63
|
}
|
|
54
|
-
}, [
|
|
64
|
+
}, [
|
|
65
|
+
announcePost,
|
|
66
|
+
article,
|
|
67
|
+
createPost,
|
|
68
|
+
navigate,
|
|
69
|
+
notify,
|
|
70
|
+
postData,
|
|
71
|
+
showNotify,
|
|
72
|
+
stores,
|
|
73
|
+
t,
|
|
74
|
+
]);
|
|
55
75
|
return {
|
|
56
76
|
postData,
|
|
57
77
|
setPostData,
|
|
@@ -59,6 +79,9 @@ export const useNewArticle = () => {
|
|
|
59
79
|
submitting,
|
|
60
80
|
error,
|
|
61
81
|
clearError: () => setError(null),
|
|
82
|
+
notify,
|
|
83
|
+
setNotify,
|
|
84
|
+
showNotify,
|
|
62
85
|
submit,
|
|
63
86
|
};
|
|
64
87
|
};
|
|
@@ -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
|
+
}
|