@openpeepshq/react 0.8.5 → 0.8.6

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.
Files changed (27) hide show
  1. package/dist/components/post/pieces/modals/DeletePostModal.js +4 -4
  2. package/dist/components/post/post-form/ArticleForm.d.ts +4 -1
  3. package/dist/components/post/post-form/ArticleForm.js +8 -3
  4. package/dist/components/post/post-form/EventForm.d.ts +4 -1
  5. package/dist/components/post/post-form/EventForm.js +8 -4
  6. package/dist/components/post/post-form/NewPostModal.js +4 -5
  7. package/dist/components/post/post-form/OpenpeepsMarkdownInput.js +7 -1
  8. package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.d.ts +1 -0
  9. package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.js +64 -0
  10. package/dist/hooks/events/useEventComposer.d.ts +3 -0
  11. package/dist/hooks/events/useEventComposer.js +24 -1
  12. package/dist/hooks/posts/useArticleComposer.d.ts +3 -0
  13. package/dist/hooks/posts/useArticleComposer.js +24 -1
  14. package/dist/pages/articles/New.js +2 -2
  15. package/dist/pages/events/New.js +2 -2
  16. package/dist/pages/groups/Index.js +1 -1
  17. package/package.json +3 -3
  18. package/src/components/post/pieces/modals/DeletePostModal.tsx +11 -9
  19. package/src/components/post/post-form/ArticleForm.tsx +28 -1
  20. package/src/components/post/post-form/EventForm.tsx +28 -2
  21. package/src/components/post/post-form/NewPostModal.tsx +5 -11
  22. package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +8 -1
  23. package/src/hooks/events/useEventComposer.ts +29 -1
  24. package/src/hooks/posts/useArticleComposer.ts +29 -1
  25. package/src/pages/articles/New.tsx +10 -1
  26. package/src/pages/events/New.tsx +10 -1
  27. package/src/pages/groups/Index.tsx +1 -1
@@ -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
- defaultValue: 'Are you sure you want to delete this post?',
19
- }) })] }), _jsx(DialogActions, { cancelLabel: t('posts.deleteModal.cancel', {
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 { Input, Label } from '@openpeepshq/react-ui';
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 }) })] }), !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
+ }), 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(Label, { description: t('events.form.attendeeListPublic', {
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 { checkRoleCapabilities, pollOptionsWithinLimit, resolvePollOptionContents, } from '@openpeepshq/common';
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(() => checkRoleCapabilities(me?.roles ?? [], ['allpeep-core-admin-notify'])
134
- .success, [me?.roles]);
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 && canNotify && response?.id) {
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,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
+ });
@@ -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
- }, [createPost, event, navigate, postData, stores, t]);
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
- }, [article, createPost, navigate, postData, stores, t]);
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
  };
@@ -6,10 +6,10 @@ import { useNewArticle } from '../../hooks/index.js';
6
6
  import { Button, Toast } from '@openpeepshq/react-ui';
7
7
  export function NewArticle() {
8
8
  const t = useT();
9
- const { postData, setPostData, canSubmit, submitting, error, clearError, submit, } = useNewArticle();
9
+ const { postData, setPostData, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewArticle();
10
10
  const headerActions = useMemo(() => (_jsx(Button, { title: t('articles.create.title', { defaultValue: 'Create article' }), variant: "default", action: submit, disabled: submitting || !canSubmit, children: submitting
11
11
  ? t('common.submitting', { defaultValue: 'Publishing…' })
12
12
  : t('articles.create.title', { defaultValue: 'Create article' }) })), [canSubmit, submit, submitting, t]);
13
13
  useSetPageHeader(t('articles.new', { defaultValue: 'New article' }), headerActions);
14
- return (_jsxs("div", { className: "pb-12", children: [_jsx(ArticleForm, { postData: postData, onChange: setPostData }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
14
+ return (_jsxs("div", { className: "pb-12", children: [_jsx(ArticleForm, { 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
15
  }
@@ -6,10 +6,10 @@ 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, submit, } = useNewEvent();
9
+ const { postData, setPostData, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewEvent();
10
10
  const headerActions = useMemo(() => (_jsx(Button, { title: t('events.create.title', { defaultValue: 'Create Event' }), variant: "default", action: submit, disabled: submitting || !canSubmit, "data-testid": "events-create-submit", children: submitting
11
11
  ? t('common.submitting', { defaultValue: 'Creating…' })
12
12
  : t('events.create.title', { defaultValue: 'Create Event' }) })), [canSubmit, submit, submitting, t]);
13
13
  useSetPageHeader(t('events.create.title', { defaultValue: 'Create Event' }), headerActions);
14
- return (_jsxs("div", { className: "pb-12", children: [_jsx(EventForm, { postData: postData, onChange: setPostData }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
14
+ 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
15
  }
@@ -23,7 +23,7 @@ export function GroupsIndex() {
23
23
  const canCreate = canCreateGroup(currentProfile?.roles ?? []);
24
24
  const plusButton = useMemo(() => canCreate
25
25
  ? {
26
- title: t('groups.new', { defaultValue: 'New Group' }),
26
+ title: t('groups.new.label', { defaultValue: 'New Group' }),
27
27
  icon: Plus,
28
28
  action: '/groups/new',
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/react",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "simple-icons": "^16.31.0",
53
53
  "uuidv7": "^1.0.2",
54
54
  "@openpeepshq/client": "^0.2.1",
55
+ "@openpeepshq/common": "^0.4.0",
55
56
  "@openpeepshq/greenscreen": "^0.2.1",
56
- "@openpeepshq/react-ui": "^0.4.1",
57
- "@openpeepshq/common": "^0.4.0"
57
+ "@openpeepshq/react-ui": "^0.4.1"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": "^18.3.0 || ^19.0.0",
@@ -35,7 +35,7 @@ export function DeletePostModal({
35
35
 
36
36
  return (
37
37
  <Dialog open={open} onOpenChange={(next) => !next && onClose()}>
38
- <DialogContent className="max-w-lg overflow-x-hidden">
38
+ <DialogContent className="flex max-h-[90vh] max-w-lg flex-col overflow-x-hidden">
39
39
  <DialogHeader>
40
40
  <DialogTitle>
41
41
  {t('posts.deleteModal.deletePostTitle', {
@@ -43,14 +43,16 @@ export function DeletePostModal({
43
43
  })}
44
44
  </DialogTitle>
45
45
  </DialogHeader>
46
- <article className="min-w-0 overflow-x-hidden">
47
- <FeedPost post={post} noReactionHeader />
48
- <p className="my-4 text-sm">
49
- {t('posts.delete.confirm', {
50
- defaultValue: 'Are you sure you want to delete this post?',
51
- })}
52
- </p>
53
- </article>
46
+ <div className="min-h-0 flex-1 overflow-y-auto">
47
+ <article className="min-w-0 overflow-x-hidden">
48
+ <FeedPost post={post} noReactionHeader />
49
+ <p className="my-4 text-sm">
50
+ {t('posts.delete.confirm', {
51
+ defaultValue: 'Are you sure you want to delete this post?',
52
+ })}
53
+ </p>
54
+ </article>
55
+ </div>
54
56
  <DialogActions
55
57
  cancelLabel={t('posts.deleteModal.cancel', {
56
58
  defaultValue: 'Cancel',
@@ -1,10 +1,11 @@
1
1
  import { useState } from 'react';
2
+ import { Megaphone } from 'lucide-react';
2
3
  import type {
3
4
  Article,
4
5
  AudienceSetting,
5
6
  PostCreationData,
6
7
  } from '@openpeepshq/common/types';
7
- import { Input, Label } from '@openpeepshq/react-ui';
8
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
8
9
  import { useT } from '../../../i18n';
9
10
  import { useCurrentProfile } from '../../layout/IdentityContext';
10
11
  import { applyAudienceSetting } from '../../../lib/audienceSetting';
@@ -18,12 +19,18 @@ export interface ArticleFormProps {
18
19
  postData: PostCreationData;
19
20
  onChange: (data: PostCreationData) => void;
20
21
  isEdit?: boolean;
22
+ showNotify?: boolean;
23
+ notify?: boolean;
24
+ onNotifyChange?: (value: boolean) => void;
21
25
  }
22
26
 
23
27
  export function ArticleForm({
24
28
  postData,
25
29
  onChange,
26
30
  isEdit = false,
31
+ showNotify = false,
32
+ notify = false,
33
+ onNotifyChange,
27
34
  }: ArticleFormProps) {
28
35
  const t = useT();
29
36
  const me = useCurrentProfile();
@@ -100,6 +107,26 @@ export function ArticleForm({
100
107
  showDirect
101
108
  />
102
109
  </Label>
110
+
111
+ {showNotify ? (
112
+ <div className="flex w-full items-center justify-between">
113
+ <div className="flex items-center gap-2">
114
+ <Megaphone className="size-5" />
115
+ <p className="text-base">
116
+ {t('posts.form.notifyEveryone', {
117
+ defaultValue: 'Notify everyone',
118
+ })}
119
+ </p>
120
+ </div>
121
+ <Switch
122
+ checked={notify}
123
+ onCheckedChange={(checked) => onNotifyChange?.(checked)}
124
+ aria-label={t('posts.form.notifyEveryone', {
125
+ defaultValue: 'Notify everyone',
126
+ })}
127
+ />
128
+ </div>
129
+ ) : null}
103
130
  </div>
104
131
 
105
132
  {!isEdit ? (
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { X } from 'lucide-react';
2
+ import { Megaphone, X } from 'lucide-react';
3
3
  import type {
4
4
  PostCreationData,
5
5
  RecurrenceFreq,
@@ -11,7 +11,7 @@ import {
11
11
  utcIsoToZonedDateTime,
12
12
  zonedDateTimeToUtcIso,
13
13
  } from '@openpeepshq/common/lib';
14
- import { Input, Label } from '@openpeepshq/react-ui';
14
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
15
15
  import { useT } from '../../../i18n';
16
16
  import {
17
17
  EVENT_WEEKDAYS,
@@ -30,6 +30,9 @@ export interface EventFormProps {
30
30
  onChange: (data: PostCreationData) => void;
31
31
  isEdit?: boolean;
32
32
  occurrenceEdit?: boolean;
33
+ showNotify?: boolean;
34
+ notify?: boolean;
35
+ onNotifyChange?: (value: boolean) => void;
33
36
  }
34
37
 
35
38
  const dateToInputValue = (value: string | undefined, timeZone: string) =>
@@ -48,6 +51,9 @@ export const EventForm = ({
48
51
  onChange,
49
52
  isEdit = false,
50
53
  occurrenceEdit = false,
54
+ showNotify = false,
55
+ notify = false,
56
+ onNotifyChange,
51
57
  }: EventFormProps) => {
52
58
  const t = useT();
53
59
  const [audienceOpen, setAudienceOpen] = useState(false);
@@ -402,6 +408,26 @@ export const EventForm = ({
402
408
  />
403
409
  </Label>
404
410
 
411
+ {showNotify ? (
412
+ <div className="flex w-full items-center justify-between">
413
+ <div className="flex items-center gap-2">
414
+ <Megaphone className="size-5" />
415
+ <p className="text-base">
416
+ {t('posts.form.notifyEveryone', {
417
+ defaultValue: 'Notify everyone',
418
+ })}
419
+ </p>
420
+ </div>
421
+ <Switch
422
+ checked={notify}
423
+ onCheckedChange={(checked) => onNotifyChange?.(checked)}
424
+ aria-label={t('posts.form.notifyEveryone', {
425
+ defaultValue: 'Notify everyone',
426
+ })}
427
+ />
428
+ </div>
429
+ ) : null}
430
+
405
431
  <Label
406
432
  description={t('events.form.attendeeListPublic', {
407
433
  defaultValue: 'Let an attendee see others attending this event',
@@ -7,7 +7,8 @@ import {
7
7
  Paperclip,
8
8
  } from 'lucide-react';
9
9
  import {
10
- checkRoleCapabilities,
10
+ canAnnouncePosts,
11
+ isCommunityWideVisibility,
11
12
  pollOptionsWithinLimit,
12
13
  resolvePollOptionContents,
13
14
  type GroupWithMeta,
@@ -194,12 +195,8 @@ export function NewPostModal({
194
195
  audience,
195
196
  ]);
196
197
 
197
- const canNotify = useMemo(
198
- () =>
199
- checkRoleCapabilities(me?.roles ?? [], ['allpeep-core-admin-notify'])
200
- .success,
201
- [me?.roles],
202
- );
198
+ const canNotify = useMemo(() => canAnnouncePosts(me?.roles), [me?.roles]);
199
+ const showNotify = canNotify && isCommunityWideVisibility(visibility);
203
200
 
204
201
  const selectedGroupName = useMemo(() => {
205
202
  if (!groupId) return undefined;
@@ -300,7 +297,7 @@ export function NewPostModal({
300
297
  }
301
298
 
302
299
  const response = await createPost(payload);
303
- if (notify && canNotify && response?.id) {
300
+ if (notify && showNotify && response?.id) {
304
301
  await announcePost({ id: response.id });
305
302
  }
306
303
  if (composerType === 'question') {
@@ -328,9 +325,6 @@ export function NewPostModal({
328
325
  }
329
326
  };
330
327
 
331
- const showNotify =
332
- canNotify && (visibility === 'public' || visibility === 'local');
333
-
334
328
  return (
335
329
  <>
336
330
  <Dialog open onOpenChange={(open) => !open && onClose()}>
@@ -1,4 +1,4 @@
1
- import { useMemo, useRef, useState } from 'react';
1
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import type { PublicProfile } from '@openpeepshq/common/types';
3
3
  import {
4
4
  Button,
@@ -48,6 +48,13 @@ export function OpenpeepsMarkdownInput({
48
48
  const [open, setOpen] = useState(false);
49
49
  const [showPreview, setShowPreview] = useState(false);
50
50
  const textareaRef = useRef<HTMLTextAreaElement>(null);
51
+
52
+ // Preview is local state. Clearing the text after send has to leave an
53
+ // editable field, not the preview overlay.
54
+ useLayoutEffect(() => {
55
+ if (value.length === 0) setShowPreview(false);
56
+ }, [value]);
57
+
51
58
  const anchorRef = useRef<HTMLDivElement>(null);
52
59
 
53
60
  const profilesQuery = openpeepsApi.useSearchProfiles(query);
@@ -1,4 +1,8 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ canAnnouncePosts,
4
+ isCommunityWideVisibility,
5
+ } from '@openpeepshq/common';
2
6
  import type {
3
7
  Event,
4
8
  PostCreationData,
@@ -12,6 +16,7 @@ import {
12
16
  import { useOpenpeeps } from '../../contexts/openpeeps';
13
17
  import { useNavigate } from '../../contexts/router';
14
18
  import { useT } from '../../i18n/context';
19
+ import { useCurrentProfile } from '../../components/layout/IdentityContext';
15
20
  import { useServerInfo } from '../../components/server-data/context';
16
21
  import { eventSanitizer, getNewPostStores } from '../../stores/newPosts';
17
22
 
@@ -19,8 +24,10 @@ export const useNewEvent = () => {
19
24
  const t = useT();
20
25
  const navigate = useNavigate();
21
26
  const serverInfo = useServerInfo();
27
+ const me = useCurrentProfile();
22
28
  const { openpeepsApi } = useOpenpeeps();
23
29
  const createPost = openpeepsApi.createPostAction();
30
+ const announcePost = openpeepsApi.admin.announcePostAction();
24
31
  const stores = getNewPostStores();
25
32
  const sanitize = useMemo(
26
33
  () => eventSanitizer(serverInfo.publicContent),
@@ -30,9 +37,14 @@ export const useNewEvent = () => {
30
37
  const [postData, setPostDataState] = useState<PostCreationData>(() =>
31
38
  sanitize(stores.event),
32
39
  );
40
+ const [notify, setNotify] = useState(false);
33
41
  const [submitting, setSubmitting] = useState(false);
34
42
  const [error, setError] = useState<string | null>(null);
35
43
 
44
+ const showNotify =
45
+ canAnnouncePosts(me?.roles) &&
46
+ isCommunityWideVisibility(postData.visibility);
47
+
36
48
  const event = postData.data.type === 'event' ? postData.data : null;
37
49
  const canSubmit =
38
50
  !!event?.start &&
@@ -73,6 +85,9 @@ export const useNewEvent = () => {
73
85
  type: 'event',
74
86
  data: normalizeEventDataForSave(event),
75
87
  });
88
+ if (notify && showNotify && created.id) {
89
+ await announcePost({ id: created.id });
90
+ }
76
91
  stores.resetNewEventState();
77
92
  navigate({ type: 'post', id: created.id });
78
93
  } catch (err) {
@@ -80,7 +95,17 @@ export const useNewEvent = () => {
80
95
  } finally {
81
96
  setSubmitting(false);
82
97
  }
83
- }, [createPost, event, navigate, postData, stores, t]);
98
+ }, [
99
+ announcePost,
100
+ createPost,
101
+ event,
102
+ navigate,
103
+ notify,
104
+ postData,
105
+ showNotify,
106
+ stores,
107
+ t,
108
+ ]);
84
109
 
85
110
  return {
86
111
  postData,
@@ -89,6 +114,9 @@ export const useNewEvent = () => {
89
114
  submitting,
90
115
  error,
91
116
  clearError: () => setError(null),
117
+ notify,
118
+ setNotify,
119
+ showNotify,
92
120
  submit,
93
121
  };
94
122
  };
@@ -1,4 +1,8 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
+ import {
3
+ canAnnouncePosts,
4
+ isCommunityWideVisibility,
5
+ } from '@openpeepshq/common';
2
6
  import type {
3
7
  Article,
4
8
  PostCreationData,
@@ -7,6 +11,7 @@ import type {
7
11
  import { useOpenpeeps } from '../../contexts/openpeeps';
8
12
  import { useNavigate } from '../../contexts/router';
9
13
  import { useT } from '../../i18n/context';
14
+ import { useCurrentProfile } from '../../components/layout/IdentityContext';
10
15
  import { useServerInfo } from '../../components/server-data';
11
16
  import { defaultNewArticle, getNewPostStores } from '../../stores';
12
17
 
@@ -14,8 +19,10 @@ export const useNewArticle = () => {
14
19
  const t = useT();
15
20
  const navigate = useNavigate();
16
21
  const serverInfo = useServerInfo();
22
+ const me = useCurrentProfile();
17
23
  const { openpeepsApi } = useOpenpeeps();
18
24
  const createPost = openpeepsApi.createPostAction();
25
+ const announcePost = openpeepsApi.admin.announcePostAction();
19
26
  const stores = getNewPostStores();
20
27
 
21
28
  const [postData, setPostDataState] = useState<PostCreationData>(() => {
@@ -25,9 +32,14 @@ export const useNewArticle = () => {
25
32
  }
26
33
  return defaultNewArticle(serverInfo.publicContent);
27
34
  });
35
+ const [notify, setNotify] = useState(false);
28
36
  const [submitting, setSubmitting] = useState(false);
29
37
  const [error, setError] = useState<string | null>(null);
30
38
 
39
+ const showNotify =
40
+ canAnnouncePosts(me?.roles) &&
41
+ isCommunityWideVisibility(postData.visibility);
42
+
31
43
  const article = postData.data.type === 'article' ? postData.data : null;
32
44
  const canSubmit =
33
45
  !!article?.title?.trim() &&
@@ -55,6 +67,9 @@ export const useNewArticle = () => {
55
67
  setSubmitting(true);
56
68
  try {
57
69
  const created = await createPost({ ...postData, type: 'article' });
70
+ if (notify && showNotify && created.id) {
71
+ await announcePost({ id: created.id });
72
+ }
58
73
  stores.resetNewArticleState();
59
74
  navigate({ type: 'post', id: created.id });
60
75
  } catch (err) {
@@ -62,7 +77,17 @@ export const useNewArticle = () => {
62
77
  } finally {
63
78
  setSubmitting(false);
64
79
  }
65
- }, [article, createPost, navigate, postData, stores, t]);
80
+ }, [
81
+ announcePost,
82
+ article,
83
+ createPost,
84
+ navigate,
85
+ notify,
86
+ postData,
87
+ showNotify,
88
+ stores,
89
+ t,
90
+ ]);
66
91
 
67
92
  return {
68
93
  postData,
@@ -71,6 +96,9 @@ export const useNewArticle = () => {
71
96
  submitting,
72
97
  error,
73
98
  clearError: () => setError(null),
99
+ notify,
100
+ setNotify,
101
+ showNotify,
74
102
  submit,
75
103
  };
76
104
  };
@@ -13,6 +13,9 @@ export function NewArticle() {
13
13
  submitting,
14
14
  error,
15
15
  clearError,
16
+ notify,
17
+ setNotify,
18
+ showNotify,
16
19
  submit,
17
20
  } = useNewArticle();
18
21
 
@@ -39,7 +42,13 @@ export function NewArticle() {
39
42
 
40
43
  return (
41
44
  <div className="pb-12">
42
- <ArticleForm postData={postData} onChange={setPostData} />
45
+ <ArticleForm
46
+ postData={postData}
47
+ onChange={setPostData}
48
+ showNotify={showNotify}
49
+ notify={notify}
50
+ onNotifyChange={setNotify}
51
+ />
43
52
 
44
53
  {error ? (
45
54
  <div className="px-3">
@@ -13,6 +13,9 @@ export function NewEvent() {
13
13
  submitting,
14
14
  error,
15
15
  clearError,
16
+ notify,
17
+ setNotify,
18
+ showNotify,
16
19
  submit,
17
20
  } = useNewEvent();
18
21
 
@@ -40,7 +43,13 @@ export function NewEvent() {
40
43
 
41
44
  return (
42
45
  <div className="pb-12">
43
- <EventForm postData={postData} onChange={setPostData} />
46
+ <EventForm
47
+ postData={postData}
48
+ onChange={setPostData}
49
+ showNotify={showNotify}
50
+ notify={notify}
51
+ onNotifyChange={setNotify}
52
+ />
44
53
 
45
54
  {error ? (
46
55
  <div className="px-3">
@@ -48,7 +48,7 @@ export function GroupsIndex() {
48
48
  () =>
49
49
  canCreate
50
50
  ? {
51
- title: t('groups.new', { defaultValue: 'New Group' }),
51
+ title: t('groups.new.label', { defaultValue: 'New Group' }),
52
52
  icon: Plus,
53
53
  action: '/groups/new',
54
54
  }