-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Create the modals that will allow the user to confirm role dele…
…tion Summary: This should be the final stack in the entire roles project. This is the client-side logic for `web` to handle role deletion. Per the designs, the warning message is the same as on `native`, with either a generic deletion message if nobody is assigned the role or a more specific one if members have this custom role. [[ https://linear.app/comm/issue/ENG-4432/create-the-modals-that-will-allow-the-user-to-confirm-role-deletion | ENG-4432 ]] Depends on D8624 Test Plan: Verified that the modal appears as expected for roles with and without members, and pressing the delete button actually deletes {F653374} Reviewers: atul, ginsu Reviewed By: atul Subscribers: tomek, ashoat Differential Revision: https://phab.comm.dev/D8625
- Loading branch information
Showing
3 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.roleDeletionText { | ||
color: var(--modal-fg); | ||
font-size: var(--m-font-14); | ||
padding: 16px 32px; | ||
} | ||
|
||
.buttonsContainer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: flex-end; | ||
padding: 16px 32px; | ||
} | ||
|
||
.cancelButton { | ||
width: 100px; | ||
} | ||
|
||
.deleteRoleButton { | ||
margin-left: 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
|
||
import { | ||
deleteCommunityRole, | ||
deleteCommunityRoleActionTypes, | ||
} from 'lib/actions/thread-actions.js'; | ||
import { useModalContext } from 'lib/components/modal-provider.react.js'; | ||
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; | ||
import { useRoleMemberCountsForCommunity } from 'lib/shared/thread-utils.js'; | ||
import type { LoadingStatus } from 'lib/types/loading-types.js'; | ||
import type { ThreadInfo } from 'lib/types/thread-types.js'; | ||
import { | ||
useServerCall, | ||
useDispatchActionPromise, | ||
} from 'lib/utils/action-utils.js'; | ||
import { constructRoleDeletionMessagePrompt } from 'lib/utils/role-utils.js'; | ||
|
||
import css from './delete-role-modal.css'; | ||
import Button, { buttonThemes } from '../components/button.react.js'; | ||
import LoadingIndicator from '../loading-indicator.react.js'; | ||
import Modal from '../modals/modal.react.js'; | ||
import { useSelector } from '../redux/redux-utils.js'; | ||
|
||
const deleteRoleLoadingStatusSelector = createLoadingStatusSelector( | ||
deleteCommunityRoleActionTypes, | ||
); | ||
|
||
type DeleteRoleModalProps = { | ||
+threadInfo: ThreadInfo, | ||
+defaultRoleID: string, | ||
+roleID: string, | ||
}; | ||
|
||
function DeleteRoleModal(props: DeleteRoleModalProps): React.Node { | ||
const { threadInfo, defaultRoleID, roleID } = props; | ||
const { popModal } = useModalContext(); | ||
|
||
const callDeleteCommunityRole = useServerCall(deleteCommunityRole); | ||
const dispatchActionPromise = useDispatchActionPromise(); | ||
|
||
const deleteRoleLoadingStatus: LoadingStatus = useSelector( | ||
deleteRoleLoadingStatusSelector, | ||
); | ||
|
||
const roleNamesToMemberCounts = useRoleMemberCountsForCommunity(threadInfo); | ||
const roleName = threadInfo.roles[roleID].name; | ||
const memberCount = roleNamesToMemberCounts[roleName]; | ||
const defaultRoleName = threadInfo.roles[defaultRoleID].name; | ||
|
||
const message = constructRoleDeletionMessagePrompt( | ||
defaultRoleName, | ||
memberCount, | ||
); | ||
|
||
const onDeleteRole = React.useCallback(() => { | ||
dispatchActionPromise( | ||
deleteCommunityRoleActionTypes, | ||
(async () => { | ||
const response = await callDeleteCommunityRole({ | ||
community: threadInfo.id, | ||
roleID: roleID, | ||
}); | ||
popModal(); | ||
return response; | ||
})(), | ||
); | ||
}, [ | ||
callDeleteCommunityRole, | ||
dispatchActionPromise, | ||
roleID, | ||
threadInfo.id, | ||
popModal, | ||
]); | ||
|
||
const deleteButtonContent = React.useMemo(() => { | ||
if (deleteRoleLoadingStatus === 'loading') { | ||
return ( | ||
<LoadingIndicator status={deleteRoleLoadingStatus} size="medium" /> | ||
); | ||
} | ||
return 'Yes, delete role'; | ||
}, [deleteRoleLoadingStatus]); | ||
|
||
return ( | ||
<Modal name="Delete role" onClose={popModal} size="large"> | ||
<div className={css.roleDeletionText}>{message}</div> | ||
<div className={css.buttonsContainer}> | ||
<Button | ||
variant="outline" | ||
className={css.cancelButton} | ||
buttonColor={buttonThemes.outline} | ||
onClick={popModal} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="filled" | ||
className={css.deleteRoleButton} | ||
buttonColor={buttonThemes.danger} | ||
onClick={onDeleteRole} | ||
> | ||
{deleteButtonContent} | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default DeleteRoleModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters