@openpeepshq/react 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/configuration/ConfigurationCategory.js +3 -2
- package/dist/components/configuration/ConfigurationList.js +1 -1
- package/dist/components/form/LocationInput.js +1 -1
- 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/markdown/compileMarkdown.js +1 -0
- package/dist/components/navigation/FooterMobile.js +4 -3
- package/dist/components/navigation/HeaderMobile.js +5 -2
- package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
- package/dist/components/navigation/MobileMenuItem.js +7 -2
- package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
- package/dist/components/navigation/NavWithTooltip.js +4 -0
- package/dist/components/navigation/index.d.ts +2 -0
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
- package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
- package/dist/components/notifications/TypedNotification.js +46 -4
- package/dist/components/post/CompactReplyParent.js +5 -6
- package/dist/components/post/Markdown.d.ts +2 -2
- package/dist/components/post/Markdown.js +1 -1
- package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
- package/dist/components/post/TruncatedMarkdown.js +37 -0
- package/dist/components/post/attachmentPreview.js +1 -1
- package/dist/components/post/helpers.d.ts +2 -2
- package/dist/components/post/helpers.js +3 -16
- package/dist/components/post/index.d.ts +2 -0
- package/dist/components/post/index.js +1 -0
- package/dist/components/post/pieces/Attachments.js +23 -17
- package/dist/components/post/pieces/EventLocation.js +14 -0
- package/dist/components/post/pieces/EventRsvpButton.js +39 -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/PollContent.js +8 -2
- 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/ArticleForm.js +1 -1
- package/dist/components/post/post-form/EventForm.js +33 -5
- package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
- package/dist/components/post/post-form/ResourceForm.js +48 -7
- package/dist/components/post/post-form/VisibilitySelector.js +9 -3
- package/dist/components/post/types/Article.js +2 -3
- package/dist/components/post/types/Event.js +10 -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 +22 -13
- package/dist/components/post/types/event/ProfileEventRelationship.js +8 -0
- package/dist/components/post/types/resource/FullResource.js +3 -3
- 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 +8 -0
- package/dist/components/profile/Avatar.js +2 -2
- package/dist/components/profile/ProfileFromId.js +1 -1
- package/dist/components/resources/ResourceCard.d.ts +5 -1
- package/dist/components/resources/ResourceCard.js +29 -5
- package/dist/components/resources/ResourceCard.test.d.ts +1 -0
- package/dist/components/resources/ResourceCard.test.js +75 -0
- package/dist/components/resources/ResourceLibrary.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 +12 -2
- package/dist/hooks/events/useEventRsvp.js +59 -10
- package/dist/hooks/events/useEventsCalendar.d.ts +174 -76
- package/dist/hooks/groups/useNewGroup.js +22 -2
- package/dist/hooks/index.d.ts +5 -1
- package/dist/hooks/index.js +4 -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 +95 -41
- package/dist/hooks/posts/useResourceComposer.js +135 -27
- package/dist/hooks/posts/useShareMenu.d.ts +2 -0
- package/dist/hooks/posts/useShareMenu.js +7 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +177 -79
- package/dist/hooks/resources/useResourceLibrary.js +6 -2
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/hooks/useWelcomePreview.d.ts +16 -0
- package/dist/hooks/useWelcomePreview.js +40 -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/navigation/menuItems.js +15 -0
- package/dist/navigation/targets.d.ts +2 -0
- 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/CommunityMarkdownPage.js +2 -1
- 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/auth/Register.js +33 -9
- package/dist/pages/conversations/Show.js +11 -0
- 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/resources/Edit.js +3 -3
- package/dist/pages/resources/New.js +2 -2
- package/dist/pages/settings/Account.js +30 -2
- package/dist/pages/settings/PublicProfile.js +15 -3
- package/dist/pwa/sw.d.ts +0 -1
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.js +1 -0
- package/dist/stores/newPosts.d.ts +4 -2
- package/dist/stores/newPosts.js +6 -1
- package/package.json +12 -7
- 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/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/markdown/compileMarkdown.ts +1 -0
- package/src/components/navigation/FooterMobile.tsx +41 -33
- package/src/components/navigation/HeaderMobile.tsx +55 -41
- package/src/components/navigation/MobileMenuItem.tsx +15 -2
- package/src/components/navigation/NavWithTooltip.tsx +26 -0
- package/src/components/navigation/index.ts +2 -0
- package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
- package/src/components/notifications/TypedNotification.tsx +81 -9
- package/src/components/post/CompactReplyParent.tsx +17 -10
- package/src/components/post/Markdown.tsx +8 -2
- package/src/components/post/TruncatedMarkdown.tsx +91 -0
- package/src/components/post/attachmentPreview.ts +1 -3
- package/src/components/post/helpers.ts +4 -18
- package/src/components/post/index.ts +2 -0
- package/src/components/post/pieces/Attachments.tsx +93 -78
- package/src/components/post/pieces/EventLocation.tsx +27 -0
- package/src/components/post/pieces/EventRsvpButton.tsx +110 -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/PollContent.tsx +8 -2
- package/src/components/post/pieces/PostActions.tsx +73 -42
- package/src/components/post/pieces/ShareMenu.tsx +67 -9
- package/src/components/post/post-form/ArticleForm.tsx +1 -1
- package/src/components/post/post-form/EventForm.tsx +69 -15
- package/src/components/post/post-form/ResourceForm.tsx +132 -4
- package/src/components/post/post-form/VisibilitySelector.tsx +12 -5
- package/src/components/post/types/Article.tsx +6 -6
- package/src/components/post/types/Event.tsx +68 -7
- 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 +48 -35
- 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/post/types/resource/FullResource.tsx +9 -1
- 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 +45 -0
- package/src/components/profile/Avatar.tsx +6 -2
- package/src/components/profile/ProfileFromId.tsx +1 -5
- package/src/components/resources/ResourceCard.tsx +68 -11
- package/src/components/resources/ResourceLibrary.tsx +2 -2
- 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 +69 -13
- package/src/hooks/groups/useNewGroup.ts +28 -3
- package/src/hooks/index.ts +8 -1
- package/src/hooks/jams/useCanDiagnoseLivekit.ts +5 -0
- package/src/hooks/posts/useResourceComposer.ts +165 -39
- package/src/hooks/posts/useShareMenu.ts +9 -0
- package/src/hooks/resources/useResourceLibrary.ts +6 -2
- package/src/hooks/useWelcomePreview.ts +61 -0
- package/src/i18n/I18nProvider.tsx +1 -4
- package/src/lib/groupFormErrors.ts +9 -2
- package/src/lib/threadHelpers.ts +1 -5
- package/src/navigation/menuItems.ts +16 -0
- package/src/navigation/targets.ts +2 -0
- 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/CommunityMarkdownPage.tsx +5 -1
- package/src/pages/admin/community/CommunityRoles.tsx +2 -2
- package/src/pages/admin/components/EditInviteLinkModal.tsx +263 -0
- package/src/pages/auth/Register.tsx +45 -4
- package/src/pages/conversations/Show.tsx +11 -0
- package/src/pages/index.ts +3 -0
- package/src/pages/jams/Index.tsx +2 -6
- package/src/pages/resources/Edit.tsx +3 -2
- package/src/pages/resources/New.tsx +6 -1
- package/src/pages/settings/Account.tsx +51 -1
- 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 +1 -0
- 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
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { normalizeResourceTags,
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { checkGroupCapabilities, normalizeResourceTags, resourceFormIssues, resourceVisibilityForCapabilities, } from '@openpeepshq/common/lib';
|
|
3
3
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
4
4
|
import { useNavigate } from '../../contexts/router/index.js';
|
|
5
5
|
import { useT } from '../../i18n/context.js';
|
|
6
|
+
import { useAuthData, useCurrentProfile, } from '../../components/layout/IdentityContext.js';
|
|
6
7
|
import { useServerInfo } from '../../components/server-data/index.js';
|
|
8
|
+
import { buildAudienceChoiceValues } from '../../lib/audienceChoices.js';
|
|
7
9
|
import { defaultNewResource, getNewPostStores } from '../../stores/index.js';
|
|
8
|
-
const asResource = (data) => data
|
|
10
|
+
const asResource = (data) => data?.type === 'resource' ? data : null;
|
|
9
11
|
const preparedResource = (resource) => ({
|
|
10
12
|
...resource,
|
|
11
13
|
title: resource.title.trim(),
|
|
@@ -13,12 +15,69 @@ const preparedResource = (resource) => ({
|
|
|
13
15
|
categoryPath: (resource.categoryPath ?? [])
|
|
14
16
|
.map((segment) => segment.trim())
|
|
15
17
|
.filter(Boolean),
|
|
16
|
-
url: resource.
|
|
18
|
+
url: resource.resourceKind === 'link'
|
|
19
|
+
? resource.url?.trim() || undefined
|
|
20
|
+
: undefined,
|
|
17
21
|
});
|
|
22
|
+
const issuesFor = (postData) => {
|
|
23
|
+
const resource = asResource(postData.data);
|
|
24
|
+
if (!resource)
|
|
25
|
+
return ['title'];
|
|
26
|
+
return resourceFormIssues({
|
|
27
|
+
title: resource.title,
|
|
28
|
+
resourceKind: resource.resourceKind,
|
|
29
|
+
url: resource.url,
|
|
30
|
+
attachments: resource.attachments,
|
|
31
|
+
visibility: postData.visibility,
|
|
32
|
+
audience: postData.audience,
|
|
33
|
+
groupId: postData.groupId,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const issueMessage = (issue, t) => {
|
|
37
|
+
if (issue === 'title') {
|
|
38
|
+
return t('resources.validation.titleRequired', {
|
|
39
|
+
defaultValue: 'Title is required',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (issue === 'titleLength') {
|
|
43
|
+
return t('resources.validation.titleTooLong', {
|
|
44
|
+
defaultValue: 'Title must be 200 characters or fewer',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (issue === 'url') {
|
|
48
|
+
return t('resources.validation.url', {
|
|
49
|
+
defaultValue: 'Enter a real link, like https://example.com',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (issue === 'media') {
|
|
53
|
+
return t('resources.validation.mediaRequired', {
|
|
54
|
+
defaultValue: 'Add the media or link this resource needs',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (issue === 'group') {
|
|
58
|
+
return t('resources.validation.groupRequired', {
|
|
59
|
+
defaultValue: 'Choose a group before creating this resource.',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return t('resources.validation.directAudience', {
|
|
63
|
+
defaultValue: 'Choose at least one recipient for a direct resource.',
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const submitErrorMessage = (err, t) => {
|
|
67
|
+
const message = err instanceof Error ? err.message : '';
|
|
68
|
+
if (message === 'Forbidden') {
|
|
69
|
+
return t('resources.validation.audienceForbidden', {
|
|
70
|
+
defaultValue: 'Choose a group you can post this resource in.',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return message;
|
|
74
|
+
};
|
|
18
75
|
export const useNewResource = () => {
|
|
19
76
|
const t = useT();
|
|
20
77
|
const navigate = useNavigate();
|
|
21
78
|
const serverInfo = useServerInfo();
|
|
79
|
+
const authData = useAuthData();
|
|
80
|
+
const me = useCurrentProfile();
|
|
22
81
|
const { openpeepsApi } = useOpenpeeps();
|
|
23
82
|
const createPost = openpeepsApi.createPostAction();
|
|
24
83
|
const stores = getNewPostStores();
|
|
@@ -31,33 +90,71 @@ export const useNewResource = () => {
|
|
|
31
90
|
});
|
|
32
91
|
const [submitting, setSubmitting] = useState(false);
|
|
33
92
|
const [error, setError] = useState(null);
|
|
93
|
+
const audience = useMemo(() => {
|
|
94
|
+
if (!authData.profile || authData.scopes.length === 0)
|
|
95
|
+
return null;
|
|
96
|
+
const choices = buildAudienceChoiceValues('resource', authData, t, {
|
|
97
|
+
publicContent: serverInfo.publicContent,
|
|
98
|
+
showDirect: true,
|
|
99
|
+
});
|
|
100
|
+
const memberships = me?.memberships;
|
|
101
|
+
const postableGroupIds = memberships == null
|
|
102
|
+
? null
|
|
103
|
+
: memberships
|
|
104
|
+
.map((membership) => membership.group)
|
|
105
|
+
.filter((group) => checkGroupCapabilities(authData, ['core-posts-create-resource'], group).success)
|
|
106
|
+
.map((group) => group.id);
|
|
107
|
+
const next = resourceVisibilityForCapabilities({
|
|
108
|
+
visibility: postData.visibility,
|
|
109
|
+
groupId: postData.groupId,
|
|
110
|
+
allowed: choices.map((choice) => choice.value),
|
|
111
|
+
postableGroupIds,
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
...next,
|
|
115
|
+
groupOnly: choices.length === 1 && choices[0]?.value === 'group',
|
|
116
|
+
hasChoice: choices.length > 0,
|
|
117
|
+
};
|
|
118
|
+
}, [
|
|
119
|
+
authData,
|
|
120
|
+
me?.memberships,
|
|
121
|
+
postData.groupId,
|
|
122
|
+
postData.visibility,
|
|
123
|
+
serverInfo.publicContent,
|
|
124
|
+
t,
|
|
125
|
+
]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!audience?.hasChoice)
|
|
128
|
+
return;
|
|
129
|
+
if (audience.visibility === postData.visibility &&
|
|
130
|
+
(audience.groupId ?? undefined) === (postData.groupId ?? undefined)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const next = {
|
|
134
|
+
...postData,
|
|
135
|
+
visibility: audience.visibility,
|
|
136
|
+
groupId: audience.groupId,
|
|
137
|
+
};
|
|
138
|
+
setPostDataState(next);
|
|
139
|
+
stores.resource = next;
|
|
140
|
+
}, [audience, postData, stores]);
|
|
34
141
|
const resource = asResource(postData.data);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
142
|
+
const audienceReady = !!audience?.hasChoice &&
|
|
143
|
+
audience.visibility === postData.visibility &&
|
|
144
|
+
(audience.groupId ?? undefined) === (postData.groupId ?? undefined);
|
|
145
|
+
const canSubmit = audienceReady && issuesFor(postData).length === 0;
|
|
39
146
|
const setPostData = (data) => {
|
|
40
147
|
setPostDataState(data);
|
|
41
148
|
stores.resource = data;
|
|
42
149
|
};
|
|
43
150
|
const submit = useCallback(async () => {
|
|
44
151
|
setError(null);
|
|
45
|
-
if (!
|
|
46
|
-
setError(t('resources.validation.titleRequired', {
|
|
47
|
-
defaultValue: 'Title is required',
|
|
48
|
-
}));
|
|
152
|
+
if (!audienceReady)
|
|
49
153
|
return;
|
|
50
|
-
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (postData.visibility === 'direct' && !postData.audience?.length) {
|
|
58
|
-
setError(t('resources.validation.directAudience', {
|
|
59
|
-
defaultValue: 'Choose at least one recipient for a direct resource.',
|
|
60
|
-
}));
|
|
154
|
+
const issue = issuesFor(postData)[0];
|
|
155
|
+
if (!resource || issue) {
|
|
156
|
+
if (issue)
|
|
157
|
+
setError(issueMessage(issue, t));
|
|
61
158
|
return;
|
|
62
159
|
}
|
|
63
160
|
setSubmitting(true);
|
|
@@ -71,15 +168,16 @@ export const useNewResource = () => {
|
|
|
71
168
|
navigate({ type: 'post', id: created.id });
|
|
72
169
|
}
|
|
73
170
|
catch (err) {
|
|
74
|
-
setError(err
|
|
171
|
+
setError(submitErrorMessage(err, t));
|
|
75
172
|
}
|
|
76
173
|
finally {
|
|
77
174
|
setSubmitting(false);
|
|
78
175
|
}
|
|
79
|
-
}, [createPost, navigate, postData, resource, stores, t]);
|
|
176
|
+
}, [audienceReady, createPost, navigate, postData, resource, stores, t]);
|
|
80
177
|
return {
|
|
81
178
|
postData,
|
|
82
179
|
setPostData,
|
|
180
|
+
groupOnly: audience?.groupOnly ?? false,
|
|
83
181
|
canSubmit,
|
|
84
182
|
submitting,
|
|
85
183
|
error,
|
|
@@ -88,6 +186,7 @@ export const useNewResource = () => {
|
|
|
88
186
|
};
|
|
89
187
|
};
|
|
90
188
|
export const useEditResource = (resourceId) => {
|
|
189
|
+
const t = useT();
|
|
91
190
|
const navigate = useNavigate();
|
|
92
191
|
const { openpeepsApi } = useOpenpeeps();
|
|
93
192
|
const postQuery = openpeepsApi.usePost(resourceId);
|
|
@@ -96,7 +195,9 @@ export const useEditResource = (resourceId) => {
|
|
|
96
195
|
const [submitting, setSubmitting] = useState(false);
|
|
97
196
|
const [error, setError] = useState(null);
|
|
98
197
|
useEffect(() => {
|
|
99
|
-
if (postQuery.data &&
|
|
198
|
+
if (postQuery.data &&
|
|
199
|
+
postQuery.data.type === 'resource' &&
|
|
200
|
+
postQuery.data.data) {
|
|
100
201
|
setPostData({
|
|
101
202
|
visibility: postQuery.data.visibility,
|
|
102
203
|
type: 'resource',
|
|
@@ -107,6 +208,7 @@ export const useEditResource = (resourceId) => {
|
|
|
107
208
|
}
|
|
108
209
|
}, [postQuery.data]);
|
|
109
210
|
const resourceTitle = asResource(postQuery.data?.data)?.title;
|
|
211
|
+
const canSubmit = !!postData && issuesFor(postData).length === 0;
|
|
110
212
|
const submit = useCallback(async () => {
|
|
111
213
|
if (!postData)
|
|
112
214
|
return;
|
|
@@ -114,6 +216,11 @@ export const useEditResource = (resourceId) => {
|
|
|
114
216
|
if (!resource)
|
|
115
217
|
return;
|
|
116
218
|
setError(null);
|
|
219
|
+
const issue = issuesFor(postData)[0];
|
|
220
|
+
if (issue) {
|
|
221
|
+
setError(issueMessage(issue, t));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
117
224
|
setSubmitting(true);
|
|
118
225
|
try {
|
|
119
226
|
await updatePost(preparedResource(resource));
|
|
@@ -125,12 +232,13 @@ export const useEditResource = (resourceId) => {
|
|
|
125
232
|
finally {
|
|
126
233
|
setSubmitting(false);
|
|
127
234
|
}
|
|
128
|
-
}, [navigate, postData, resourceId, updatePost]);
|
|
235
|
+
}, [navigate, postData, resourceId, t, updatePost]);
|
|
129
236
|
return {
|
|
130
237
|
postQuery,
|
|
131
238
|
postData,
|
|
132
239
|
setPostData,
|
|
133
240
|
resourceTitle,
|
|
241
|
+
canSubmit,
|
|
134
242
|
submitting,
|
|
135
243
|
error,
|
|
136
244
|
clearError: () => setError(null),
|
|
@@ -3,6 +3,8 @@ export type EventIcsFile = {
|
|
|
3
3
|
filename: string;
|
|
4
4
|
content: string;
|
|
5
5
|
};
|
|
6
|
+
/** Canonical public path for a post, including a recurring event occurrence. */
|
|
7
|
+
export declare const postPublicPath: (post: Pick<PublicPost, "id" | "occurrenceRecurrenceId">) => string;
|
|
6
8
|
/** Share actions for a post; `postUrl` is the platform's canonical public link. */
|
|
7
9
|
export declare const useShareMenu: (post: PublicPost, postUrl: string) => {
|
|
8
10
|
signedIn: boolean;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { buildEventIcs } from '@openpeepshq/common/lib';
|
|
2
2
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
3
3
|
import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
|
|
4
|
+
/** Canonical public path for a post, including a recurring event occurrence. */
|
|
5
|
+
export const postPublicPath = (post) => {
|
|
6
|
+
const occurrence = post.occurrenceRecurrenceId;
|
|
7
|
+
if (!occurrence)
|
|
8
|
+
return `/posts/${post.id}`;
|
|
9
|
+
return `/posts/${post.id}?occurrence=${encodeURIComponent(occurrence)}`;
|
|
10
|
+
};
|
|
4
11
|
/** Share actions for a post; `postUrl` is the platform's canonical public link. */
|
|
5
12
|
export const useShareMenu = (post, postUrl) => {
|
|
6
13
|
const me = useCurrentProfile();
|