Page MenuHomePhabricator

D8597.id29063.diff
No OneTemporary

D8597.id29063.diff

diff --git a/web/roles/create-roles-modal.css b/web/roles/create-roles-modal.css
--- a/web/roles/create-roles-modal.css
+++ b/web/roles/create-roles-modal.css
@@ -16,6 +16,17 @@
margin: 8px 0 12px 0;
}
+.errorMessage {
+ color: var(--error);
+ font-size: var(--s-font-14);
+ align-self: center;
+ visibility: hidden;
+}
+
+.errorMessageVisible {
+ visibility: visible;
+}
+
.separator {
border: 0;
margin: 16px 32px 8px 32px;
diff --git a/web/roles/create-roles-modal.react.js b/web/roles/create-roles-modal.react.js
--- a/web/roles/create-roles-modal.react.js
+++ b/web/roles/create-roles-modal.react.js
@@ -14,6 +14,7 @@
useServerCall,
useDispatchActionPromise,
} from 'lib/utils/action-utils.js';
+import { values } from 'lib/utils/objects.js';
import css from './create-roles-modal.css';
import {
@@ -47,8 +48,12 @@
const [pendingRolePermissions, setPendingRolePermissions] =
React.useState<$ReadOnlyArray<UserSurfacedPermission>>(rolePermissions);
+ const [roleCreationFailed, setRoleCreationFailed] =
+ React.useState<boolean>(false);
+
const onChangeRoleName = React.useCallback(
(event: SyntheticEvent<HTMLInputElement>) => {
+ setRoleCreationFailed(false);
setPendingRoleName(event.currentTarget.value);
},
[],
@@ -132,8 +137,17 @@
],
);
+ const errorMessageClassNames = classNames({
+ [css.errorMessage]: true,
+ [css.errorMessageVisible]: roleCreationFailed,
+ });
+
const onClickCreateRole = React.useCallback(() => {
- // TODO: Error handling in a later diff
+ const threadRoleNames = values(threadInfo.roles).map(role => role.name);
+ if (threadRoleNames.includes(pendingRoleName) && action === 'create_role') {
+ setRoleCreationFailed(true);
+ return;
+ }
dispatchActionPromise(
modifyCommunityRoleActionTypes,
@@ -169,6 +183,9 @@
onChange={onChangeRoleName}
/>
</div>
+ <div className={errorMessageClassNames}>
+ There is already a role with this name in the community
+ </div>
</form>
<hr className={css.separator} />
<div className={css.permissionsHeaderContainer}>

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 6:48 PM (22 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601994
Default Alt Text
D8597.id29063.diff (2 KB)

Event Timeline