@openpeepshq/react 0.6.3 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/configuration/ConfigurationCategory.js +3 -2
- package/dist/components/configuration/ConfigurationList.js +1 -1
- package/dist/components/form/LocationInput.js +1 -1
- package/dist/components/groups/GroupHeader.js +2 -1
- package/dist/components/groups/GroupNotificationSettingsModal.d.ts +9 -0
- package/dist/components/groups/GroupNotificationSettingsModal.js +57 -0
- package/dist/components/groups/GroupShareMenu.js +30 -8
- package/dist/components/groups/index.d.ts +2 -0
- package/dist/components/groups/index.js +1 -0
- package/dist/components/jams/JamCapacityGate.js +1 -1
- package/dist/components/jams/JamConference.js +2 -0
- package/dist/components/jams/JamParticipantConference.js +2 -0
- package/dist/components/jams/JamRoom.js +2 -3
- package/dist/components/jams/LiveJamsSection.js +8 -2
- package/dist/components/jams/LivekitUnavailableNotice.d.ts +9 -0
- package/dist/components/jams/LivekitUnavailableNotice.js +19 -0
- package/dist/components/jams/dropLateAudio.d.ts +22 -0
- package/dist/components/jams/dropLateAudio.js +115 -0
- package/dist/components/jams/index.d.ts +1 -0
- package/dist/components/jams/index.js +1 -0
- package/dist/components/notifications/TypedNotification.js +46 -4
- package/dist/components/post/Markdown.d.ts +2 -2
- package/dist/components/post/Markdown.js +1 -1
- package/dist/components/post/attachmentPreview.js +1 -1
- package/dist/components/post/pieces/Attachments.js +23 -17
- package/dist/components/post/pieces/EventRsvpButton.js +37 -7
- package/dist/components/post/pieces/EventRsvpList.js +23 -3
- package/dist/components/post/pieces/EventRsvpScopeDialog.d.ts +1 -1
- package/dist/components/post/pieces/EventRsvpScopeDialog.js +34 -22
- package/dist/components/post/pieces/EventWaitlistJoinDialog.d.ts +10 -0
- package/dist/components/post/pieces/EventWaitlistJoinDialog.js +26 -0
- package/dist/components/post/pieces/ParticipantsCard.d.ts +1 -1
- package/dist/components/post/pieces/ParticipantsCard.js +1 -1
- package/dist/components/post/pieces/PostActions.d.ts +1 -1
- package/dist/components/post/pieces/PostActions.js +20 -12
- package/dist/components/post/pieces/ShareMenu.d.ts +6 -1
- package/dist/components/post/pieces/ShareMenu.js +40 -7
- package/dist/components/post/post-form/EventForm.js +10 -2
- package/dist/components/post/types/Article.js +1 -1
- package/dist/components/post/types/article/FullArticle.js +1 -1
- package/dist/components/post/types/event/CardEvent.js +2 -1
- package/dist/components/post/types/event/FullEvent.js +21 -11
- package/dist/components/post/types/event/ProfileEventRelationship.js +8 -0
- package/dist/components/preview-link/LocalPreviewLink.js +4 -2
- package/dist/components/preview-link/PreviewLink.js +1 -1
- package/dist/components/preview-link/helpers.d.ts +5 -0
- package/dist/components/preview-link/helpers.js +27 -1
- package/dist/components/preview-link/local/WelcomePreview.d.ts +1 -0
- package/dist/components/preview-link/local/WelcomePreview.js +6 -0
- package/dist/components/profile/Avatar.js +2 -2
- package/dist/components/profile/ProfileFromId.js +1 -1
- package/dist/components/server-data/context.d.ts +1 -0
- package/dist/contexts/openpeeps/hooks/accounts.d.ts +5 -5
- package/dist/contexts/openpeeps/hooks/accounts.js +1 -3
- package/dist/contexts/openpeeps/hooks/admin.d.ts +165 -66
- package/dist/contexts/openpeeps/hooks/admin.js +11 -3
- package/dist/contexts/openpeeps/hooks/auth.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/groups.d.ts +8 -8
- package/dist/contexts/openpeeps/hooks/jams.d.ts +73 -24
- package/dist/contexts/openpeeps/hooks/other.d.ts +7 -6
- package/dist/contexts/openpeeps/hooks/payments.d.ts +2 -2
- package/dist/contexts/openpeeps/hooks/posts.d.ts +368 -170
- package/dist/contexts/openpeeps/hooks/streaming.d.ts +1 -1
- package/dist/hooks/admin/useCanAccessAdminSection.d.ts +13 -0
- package/dist/hooks/admin/useCanAccessAdminSection.js +21 -0
- package/dist/hooks/events/useEventComposer.d.ts +94 -41
- package/dist/hooks/events/useEventForm.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.d.ts +11 -2
- package/dist/hooks/events/useEventRsvp.js +46 -5
- package/dist/hooks/events/useEventsCalendar.d.ts +174 -76
- package/dist/hooks/groups/useGroupNotificationLevel.d.ts +9 -0
- package/dist/hooks/groups/useGroupNotificationLevel.js +57 -0
- package/dist/hooks/groups/useNewGroup.js +22 -2
- package/dist/hooks/index.d.ts +6 -1
- package/dist/hooks/index.js +5 -1
- package/dist/hooks/jams/useCanDiagnoseLivekit.d.ts +2 -0
- package/dist/hooks/jams/useCanDiagnoseLivekit.js +3 -0
- package/dist/hooks/jams/useCreateNewJamForm.d.ts +3 -1
- package/dist/hooks/jams/useJamDetails.d.ts +87 -38
- package/dist/hooks/jams/useJamLobby.d.ts +1 -0
- package/dist/hooks/jams/useJamRoom.d.ts +175 -76
- package/dist/hooks/posts/useArticleComposer.d.ts +93 -41
- package/dist/hooks/posts/useFeedPostPresentation.d.ts +174 -76
- package/dist/hooks/posts/usePostDetailTitle.d.ts +87 -38
- package/dist/hooks/posts/useResourceComposer.d.ts +93 -41
- package/dist/hooks/posts/useResourceComposer.js +4 -2
- package/dist/hooks/posts/useShareMenu.d.ts +2 -0
- package/dist/hooks/posts/useShareMenu.js +7 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +176 -78
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/hooks/useWelcomePreview.d.ts +13 -0
- package/dist/hooks/useWelcomePreview.js +39 -0
- package/dist/lib/groupFormErrors.d.ts +1 -0
- package/dist/lib/groupFormErrors.js +5 -2
- package/dist/lib/threadHelpers.js +1 -5
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/Diagnostics.js +1 -1
- package/dist/pages/admin/DiagnosticsLivekit.d.ts +1 -0
- package/dist/pages/admin/DiagnosticsLivekit.js +50 -0
- package/dist/pages/admin/Invites.js +5 -3
- package/dist/pages/admin/Media.d.ts +1 -0
- package/dist/pages/admin/Media.js +135 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.d.ts +1 -0
- package/dist/pages/admin/community/CommunityForbiddenUsernames.js +106 -0
- package/dist/pages/admin/community/CommunityRoles.js +1 -1
- package/dist/pages/admin/community/useCommunityConfig.d.ts +2 -0
- package/dist/pages/admin/components/EditInviteLinkModal.d.ts +5 -0
- package/dist/pages/admin/components/EditInviteLinkModal.js +131 -0
- package/dist/pages/admin/configurationSsoShared.d.ts +4 -0
- package/dist/pages/auth/Register.js +30 -8
- package/dist/pages/conversations/Show.js +11 -0
- package/dist/pages/groups/Show.js +22 -19
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +3 -0
- package/dist/pages/jams/Index.js +2 -4
- package/dist/pages/settings/PublicProfile.js +15 -3
- package/dist/pwa/sw.d.ts +0 -1
- package/dist/react-native.d.ts +2 -1
- package/dist/react-native.js +2 -1
- package/dist/stores/newPosts.d.ts +4 -2
- package/dist/stores/newPosts.js +6 -1
- package/package.json +11 -6
- package/src/components/configuration/ConfigurationCategory.tsx +23 -10
- package/src/components/configuration/ConfigurationList.tsx +6 -1
- package/src/components/form/LocationInput.tsx +7 -1
- package/src/components/groups/GroupHeader.tsx +2 -0
- package/src/components/groups/GroupNotificationSettingsModal.tsx +163 -0
- package/src/components/groups/GroupShareMenu.tsx +77 -12
- package/src/components/groups/index.ts +5 -0
- package/src/components/jams/JamCapacityGate.tsx +1 -1
- package/src/components/jams/JamConference.tsx +2 -0
- package/src/components/jams/JamParticipantConference.tsx +2 -0
- package/src/components/jams/JamRoom.tsx +2 -6
- package/src/components/jams/LiveJamsSection.tsx +16 -2
- package/src/components/jams/LivekitUnavailableNotice.tsx +40 -0
- package/src/components/jams/dropLateAudio.ts +153 -0
- package/src/components/jams/index.ts +1 -0
- package/src/components/notifications/TypedNotification.tsx +81 -9
- package/src/components/post/Markdown.tsx +8 -2
- package/src/components/post/attachmentPreview.ts +1 -3
- package/src/components/post/pieces/Attachments.tsx +93 -78
- package/src/components/post/pieces/EventRsvpButton.tsx +107 -7
- package/src/components/post/pieces/EventRsvpList.tsx +64 -0
- package/src/components/post/pieces/EventRsvpScopeDialog.tsx +39 -27
- package/src/components/post/pieces/EventWaitlistJoinDialog.tsx +77 -0
- package/src/components/post/pieces/ParticipantsCard.tsx +4 -1
- package/src/components/post/pieces/PostActions.tsx +73 -42
- package/src/components/post/pieces/ShareMenu.tsx +67 -9
- package/src/components/post/post-form/EventForm.tsx +26 -0
- package/src/components/post/post-form/VisibilitySelector.tsx +1 -2
- package/src/components/post/types/Article.tsx +1 -1
- package/src/components/post/types/article/FullArticle.tsx +2 -2
- package/src/components/post/types/event/CardEvent.tsx +26 -14
- package/src/components/post/types/event/FullEvent.tsx +47 -29
- package/src/components/post/types/event/ProfileEventRelationship.tsx +8 -0
- package/src/components/post/types/note/FullNote.tsx +1 -4
- package/src/components/post/types/poll/FullPoll.tsx +1 -4
- package/src/components/preview-link/LocalPreviewLink.tsx +4 -1
- package/src/components/preview-link/PreviewLink.tsx +2 -7
- package/src/components/preview-link/helpers.ts +32 -1
- package/src/components/preview-link/local/GroupPreview.tsx +1 -1
- package/src/components/preview-link/local/JamPreview.tsx +1 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +36 -0
- package/src/components/profile/Avatar.tsx +6 -2
- package/src/components/profile/ProfileFromId.tsx +1 -5
- package/src/components/resources/ResourceCard.tsx +0 -1
- package/src/contexts/openpeeps/hooks/accounts.ts +1 -3
- package/src/contexts/openpeeps/hooks/admin.ts +11 -3
- package/src/contexts/openpeeps/hooks/other.ts +9 -12
- package/src/contexts/openpeeps/hooks/streaming.ts +3 -3
- package/src/css.d.ts +4 -0
- package/src/hooks/admin/useCanAccessAdminSection.ts +27 -0
- package/src/hooks/events/useEventRsvp.ts +51 -7
- package/src/hooks/groups/useGroupNotificationLevel.ts +57 -0
- package/src/hooks/groups/useNewGroup.ts +28 -3
- package/src/hooks/index.ts +9 -1
- package/src/hooks/jams/useCanDiagnoseLivekit.ts +5 -0
- package/src/hooks/posts/useResourceComposer.ts +8 -6
- package/src/hooks/posts/useShareMenu.ts +9 -0
- package/src/hooks/useWelcomePreview.ts +57 -0
- package/src/i18n/I18nProvider.tsx +1 -4
- package/src/lib/groupFormErrors.ts +9 -2
- package/src/lib/threadHelpers.ts +1 -5
- package/src/pages/admin/ConfigurationCommunity.tsx +5 -0
- package/src/pages/admin/Diagnostics.tsx +4 -0
- package/src/pages/admin/DiagnosticsLivekit.tsx +147 -0
- package/src/pages/admin/Invites.tsx +23 -1
- package/src/pages/admin/Media.tsx +290 -0
- package/src/pages/admin/community/CommunityForbiddenUsernames.tsx +223 -0
- package/src/pages/admin/community/CommunityRoles.tsx +2 -2
- package/src/pages/admin/components/EditInviteLinkModal.tsx +263 -0
- package/src/pages/auth/Register.tsx +33 -4
- package/src/pages/conversations/Show.tsx +11 -0
- package/src/pages/groups/Show.tsx +60 -53
- package/src/pages/index.ts +3 -0
- package/src/pages/jams/Index.tsx +2 -6
- package/src/pages/settings/PublicProfile.tsx +20 -2
- package/src/pwa/sw.ts +6 -3
- package/src/pwa/useNotificationBadgeSync.ts +3 -1
- package/src/react-native.ts +2 -1
- package/src/stores/newPosts.ts +6 -1
- package/src/streaming.ts +3 -3
- package/dist/setupTests.d.ts +0 -1
- package/dist/setupTests.js +0 -5
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import { Images } from 'lucide-react';
|
|
3
|
+
import type {
|
|
4
|
+
StoredMediaFile,
|
|
5
|
+
StoredMediaStatus,
|
|
6
|
+
} from '@openpeepshq/common/types';
|
|
7
|
+
import { checkRoleCapabilities } from '@openpeepshq/common';
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogActions,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogHeader,
|
|
14
|
+
DialogTitle,
|
|
15
|
+
} from '@openpeepshq/react-ui';
|
|
16
|
+
import { useOpenpeeps, useSetPageHeader, useT } from '../../index';
|
|
17
|
+
import { useCurrentProfile } from '../../components';
|
|
18
|
+
|
|
19
|
+
type MediaFilter = 'all' | 'unused' | 'referenced';
|
|
20
|
+
|
|
21
|
+
const formatBytes = (size: number): string => {
|
|
22
|
+
if (size < 1024) return `${size} B`;
|
|
23
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
|
|
24
|
+
if (size < 1024 * 1024 * 1024) {
|
|
25
|
+
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
|
|
26
|
+
}
|
|
27
|
+
return `${(size / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const formatWhen = (iso: string | null): string =>
|
|
31
|
+
iso ? new Date(iso).toLocaleString() : '';
|
|
32
|
+
|
|
33
|
+
export const AdminMedia = () => {
|
|
34
|
+
const t = useT();
|
|
35
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
36
|
+
const me = useCurrentProfile();
|
|
37
|
+
const canDeleteMedia = checkRoleCapabilities(me?.roles ?? [], [
|
|
38
|
+
'core-media-delete',
|
|
39
|
+
]).success;
|
|
40
|
+
const mediaQuery = openpeepsApi.admin.useMediaList();
|
|
41
|
+
const deleteMedia = openpeepsApi.admin.deleteMediaAction();
|
|
42
|
+
|
|
43
|
+
const [filter, setFilter] = useState<MediaFilter>('all');
|
|
44
|
+
const [query, setQuery] = useState('');
|
|
45
|
+
const [pending, setPending] = useState<StoredMediaFile | null>(null);
|
|
46
|
+
const [deleting, setDeleting] = useState(false);
|
|
47
|
+
const [deleteError, setDeleteError] = useState<string | null>(null);
|
|
48
|
+
|
|
49
|
+
const files = mediaQuery.data?.files ?? [];
|
|
50
|
+
const graceDays = Math.round((mediaQuery.data?.graceMs ?? 0) / 86_400_000);
|
|
51
|
+
const needle = query.trim().toLowerCase();
|
|
52
|
+
|
|
53
|
+
const visible = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
files.filter((file) => {
|
|
56
|
+
if (filter === 'unused' && file.status === 'referenced') return false;
|
|
57
|
+
if (filter === 'referenced' && file.status !== 'referenced') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
needle.length === 0 || file.storageId.toLowerCase().includes(needle)
|
|
62
|
+
);
|
|
63
|
+
}),
|
|
64
|
+
[files, filter, needle],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const unusedCount = files.filter(
|
|
68
|
+
(file) => file.status !== 'referenced',
|
|
69
|
+
).length;
|
|
70
|
+
|
|
71
|
+
useSetPageHeader(t('admin.media.title', { defaultValue: 'Media' }));
|
|
72
|
+
|
|
73
|
+
const statusLabel = (status: StoredMediaStatus) =>
|
|
74
|
+
t(`admin.media.status.${status}`, {
|
|
75
|
+
defaultValue:
|
|
76
|
+
status === 'referenced'
|
|
77
|
+
? 'In use'
|
|
78
|
+
: status === 'due'
|
|
79
|
+
? 'Ready to collect'
|
|
80
|
+
: 'Unused',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const collectionLabel = (file: StoredMediaFile) => {
|
|
84
|
+
if (file.status === 'referenced') {
|
|
85
|
+
return t('admin.media.collects.referenced', {
|
|
86
|
+
defaultValue: 'Kept — still linked',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (file.status === 'pending') {
|
|
90
|
+
return t('admin.media.collects.pending', {
|
|
91
|
+
defaultValue: 'Deletes {{date}}',
|
|
92
|
+
date: formatWhen(file.deletesAt),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (file.status === 'due') {
|
|
96
|
+
return t('admin.media.collects.due', {
|
|
97
|
+
defaultValue: 'Deletes on the next run',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return t('admin.media.collects.unseen', {
|
|
101
|
+
defaultValue: 'Recorded on the next run',
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const confirmDelete = async () => {
|
|
106
|
+
if (!pending) return;
|
|
107
|
+
setDeleting(true);
|
|
108
|
+
setDeleteError(null);
|
|
109
|
+
try {
|
|
110
|
+
await deleteMedia({ storageId: pending.storageId });
|
|
111
|
+
setPending(null);
|
|
112
|
+
void mediaQuery.refetch();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
setDeleteError((error as Error).message);
|
|
115
|
+
} finally {
|
|
116
|
+
setDeleting(false);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const filters: { id: MediaFilter; label: string }[] = [
|
|
121
|
+
{ id: 'all', label: t('admin.media.filter.all', { defaultValue: 'All' }) },
|
|
122
|
+
{
|
|
123
|
+
id: 'unused',
|
|
124
|
+
label: t('admin.media.filter.unused', { defaultValue: 'Unused' }),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'referenced',
|
|
128
|
+
label: t('admin.media.filter.inUse', { defaultValue: 'In use' }),
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div className="space-y-4 p-4">
|
|
134
|
+
<div className="rounded-md border p-4 text-sm">
|
|
135
|
+
{t('admin.media.description', {
|
|
136
|
+
defaultValue:
|
|
137
|
+
'Removing a post or jam recording leaves the file on the server, because another post, the welcome page, the about page, the code of conduct, a profile, or a custom field may still link to it. Garbage collection deletes a file {{days}} days after it first has no live link. Delete now removes a file immediately.',
|
|
138
|
+
days: graceDays || 7,
|
|
139
|
+
})}
|
|
140
|
+
</div>
|
|
141
|
+
<p className="text-muted-foreground text-sm">
|
|
142
|
+
{t('admin.media.counts', {
|
|
143
|
+
defaultValue:
|
|
144
|
+
'{{total}} files · {{unused}} unused · {{inUse}} in use',
|
|
145
|
+
total: files.length,
|
|
146
|
+
unused: unusedCount,
|
|
147
|
+
inUse: files.length - unusedCount,
|
|
148
|
+
})}
|
|
149
|
+
</p>
|
|
150
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
151
|
+
{filters.map((item) => (
|
|
152
|
+
<Button
|
|
153
|
+
key={item.id}
|
|
154
|
+
title={item.label}
|
|
155
|
+
variant={filter === item.id ? 'default' : 'outline'}
|
|
156
|
+
action={() => setFilter(item.id)}
|
|
157
|
+
>
|
|
158
|
+
{item.label}
|
|
159
|
+
</Button>
|
|
160
|
+
))}
|
|
161
|
+
<input
|
|
162
|
+
value={query}
|
|
163
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
164
|
+
placeholder={t('admin.media.search', {
|
|
165
|
+
defaultValue: 'Search by file id',
|
|
166
|
+
})}
|
|
167
|
+
className="border-border bg-background min-w-48 flex-1 rounded-md border px-3 py-2 text-sm"
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{mediaQuery.isLoading ? (
|
|
172
|
+
<p className="text-muted-foreground text-sm">
|
|
173
|
+
{t('admin.media.loading', { defaultValue: 'Loading…' })}
|
|
174
|
+
</p>
|
|
175
|
+
) : null}
|
|
176
|
+
{mediaQuery.isError ? (
|
|
177
|
+
<p className="text-error text-sm">
|
|
178
|
+
{t('admin.media.error', {
|
|
179
|
+
defaultValue: 'Could not load media files',
|
|
180
|
+
})}
|
|
181
|
+
</p>
|
|
182
|
+
) : null}
|
|
183
|
+
{!mediaQuery.isLoading && !mediaQuery.isError && visible.length === 0 ? (
|
|
184
|
+
<div className="text-muted-foreground flex flex-col items-center pt-16">
|
|
185
|
+
<Images size={48} />
|
|
186
|
+
<p className="mt-2 text-sm">
|
|
187
|
+
{t('admin.media.empty', { defaultValue: 'No media files' })}
|
|
188
|
+
</p>
|
|
189
|
+
</div>
|
|
190
|
+
) : null}
|
|
191
|
+
{visible.length > 0 ? (
|
|
192
|
+
<ul className="space-y-2">
|
|
193
|
+
{visible.map((file) => (
|
|
194
|
+
<li key={file.storageId} className="rounded-md border p-3">
|
|
195
|
+
<div className="flex flex-wrap items-start justify-between gap-3">
|
|
196
|
+
<div className="min-w-0">
|
|
197
|
+
<p className="break-all font-mono text-xs">
|
|
198
|
+
{file.storageId}
|
|
199
|
+
</p>
|
|
200
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
201
|
+
{formatBytes(file.size)} · {formatWhen(file.modifiedAt)}
|
|
202
|
+
</p>
|
|
203
|
+
<p className="mt-1 text-sm">
|
|
204
|
+
<span className="font-medium">
|
|
205
|
+
{statusLabel(file.status)}
|
|
206
|
+
</span>
|
|
207
|
+
<span className="text-muted-foreground">
|
|
208
|
+
{' '}
|
|
209
|
+
· {collectionLabel(file)}
|
|
210
|
+
</span>
|
|
211
|
+
</p>
|
|
212
|
+
</div>
|
|
213
|
+
<div className="flex items-center gap-2">
|
|
214
|
+
<a
|
|
215
|
+
href={file.url}
|
|
216
|
+
target="_blank"
|
|
217
|
+
rel="noreferrer"
|
|
218
|
+
className="text-primary text-sm"
|
|
219
|
+
>
|
|
220
|
+
{t('admin.media.open', { defaultValue: 'Open' })}
|
|
221
|
+
</a>
|
|
222
|
+
{canDeleteMedia ? (
|
|
223
|
+
<Button
|
|
224
|
+
title={t('admin.media.delete', {
|
|
225
|
+
defaultValue: 'Delete now',
|
|
226
|
+
})}
|
|
227
|
+
variant="outline"
|
|
228
|
+
action={() => {
|
|
229
|
+
setDeleteError(null);
|
|
230
|
+
setPending(file);
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
{t('admin.media.delete', { defaultValue: 'Delete now' })}
|
|
234
|
+
</Button>
|
|
235
|
+
) : null}
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
</li>
|
|
239
|
+
))}
|
|
240
|
+
</ul>
|
|
241
|
+
) : null}
|
|
242
|
+
|
|
243
|
+
{pending ? (
|
|
244
|
+
<Dialog
|
|
245
|
+
open
|
|
246
|
+
onOpenChange={(open) => {
|
|
247
|
+
if (!open && !deleting) setPending(null);
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
<DialogContent className="max-w-md">
|
|
251
|
+
<DialogHeader>
|
|
252
|
+
<DialogTitle>
|
|
253
|
+
{t('admin.media.confirm.title', {
|
|
254
|
+
defaultValue: 'Delete this file?',
|
|
255
|
+
})}
|
|
256
|
+
</DialogTitle>
|
|
257
|
+
</DialogHeader>
|
|
258
|
+
<p className="px-1 text-sm">
|
|
259
|
+
{pending.status === 'referenced'
|
|
260
|
+
? t('admin.media.confirm.referenced', {
|
|
261
|
+
defaultValue:
|
|
262
|
+
'This file is still linked from a post, page, or profile. Deleting it now removes it from the server, and those links will stop working.',
|
|
263
|
+
})
|
|
264
|
+
: t('admin.media.confirm.unused', {
|
|
265
|
+
defaultValue:
|
|
266
|
+
'This file is unused. Deleting it now removes it from the server instead of waiting for garbage collection.',
|
|
267
|
+
})}
|
|
268
|
+
</p>
|
|
269
|
+
{deleteError ? (
|
|
270
|
+
<p className="border-error/40 text-error rounded-md border p-2 text-sm">
|
|
271
|
+
{deleteError}
|
|
272
|
+
</p>
|
|
273
|
+
) : null}
|
|
274
|
+
<DialogActions
|
|
275
|
+
cancelLabel={t('admin.media.confirm.cancel', {
|
|
276
|
+
defaultValue: 'Cancel',
|
|
277
|
+
})}
|
|
278
|
+
onCancel={() => setPending(null)}
|
|
279
|
+
actionLabel={t('admin.media.confirm.action', {
|
|
280
|
+
defaultValue: 'Delete file',
|
|
281
|
+
})}
|
|
282
|
+
onAction={confirmDelete}
|
|
283
|
+
disabled={deleting}
|
|
284
|
+
/>
|
|
285
|
+
</DialogContent>
|
|
286
|
+
</Dialog>
|
|
287
|
+
) : null}
|
|
288
|
+
</div>
|
|
289
|
+
);
|
|
290
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Lock, X } from 'lucide-react';
|
|
3
|
+
import {
|
|
4
|
+
classifyAdditionalForbiddenHandle,
|
|
5
|
+
collectAdditionalForbiddenHandles,
|
|
6
|
+
forbiddenHandles,
|
|
7
|
+
normalizeForbiddenHandle,
|
|
8
|
+
type CommunityConfig,
|
|
9
|
+
} from '@openpeepshq/common/types';
|
|
10
|
+
import { useT, useSetPageHeader, useOpenpeeps } from '../../../index';
|
|
11
|
+
import { Button, Input, Toast } from '@openpeepshq/react-ui';
|
|
12
|
+
|
|
13
|
+
const sameHandles = (left: readonly string[], right: readonly string[]) =>
|
|
14
|
+
left.length === right.length &&
|
|
15
|
+
left.every((handle, i) => handle === right[i]);
|
|
16
|
+
|
|
17
|
+
export function AdminConfigurationCommunityForbiddenUsernames() {
|
|
18
|
+
const t = useT();
|
|
19
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
20
|
+
const configQuery = openpeepsApi.admin.useConfigRead(
|
|
21
|
+
'openpeeps',
|
|
22
|
+
'community',
|
|
23
|
+
);
|
|
24
|
+
const updateConfig = openpeepsApi.admin.updateConfigAction({
|
|
25
|
+
namespace: 'openpeeps',
|
|
26
|
+
name: 'community',
|
|
27
|
+
});
|
|
28
|
+
const [custom, setCustom] = useState<string[]>([]);
|
|
29
|
+
const [draft, setDraft] = useState('');
|
|
30
|
+
const [fieldError, setFieldError] = useState<string | null>(null);
|
|
31
|
+
const [saving, setSaving] = useState(false);
|
|
32
|
+
const [status, setStatus] = useState<{
|
|
33
|
+
type: 'success' | 'error';
|
|
34
|
+
message: string;
|
|
35
|
+
} | null>(null);
|
|
36
|
+
|
|
37
|
+
useSetPageHeader(
|
|
38
|
+
t('configuration.community.forbiddenUsernames.title', {
|
|
39
|
+
defaultValue: 'Forbidden usernames',
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const base = configQuery.data?.config as CommunityConfig | undefined;
|
|
44
|
+
const saved = collectAdditionalForbiddenHandles(
|
|
45
|
+
base?.settings?.additionalForbiddenHandles ?? [],
|
|
46
|
+
).handles;
|
|
47
|
+
const savedKey = saved.join('\n');
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setCustom(savedKey ? savedKey.split('\n') : []);
|
|
51
|
+
}, [savedKey]);
|
|
52
|
+
|
|
53
|
+
const issueMessage = (
|
|
54
|
+
issue: NonNullable<ReturnType<typeof classifyAdditionalForbiddenHandle>>,
|
|
55
|
+
) => {
|
|
56
|
+
if (issue === 'empty') {
|
|
57
|
+
return t('configuration.community.forbiddenUsernames.empty', {
|
|
58
|
+
defaultValue: 'Enter a username to add.',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (issue === 'invalid') {
|
|
62
|
+
return t('configuration.community.forbiddenUsernames.invalid', {
|
|
63
|
+
defaultValue:
|
|
64
|
+
'Usernames must be 1–16 characters: letters, numbers, underscores, or hyphens.',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (issue === 'builtIn') {
|
|
68
|
+
return t('configuration.community.forbiddenUsernames.builtInError', {
|
|
69
|
+
defaultValue:
|
|
70
|
+
'Built-in usernames are always reserved and cannot be changed.',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return t('configuration.community.forbiddenUsernames.duplicate', {
|
|
74
|
+
defaultValue: 'That username is already on the list.',
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const addUsername = () => {
|
|
79
|
+
const issue = classifyAdditionalForbiddenHandle(draft, custom);
|
|
80
|
+
if (issue) {
|
|
81
|
+
setFieldError(issueMessage(issue));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setCustom((prev) => [...prev, normalizeForbiddenHandle(draft)]);
|
|
85
|
+
setDraft('');
|
|
86
|
+
setFieldError(null);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const save = async () => {
|
|
90
|
+
setStatus(null);
|
|
91
|
+
setSaving(true);
|
|
92
|
+
try {
|
|
93
|
+
await updateConfig({
|
|
94
|
+
config: { settings: { additionalForbiddenHandles: custom } },
|
|
95
|
+
});
|
|
96
|
+
setStatus({
|
|
97
|
+
type: 'success',
|
|
98
|
+
message: t('configuration.community.updateSuccess', {
|
|
99
|
+
defaultValue: 'Community settings updated',
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
} catch (err) {
|
|
103
|
+
setStatus({ type: 'error', message: (err as Error).message });
|
|
104
|
+
} finally {
|
|
105
|
+
setSaving(false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (configQuery.isLoading) {
|
|
110
|
+
return (
|
|
111
|
+
<div className="text-muted-foreground flex h-32 items-center justify-center text-sm">
|
|
112
|
+
{t('common.form.loading', { defaultValue: 'Loading…' })}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div
|
|
119
|
+
className="flex flex-col gap-4 p-4"
|
|
120
|
+
data-testid="admin-forbidden-usernames"
|
|
121
|
+
>
|
|
122
|
+
<p className="text-muted-foreground text-sm">
|
|
123
|
+
{t('configuration.community.forbiddenUsernames.description', {
|
|
124
|
+
defaultValue:
|
|
125
|
+
'Block usernames your community does not allow, such as slurs or hate speech. Each entry is a full username, ignoring capitalization. Built-in usernames stay reserved and cannot be removed.',
|
|
126
|
+
})}
|
|
127
|
+
</p>
|
|
128
|
+
<ul className="border-border divide-border divide-y border">
|
|
129
|
+
{forbiddenHandles.map((handle) => (
|
|
130
|
+
<li
|
|
131
|
+
key={handle}
|
|
132
|
+
className="flex items-center justify-between gap-3 px-3 py-2"
|
|
133
|
+
data-testid={`admin-forbidden-username-${handle}`}
|
|
134
|
+
>
|
|
135
|
+
<span>{handle}</span>
|
|
136
|
+
<span className="text-muted-foreground flex items-center gap-1 text-xs">
|
|
137
|
+
<Lock className="size-3" aria-hidden="true" />
|
|
138
|
+
{t('configuration.community.forbiddenUsernames.builtIn', {
|
|
139
|
+
defaultValue: 'Built-in',
|
|
140
|
+
})}
|
|
141
|
+
</span>
|
|
142
|
+
</li>
|
|
143
|
+
))}
|
|
144
|
+
{custom.map((handle) => (
|
|
145
|
+
<li
|
|
146
|
+
key={handle}
|
|
147
|
+
className="flex items-center justify-between gap-3 px-3 py-2"
|
|
148
|
+
data-testid={`admin-forbidden-username-${handle}`}
|
|
149
|
+
>
|
|
150
|
+
<span>{handle}</span>
|
|
151
|
+
<Button
|
|
152
|
+
variant="ghost"
|
|
153
|
+
title={t('configuration.community.forbiddenUsernames.remove', {
|
|
154
|
+
defaultValue: 'Remove',
|
|
155
|
+
})}
|
|
156
|
+
action={() =>
|
|
157
|
+
setCustom((prev) => prev.filter((item) => item !== handle))
|
|
158
|
+
}
|
|
159
|
+
data-testid={`admin-forbidden-username-remove-${handle}`}
|
|
160
|
+
>
|
|
161
|
+
<X className="size-4" aria-hidden="true" />
|
|
162
|
+
{t('configuration.community.forbiddenUsernames.remove', {
|
|
163
|
+
defaultValue: 'Remove',
|
|
164
|
+
})}
|
|
165
|
+
</Button>
|
|
166
|
+
</li>
|
|
167
|
+
))}
|
|
168
|
+
</ul>
|
|
169
|
+
<div className="flex flex-col gap-2">
|
|
170
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
171
|
+
<Input
|
|
172
|
+
value={draft}
|
|
173
|
+
placeholder={t(
|
|
174
|
+
'configuration.community.forbiddenUsernames.placeholder',
|
|
175
|
+
{ defaultValue: 'username' },
|
|
176
|
+
)}
|
|
177
|
+
aria-invalid={Boolean(fieldError)}
|
|
178
|
+
onChange={(event) => {
|
|
179
|
+
setDraft(event.target.value);
|
|
180
|
+
setFieldError(null);
|
|
181
|
+
}}
|
|
182
|
+
onKeyDown={(event) => {
|
|
183
|
+
if (event.key !== 'Enter') return;
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
addUsername();
|
|
186
|
+
}}
|
|
187
|
+
data-testid="admin-forbidden-usernames-input"
|
|
188
|
+
/>
|
|
189
|
+
<Button
|
|
190
|
+
variant="outline"
|
|
191
|
+
title={t('configuration.community.forbiddenUsernames.add', {
|
|
192
|
+
defaultValue: 'Add username',
|
|
193
|
+
})}
|
|
194
|
+
action={addUsername}
|
|
195
|
+
data-testid="admin-forbidden-usernames-add"
|
|
196
|
+
>
|
|
197
|
+
{t('configuration.community.forbiddenUsernames.add', {
|
|
198
|
+
defaultValue: 'Add username',
|
|
199
|
+
})}
|
|
200
|
+
</Button>
|
|
201
|
+
</div>
|
|
202
|
+
{fieldError ? (
|
|
203
|
+
<p className="text-error text-sm" role="alert">
|
|
204
|
+
{fieldError}
|
|
205
|
+
</p>
|
|
206
|
+
) : null}
|
|
207
|
+
</div>
|
|
208
|
+
{status ? (
|
|
209
|
+
<Toast variant={status.type} onDismiss={() => setStatus(null)}>
|
|
210
|
+
{status.message}
|
|
211
|
+
</Toast>
|
|
212
|
+
) : null}
|
|
213
|
+
<Button
|
|
214
|
+
variant="default"
|
|
215
|
+
action={save}
|
|
216
|
+
disabled={saving || sameHandles(custom, saved)}
|
|
217
|
+
data-testid="admin-forbidden-usernames-save"
|
|
218
|
+
>
|
|
219
|
+
{t('common.form.save', { defaultValue: 'Save' })}
|
|
220
|
+
</Button>
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -13,8 +13,8 @@ import { roleKeyFromName } from '../../../lib/capabilityMatrix';
|
|
|
13
13
|
const TAB_DEFAULT_ROLE = 'default-role';
|
|
14
14
|
const TAB_ROLES = 'roles';
|
|
15
15
|
const TAB_RELATIONS = 'relations';
|
|
16
|
-
const
|
|
17
|
-
type TabKey = (typeof
|
|
16
|
+
const _TAB_LIST = [TAB_DEFAULT_ROLE, TAB_ROLES, TAB_RELATIONS] as const;
|
|
17
|
+
type TabKey = (typeof _TAB_LIST)[number];
|
|
18
18
|
|
|
19
19
|
function DefaultRoles({ base }: { base: CommunityConfig }) {
|
|
20
20
|
const t = useT();
|