@openpeepshq/react 0.8.0 → 0.8.2

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.
@@ -1,6 +1,7 @@
1
1
  import { Link } from 'react-router-dom';
2
2
  import { ChevronRight } from 'lucide-react';
3
3
  import { useT } from '../../i18n';
4
+ import { Markdown } from '../../lib/Markdown';
4
5
 
5
6
  export interface ConfigMenuButtonProps {
6
7
  translationPrefix: string;
@@ -36,10 +37,13 @@ export function ConfigMenuButton({
36
37
  )}
37
38
  </div>
38
39
  <div className="text-muted-foreground text-xs">
39
- {t(
40
- `${translationPrefix}.description`,
41
- descriptionFallback ? { defaultValue: descriptionFallback } : {},
42
- )}
40
+ <Markdown
41
+ inline
42
+ source={t(
43
+ `${translationPrefix}.description`,
44
+ descriptionFallback ? { defaultValue: descriptionFallback } : {},
45
+ )}
46
+ />
43
47
  </div>
44
48
  </div>
45
49
  <span aria-hidden="true">
@@ -10,6 +10,10 @@ import { isBlobUrl, revokeBlobUrl } from '../attachmentPreview';
10
10
  export interface ComposeAttachmentsProps {
11
11
  attachments: MediaAttachmentData[];
12
12
  onChange: (attachments: MediaAttachmentData[]) => void;
13
+ /** Image picker may select several files at once (resource galleries). */
14
+ multipleImages?: boolean;
15
+ /** Audio picker may select several files at once (default: yes). */
16
+ multipleAudio?: boolean;
13
17
  }
14
18
 
15
19
  const AUDIO_NAME = /\.(mp3|wav|ogg|oga|m4a|aac|flac|opus|weba)$/i;
@@ -59,6 +63,8 @@ export interface ComposeAttachmentsApi {
59
63
  export function useComposeAttachments({
60
64
  attachments,
61
65
  onChange,
66
+ multipleImages = false,
67
+ multipleAudio = true,
62
68
  }: ComposeAttachmentsProps): ComposeAttachmentsApi {
63
69
  const imageInputRef = useRef<HTMLInputElement>(null);
64
70
  const audioInputRef = useRef<HTMLInputElement>(null);
@@ -130,6 +136,20 @@ export function useComposeAttachments({
130
136
  enqueueFile(processed);
131
137
  };
132
138
 
139
+ // A single pick keeps the crop/alt-text flow; a bulk pick is enqueued
140
+ // directly, since per-file cropping isn't practical for a gallery batch.
141
+ const handleImageFilesSelected = async (files: File[]) => {
142
+ const first = files[0];
143
+ if (!first) return;
144
+ if (files.length === 1) {
145
+ await handleImageSelected(first);
146
+ return;
147
+ }
148
+ for (const file of files) {
149
+ enqueueFile(await convertToWebpIfHeic(file));
150
+ }
151
+ };
152
+
133
153
  const onUploaded = (key: string, attachment: MediaAttachment) =>
134
154
  setItems((prev) =>
135
155
  prev.map((i) => {
@@ -204,10 +224,11 @@ export function useComposeAttachments({
204
224
  ref={imageInputRef}
205
225
  type="file"
206
226
  accept="image/*,video/*,.mkv"
227
+ multiple={multipleImages}
207
228
  className="hidden"
208
229
  onChange={(e) => {
209
- const file = e.target.files?.[0];
210
- if (file) void handleImageSelected(file);
230
+ const files = e.target.files;
231
+ if (files?.length) void handleImageFilesSelected(Array.from(files));
211
232
  e.target.value = '';
212
233
  }}
213
234
  />
@@ -215,7 +236,7 @@ export function useComposeAttachments({
215
236
  ref={audioInputRef}
216
237
  type="file"
217
238
  accept="audio/*,.mp3,.wav,.ogg,.m4a,.aac,.flac,.opus,.weba"
218
- multiple
239
+ multiple={multipleAudio}
219
240
  className="hidden"
220
241
  onChange={(e) => {
221
242
  const files = e.target.files;
@@ -48,6 +48,9 @@ export const ResourceForm = ({
48
48
  const attachments = useComposeAttachments({
49
49
  attachments: resource.attachments ?? [],
50
50
  onChange: (next) => patchResource({ attachments: next }),
51
+ // Only galleries take more than one file; other kinds pick one at a time.
52
+ multipleImages: resource.resourceKind === 'gallery',
53
+ multipleAudio: false,
51
54
  });
52
55
 
53
56
  const patchResource = (patch: Partial<ResourcePost>) => {
@@ -1,12 +1,14 @@
1
1
  import { useMemo, useState } from 'react';
2
2
  import type { ReactNode } from 'react';
3
3
  import {
4
+ AudioLines,
4
5
  BookmarkCheck,
5
6
  BookmarkPlus,
6
7
  Link as LinkIcon,
7
8
  ImageOff,
8
9
  } from 'lucide-react';
9
10
  import type {
11
+ GroupWithMeta,
10
12
  MediaAttachmentData,
11
13
  PublicPost,
12
14
  ResourceKind,
@@ -17,13 +19,13 @@ import {
17
19
  groupName,
18
20
  normalizeResourceTags,
19
21
  } from '@openpeepshq/common/lib';
20
- import { useHrefOf } from '../../contexts/router';
22
+ import { useHrefOf, useNavigate } from '../../contexts/router';
21
23
  import { useT } from '../../i18n';
24
+ import { useStaticRender } from '../markdown/staticRender';
22
25
  import { useOpenpeeps } from '../../contexts/openpeeps';
23
26
  import { useCurrentProfile } from '../layout/IdentityContext';
24
27
  import { VideoPlayOverlay } from '../post/VideoPlayOverlay';
25
28
  import { TruncatedMarkdown } from '../post/TruncatedMarkdown';
26
- import { useNavigate } from '../../contexts/router';
27
29
 
28
30
  export interface ResourceCardProps {
29
31
  post: PublicPost;
@@ -35,8 +37,12 @@ export interface ResourceCardProps {
35
37
  inGroup?: boolean;
36
38
  }
37
39
 
40
+ // Audio attachments render their generated waveform preview like any other
41
+ // visual; without one they fall back to the kind placeholder below.
38
42
  const visualAttachments = (attachments: MediaAttachmentData[]) =>
39
- attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
43
+ attachments.filter(
44
+ (att) => attachmentMediaKind(att) !== 'audio' || !!att.previewUrl,
45
+ );
40
46
 
41
47
  const previewSrc = (att: MediaAttachmentData) => att.previewUrl ?? att.url;
42
48
 
@@ -59,6 +65,108 @@ const primaryActionLabel = (kind: ResourceKind, t: ReturnType<typeof useT>) => {
59
65
  }
60
66
  };
61
67
 
68
+ /**
69
+ * Bookmark toggle. Lives in its own component so ResourceCard itself stays
70
+ * free of app providers (OpenpeepsProvider, IdentityContext, RouterProvider)
71
+ * and can render in provider-less static contexts such as notification emails.
72
+ */
73
+ const ResourceSaveButton = ({
74
+ postId,
75
+ className,
76
+ }: {
77
+ postId: string;
78
+ className: string;
79
+ }) => {
80
+ const t = useT();
81
+ const { openpeepsApi } = useOpenpeeps();
82
+ const me = useCurrentProfile();
83
+ const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
84
+ const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: postId });
85
+ const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: postId });
86
+ const isBookmarked = bookmarkedIdsQuery.data?.includes(postId) ?? false;
87
+
88
+ const toggleBookmark = () => {
89
+ if (!me) return;
90
+ if (isBookmarked) {
91
+ unbookmarkPost(undefined);
92
+ } else {
93
+ bookmarkPost(undefined);
94
+ }
95
+ };
96
+
97
+ return (
98
+ <button
99
+ type="button"
100
+ onClick={(e) => {
101
+ e.preventDefault();
102
+ e.stopPropagation();
103
+ toggleBookmark();
104
+ }}
105
+ disabled={!me}
106
+ className={className}
107
+ title={
108
+ isBookmarked
109
+ ? t('resources.actions.saved', { defaultValue: 'Saved' })
110
+ : t('resources.actions.save', { defaultValue: 'Save' })
111
+ }
112
+ >
113
+ {isBookmarked ? (
114
+ <BookmarkCheck className="text-primary size-4" />
115
+ ) : (
116
+ <BookmarkPlus className="size-4" />
117
+ )}
118
+ </button>
119
+ );
120
+ };
121
+
122
+ /**
123
+ * Clickable hashtag chip. Child component like ResourceSaveButton so the
124
+ * router hook stays out of ResourceCard's static (email) render path.
125
+ */
126
+ const ResourceTagChip = ({ value }: { value: string }) => {
127
+ const navigate = useNavigate();
128
+ return (
129
+ <button
130
+ type="button"
131
+ className="bg-muted text-muted-foreground hover:text-foreground rounded-full px-2 py-0.5 text-xs"
132
+ onClick={(e) => {
133
+ e.preventDefault();
134
+ e.stopPropagation();
135
+ navigate({ type: 'tags', hashtag: value });
136
+ }}
137
+ >
138
+ #{value}
139
+ </button>
140
+ );
141
+ };
142
+
143
+ /** Clickable group label. Child component so the router hook stays out of the static render path. */
144
+ const ResourceGroupLabel = ({ group }: { group: GroupWithMeta }) => {
145
+ const t = useT();
146
+ const hrefOf = useHrefOf();
147
+ const groupLabel = groupName(group);
148
+ return (
149
+ <a
150
+ href={hrefOf({ type: 'group', handle: group.handle })}
151
+ onClick={(e) => {
152
+ e.stopPropagation();
153
+ }}
154
+ className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs"
155
+ title={t('resources.group.inGroup', {
156
+ defaultValue: 'in {{groupName}}',
157
+ groupName: groupLabel,
158
+ })}
159
+ >
160
+ <span className="bg-muted rounded-full px-2 py-0.5 text-xs">
161
+ {t('resources.group.inGroup', {
162
+ defaultValue: 'in {{groupName}}',
163
+ groupName: groupLabel,
164
+ })}
165
+ </span>
166
+ </a>
167
+ );
168
+ };
169
+
62
170
  const MediaPreview = ({
63
171
  src,
64
172
  alt,
@@ -118,19 +226,17 @@ export const ResourceCard = ({
118
226
  inGroup = false,
119
227
  }: ResourceCardProps) => {
120
228
  const t = useT();
121
- const navigate = useNavigate();
122
- const hrefOf = useHrefOf();
123
- const { openpeepsApi } = useOpenpeeps();
124
- const me = useCurrentProfile();
125
- if (post.data?.type !== 'resource') return null;
126
- const resource = post.data;
127
- const attachments = resource.attachments ?? [];
229
+ const { enabled: staticRender } = useStaticRender();
230
+ const resource = post.data?.type === 'resource' ? post.data : undefined;
231
+ const attachments = resource?.attachments ?? [];
128
232
  const visuals = visualAttachments(attachments);
129
- const tags = normalizeResourceTags(resource.tags);
130
- const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
233
+ const tags = normalizeResourceTags(resource?.tags);
234
+ const isGallery = resource?.resourceKind === 'gallery' && visuals.length > 1;
131
235
  const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
132
236
  const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
133
- const actionLabel = primaryActionLabel(resource.resourceKind, t);
237
+ const actionLabel = resource
238
+ ? primaryActionLabel(resource.resourceKind, t)
239
+ : null;
134
240
  const thumbnail = visuals[0];
135
241
  const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
136
242
 
@@ -138,6 +244,7 @@ export const ResourceCard = ({
138
244
  const groupLabel = group ? groupName(group) : null;
139
245
 
140
246
  const metaText = useMemo(() => {
247
+ if (!resource) return null;
141
248
  if (resource.resourceKind === 'gallery' && visuals.length > 1) {
142
249
  return t('resources.meta.imagesCount', {
143
250
  defaultValue: '{{count}} images',
@@ -153,74 +260,36 @@ export const ResourceCard = ({
153
260
  const size = fileAtt?.meta?.size;
154
261
  if (size) return formatSize(size);
155
262
  return null;
156
- }, [resource.resourceKind, visuals, attachments, t]);
157
-
158
- const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
159
- const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
160
- const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
161
- const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
263
+ }, [resource, visuals, attachments, t]);
162
264
 
163
- const toggleBookmark = () => {
164
- if (!me) return;
165
- if (isBookmarked) {
166
- unbookmarkPost(undefined);
167
- } else {
168
- bookmarkPost(undefined);
169
- }
170
- };
265
+ if (!resource) return null;
171
266
 
172
267
  const downloadUrl =
173
268
  resource.resourceKind === 'file'
174
269
  ? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
175
270
  : null;
176
271
 
177
- const renderBookmarkButton = (className: string) => (
178
- <button
179
- type="button"
180
- onClick={(e) => {
181
- e.preventDefault();
182
- e.stopPropagation();
183
- toggleBookmark();
184
- }}
185
- disabled={!me}
186
- className={className}
187
- title={
188
- isBookmarked
189
- ? t('resources.actions.saved', { defaultValue: 'Saved' })
190
- : t('resources.actions.save', { defaultValue: 'Save' })
191
- }
192
- >
193
- {isBookmarked ? (
194
- <BookmarkCheck className="text-primary size-4" />
195
- ) : (
196
- <BookmarkPlus className="size-4" />
197
- )}
198
- </button>
199
- );
272
+ const renderSaveButton = (className: string) =>
273
+ staticRender ? null : (
274
+ <ResourceSaveButton postId={post.id} className={className} />
275
+ );
200
276
 
201
277
  const renderGroupLabel = () => {
202
278
  if (!group || !groupLabel || inGroup) return null;
203
- const groupHref = hrefOf({ type: 'group', handle: group.handle });
204
- return (
205
- <a
206
- href={groupHref}
207
- onClick={(e) => {
208
- e.stopPropagation();
209
- }}
210
- className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs"
211
- title={t('resources.group.inGroup', {
212
- defaultValue: 'in {{groupName}}',
213
- groupName: groupLabel,
214
- })}
215
- >
216
- <span className="bg-muted rounded-full px-2 py-0.5 text-xs">
217
- {t('resources.group.inGroup', {
218
- defaultValue: 'in {{groupName}}',
219
- groupName: groupLabel,
220
- })}
279
+ const label = t('resources.group.inGroup', {
280
+ defaultValue: 'in {{groupName}}',
281
+ groupName: groupLabel,
282
+ });
283
+ if (staticRender) {
284
+ return (
285
+ <span className="text-muted-foreground inline-flex items-center gap-1 text-xs">
286
+ <span className="bg-muted rounded-full px-2 py-0.5 text-xs">
287
+ {label}
288
+ </span>
221
289
  </span>
222
- </a>
223
- );
290
+ );
291
+ }
292
+ return <ResourceGroupLabel group={group} />;
224
293
  };
225
294
 
226
295
  const renderThumbnail = () => {
@@ -236,6 +305,13 @@ export const ResourceCard = ({
236
305
  />
237
306
  );
238
307
  }
308
+ if (resource.resourceKind === 'audio') {
309
+ return (
310
+ <div className="bg-muted flex h-12 w-12 items-center justify-center rounded-md">
311
+ <AudioLines className="text-muted-foreground size-5" />
312
+ </div>
313
+ );
314
+ }
239
315
  if (resource.resourceKind === 'link' && resource.url) {
240
316
  return (
241
317
  <div className="bg-muted flex h-12 w-12 items-center justify-center rounded-md">
@@ -264,6 +340,7 @@ export const ResourceCard = ({
264
340
  maxBlocks={2}
265
341
  maxChars={240}
266
342
  maxLines={2}
343
+ interactive={!staticRender}
267
344
  className="text-sm text-muted-foreground"
268
345
  />
269
346
  ) : null}
@@ -289,7 +366,7 @@ export const ResourceCard = ({
289
366
  </span>
290
367
  )
291
368
  ) : null}
292
- {renderBookmarkButton(
369
+ {renderSaveButton(
293
370
  'text-muted-foreground hover:text-foreground disabled:opacity-50',
294
371
  )}
295
372
  </div>
@@ -335,12 +412,16 @@ export const ResourceCard = ({
335
412
  );
336
413
  })}
337
414
  </div>
415
+ ) : resource.resourceKind === 'audio' ? (
416
+ <div className="bg-muted flex h-48 w-full items-center justify-center rounded-md">
417
+ <AudioLines className="text-muted-foreground/50 size-8" />
418
+ </div>
338
419
  ) : resource.resourceKind === 'link' && resource.url ? (
339
420
  <div className="bg-muted flex h-48 w-full items-center justify-center rounded-md">
340
421
  <LinkIcon className="text-muted-foreground/50 size-8" />
341
422
  </div>
342
423
  ) : null}
343
- {renderBookmarkButton(
424
+ {renderSaveButton(
344
425
  'bg-background text-muted-foreground hover:text-foreground absolute right-2 top-2 rounded-full p-1 opacity-70 hover:opacity-100 disabled:opacity-50',
345
426
  )}
346
427
  </div>
@@ -358,6 +439,7 @@ export const ResourceCard = ({
358
439
  maxBlocks={2}
359
440
  maxChars={240}
360
441
  maxLines={2}
442
+ interactive={!staticRender}
361
443
  className="text-sm text-muted-foreground"
362
444
  />
363
445
  ) : null}
@@ -366,20 +448,18 @@ export const ResourceCard = ({
366
448
  ) : null}
367
449
  {tags.length ? (
368
450
  <div className="flex flex-wrap gap-1">
369
- {tags.map((value) => (
370
- <button
371
- key={value}
372
- type="button"
373
- className="bg-muted text-muted-foreground hover:text-foreground rounded-full px-2 py-0.5 text-xs"
374
- onClick={(e) => {
375
- e.preventDefault();
376
- e.stopPropagation();
377
- navigate({ type: 'tags', hashtag: value });
378
- }}
379
- >
380
- #{value}
381
- </button>
382
- ))}
451
+ {tags.map((value) =>
452
+ staticRender ? (
453
+ <span
454
+ key={value}
455
+ className="bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs"
456
+ >
457
+ #{value}
458
+ </span>
459
+ ) : (
460
+ <ResourceTagChip key={value} value={value} />
461
+ ),
462
+ )}
383
463
  </div>
384
464
  ) : null}
385
465
  <p className="text-muted-foreground text-xs uppercase">
@@ -7,11 +7,13 @@ import {
7
7
  } from '@openpeepshq/common/types';
8
8
  import {
9
9
  applySimpleGroupTemplate,
10
+ canCreateGroup,
10
11
  defaultSimpleGroupTemplate,
11
12
  } from '@openpeepshq/common/lib';
12
13
  import { useOpenpeeps } from '../../contexts/openpeeps';
13
14
  import { useNavigate } from '../../contexts/router';
14
15
  import { useT } from '../../i18n/context';
16
+ import { useCurrentProfile } from '../../components/layout/IdentityContext';
15
17
  import { useServerInfo } from '../../components/server-data/context';
16
18
  import { apiErrorMessage } from '../../lib/apiErrorMessage';
17
19
  import {
@@ -33,6 +35,8 @@ const handleFromDisplayName = (displayName: string) =>
33
35
  export const useNewGroup = () => {
34
36
  const t = useT();
35
37
  const navigate = useNavigate();
38
+ const profile = useCurrentProfile();
39
+ const canCreate = !!profile && canCreateGroup(profile.roles);
36
40
  const { openpeepsApi } = useOpenpeeps();
37
41
  const createGroup = openpeepsApi.createGroupAction();
38
42
  const serverInfo = useServerInfo();
@@ -54,6 +58,7 @@ export const useNewGroup = () => {
54
58
  const [fieldErrors, setFieldErrors] = useState<GroupFormFieldErrors>({});
55
59
 
56
60
  const submit = async () => {
61
+ if (!canCreate) return;
57
62
  setError(null);
58
63
  const nextFieldErrors = groupFormFieldErrors(groupData, t, {
59
64
  additionalForbiddenHandles,
@@ -119,6 +124,7 @@ export const useNewGroup = () => {
119
124
  error,
120
125
  clearError: () => setError(null),
121
126
  fieldErrors,
127
+ canCreate,
122
128
  submit,
123
129
  };
124
130
  };
@@ -4,6 +4,12 @@ import { marked } from 'marked';
4
4
  export interface MarkdownProps {
5
5
  source: string;
6
6
  className?: string;
7
+ /**
8
+ * Render as inline markdown (no block `<p>` wrapper) via `marked.parseInline`.
9
+ * Use for short help text inside tight layouts (e.g. config card rows) where
10
+ * block margins would disrupt alignment.
11
+ */
12
+ inline?: boolean;
7
13
  }
8
14
 
9
15
  /**
@@ -15,10 +21,13 @@ export interface MarkdownProps {
15
21
  * Svelte app behaves. If you ever feed untrusted markdown through here,
16
22
  * sanitize first.
17
23
  */
18
- export function Markdown({ source, className }: MarkdownProps) {
24
+ export function Markdown({ source, className, inline }: MarkdownProps) {
19
25
  const html = useMemo(
20
- () => marked.parse(source ?? '', { async: false }) as string,
21
- [source],
26
+ () =>
27
+ inline
28
+ ? (marked.parseInline(source ?? '', { async: false }) as string)
29
+ : (marked.parse(source ?? '', { async: false }) as string),
30
+ [source, inline],
22
31
  );
23
32
  return (
24
33
  <div
@@ -1,9 +1,14 @@
1
1
  import { useMemo, useState } from 'react';
2
2
  import { useNavigate } from 'react-router-dom';
3
3
  import { Users } from 'lucide-react';
4
- import { groupName } from '@openpeepshq/common/lib';
4
+ import { canCreateGroup, groupName } from '@openpeepshq/common/lib';
5
5
  import type { AdminGroup } from '@openpeepshq/common/types';
6
- import { useT, useOpenpeeps, useSetPageHeader } from '../../index';
6
+ import {
7
+ useT,
8
+ useOpenpeeps,
9
+ useSetPageHeader,
10
+ useCurrentProfile,
11
+ } from '../../index';
7
12
  import {
8
13
  Button,
9
14
  Dialog,
@@ -18,6 +23,8 @@ import { AdminGroupCard } from './components/AdminGroupCard';
18
23
  export function AdminGroups() {
19
24
  const t = useT();
20
25
  const navigate = useNavigate();
26
+ const profile = useCurrentProfile();
27
+ const canCreate = !!profile && canCreateGroup(profile.roles);
21
28
  const { openpeepsApi } = useOpenpeeps();
22
29
  const groupsQuery = openpeepsApi.admin.useAllGroupsList();
23
30
  const [search, setSearch] = useState('');
@@ -27,16 +34,17 @@ export function AdminGroups() {
27
34
  defaultValue: 'Create Group',
28
35
  });
29
36
  const headerActions = useMemo(
30
- () => (
31
- <Button
32
- title={createLabel}
33
- variant="default"
34
- action={() => navigate('/groups/new')}
35
- >
36
- {createLabel}
37
- </Button>
38
- ),
39
- [createLabel, navigate],
37
+ () =>
38
+ canCreate ? (
39
+ <Button
40
+ title={createLabel}
41
+ variant="default"
42
+ action={() => navigate('/groups/new')}
43
+ >
44
+ {createLabel}
45
+ </Button>
46
+ ) : undefined,
47
+ [canCreate, createLabel, navigate],
40
48
  );
41
49
 
42
50
  useSetPageHeader(
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useState, type ReactNode } from 'react';
2
2
  import { Plus, Users } from 'lucide-react';
3
- import { checkRoleCapabilities } from '@openpeepshq/common';
3
+ import { canCreateGroup } from '@openpeepshq/common';
4
4
  import { matchesQuery } from '@openpeepshq/common/lib';
5
5
  import {
6
6
  useT,
@@ -43,17 +43,17 @@ export function GroupsIndex() {
43
43
  [groups, myGroupIds, tab],
44
44
  );
45
45
 
46
+ const canCreate = canCreateGroup(currentProfile?.roles ?? []);
46
47
  const plusButton = useMemo(
47
48
  () =>
48
- checkRoleCapabilities(currentProfile?.roles ?? [], ['core-groups-create'])
49
- .success
49
+ canCreate
50
50
  ? {
51
51
  title: t('groups.new', { defaultValue: 'New Group' }),
52
52
  icon: Plus,
53
53
  action: '/groups/new',
54
54
  }
55
55
  : undefined,
56
- [currentProfile?.roles, t],
56
+ [canCreate, t],
57
57
  );
58
58
  useSetPlusButtonActions(plusButton);
59
59
 
@@ -1,3 +1,4 @@
1
+ import { Navigate } from 'react-router-dom';
1
2
  import { useT, useSetPageHeader } from '../../index';
2
3
  import { GroupForm, ProfilesInput, useCurrentProfile } from '../../components';
3
4
  import { useNewGroup } from '../../hooks';
@@ -15,15 +16,22 @@ export function NewGroup() {
15
16
  error,
16
17
  clearError,
17
18
  fieldErrors,
19
+ canCreate,
18
20
  submit,
19
21
  } = useNewGroup();
20
22
 
21
23
  useSetPageHeader(
22
- t('groups.new.title', { defaultValue: 'Create group' }),
24
+ canCreate
25
+ ? t('groups.new.title', { defaultValue: 'Create group' })
26
+ : undefined,
23
27
  undefined,
24
- 'groups-create-page-title',
28
+ canCreate ? 'groups-create-page-title' : undefined,
25
29
  );
26
30
 
31
+ if (!canCreate) {
32
+ return me ? <Navigate to="/groups" replace /> : null;
33
+ }
34
+
27
35
  return (
28
36
  <div className="space-y-4 p-4 pb-12">
29
37
  <GroupForm