Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3559375
D5211.id16981.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D5211.id16981.diff
View Options
diff --git a/web/modals/threads/create/compose-subchannel-modal.react.js b/web/modals/threads/create/compose-subchannel-modal.react.js
--- a/web/modals/threads/create/compose-subchannel-modal.react.js
+++ b/web/modals/threads/create/compose-subchannel-modal.react.js
@@ -1,10 +1,19 @@
// @flow
import * as React from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { newThread, newThreadActionTypes } from 'lib/actions/thread-actions';
import type { ThreadInfo } from 'lib/types/thread-types';
+import { threadTypes } from 'lib/types/thread-types';
+import {
+ useDispatchActionPromise,
+ useServerCall,
+} from 'lib/utils/action-utils';
import { trimText } from 'lib/utils/text-utils';
import Stepper from '../../../components/stepper.react';
+import { updateNavInfoActionType } from '../../../redux/action-types';
+import { nonThreadCalendarQuery } from '../../../selectors/nav-selectors';
import Modal from '../../modal.react';
import css from './compose-subchannel-modal.css';
import SubchannelMembers from './steps/subchannel-members.react';
@@ -15,6 +24,17 @@
+parentThreadInfo: ThreadInfo,
};
+const threadTypesMatrix = {
+ open: [
+ threadTypes.COMMUNITY_OPEN_SUBTHREAD,
+ threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD,
+ ],
+ closed: [
+ threadTypes.COMMUNITY_SECRET_SUBTHREAD,
+ threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD,
+ ],
+};
+
type Pages = 'settings' | 'members';
type VisibilityType = 'open' | 'closed';
@@ -50,6 +70,70 @@
);
const [searchUserText, setSearchUserText] = React.useState<string>('');
+ const [isLoading, setIsLoading] = React.useState<boolean>(false);
+ const [errorMessage, setErrorMessage] = React.useState<string>('');
+
+ const calendarQuery = useSelector(nonThreadCalendarQuery);
+ const callNewThread = useServerCall(newThread);
+
+ const dispatchActionPromise = useDispatchActionPromise();
+ const dispatch = useDispatch();
+
+ const createSubchannel = React.useCallback(async () => {
+ try {
+ const threadType = threadTypesMatrix[visibilityType][+announcement];
+ const query = calendarQuery();
+ const result = await callNewThread({
+ name: channelName,
+ type: threadType,
+ parentThreadID: parentThreadInfo.id,
+ initialMemberIDs: Array.from(selectedUsers),
+ calendarQuery: query,
+ color: parentThreadInfo.color,
+ });
+
+ return result;
+ } catch (e) {
+ await setIsLoading(false);
+ await setErrorMessage(
+ e.message === 'invalid_parameters'
+ ? 'annoucement channels currently not available'
+ : 'unknown error',
+ );
+
+ return null;
+ }
+ }, [
+ parentThreadInfo,
+ selectedUsers,
+ visibilityType,
+ announcement,
+ callNewThread,
+ calendarQuery,
+ channelName,
+ ]);
+
+ const dispatchCreateSubchannel = React.useCallback(async () => {
+ await setErrorMessage('');
+ await setIsLoading(true);
+
+ const response = createSubchannel();
+ await dispatchActionPromise(newThreadActionTypes, response);
+ const result = await response;
+
+ if (result) {
+ const { newThreadID } = result;
+ await dispatch({
+ type: updateNavInfoActionType,
+ payload: {
+ activeChatThreadID: newThreadID,
+ },
+ });
+
+ props.onClose();
+ }
+ }, [dispatchActionPromise, createSubchannel, props, dispatch]);
+
const handleChanges = React.useCallback(
(
event: SyntheticEvent<HTMLInputElement>,
@@ -127,6 +211,7 @@
content: 'Next',
disabled: !channelName.trim(),
onClick: () => {
+ setErrorMessage('');
setChannelName(channelName.trim());
setActiveStep('members');
},
@@ -139,13 +224,15 @@
},
nextProps: {
content: 'Create',
+ loading: isLoading,
+ disabled: selectedUsers.size === 0,
onClick: () => {
- /// TODO: make form logic
+ dispatchCreateSubchannel();
},
},
},
}),
- [channelName],
+ [channelName, dispatchCreateSubchannel, isLoading, selectedUsers],
);
const subchannelMembers = React.useMemo(
@@ -180,6 +267,7 @@
key="members"
prevProps={stepperButtons.members.prevProps}
nextProps={stepperButtons.members.nextProps}
+ errorMessage={errorMessage}
/>,
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 5:58 AM (3 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2724117
Default Alt Text
D5211.id16981.diff (4 KB)
Attached To
Mode
D5211: [web] Connect `ComposeSubchannel` modal with keyserver
Attached
Detach File
Event Timeline
Log In to Comment