-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat: adds kebab menu to contact center and delete contact item #36791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3597234
chore: adds new action column to contact center
lucas-a-pelegrino 38cad53
tests: adds unit testing for disableContactById
lucas-a-pelegrino a290736
feat: adds new permission and setting to handle livechat contact removal
lucas-a-pelegrino c47f76e
tests: adds setting check for unit/e2e tests
lucas-a-pelegrino 98f9a5d
chore: addresses pull request requested changes
lucas-a-pelegrino 974c154
chore: addresses further PR requested changes
lucas-a-pelegrino a2acef2
tests: moves disableContact.spec.ts to tests/unit/
lucas-a-pelegrino c9774de
feat: adds kebab menu to contact center for contact removal
lucas-a-pelegrino 38f843f
feat: adds the edit option on the kebab menu as well as some improvem…
lucas-a-pelegrino 4092baa
feat: adds minor improvements to kebab menu options build
lucas-a-pelegrino 4aab973
fix: toast message not showing up
lucas-a-pelegrino 8cace9b
chore: adds minor improvements to RemoveContactModal
lucas-a-pelegrino 4a88529
tests: adds UI tests for contact removal
lucas-a-pelegrino 85704cc
fix: i18n label for contact removal confirmation
lucas-a-pelegrino 9b7474b
fix: updates text aria label getter
lucas-a-pelegrino 49c9818
chore: applies code review requested changes
lucas-a-pelegrino c48a175
fix: removes .only from test
lucas-a-pelegrino 4a6ed13
tests: adds a test assertion that validates input is correctly parsin…
lucas-a-pelegrino 4241012
chore: adds minor improvements to contact removal confirmation logic
lucas-a-pelegrino e5ec42e
tests: minor improvements to contact center test setup hooks
lucas-a-pelegrino 76c916c
fix: linting error
lucas-a-pelegrino 97a6ace
fix: error messages not displaying on toast
lucas-a-pelegrino e9d7243
Merge branch 'develop' into feat/CTZ-173-FE
lucas-a-pelegrino 54773e1
Merge branch 'develop' into feat/CTZ-173-FE
kodiakhq[bot] 5e60e26
Merge branch 'develop' into feat/CTZ-173-FE
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
apps/meteor/client/views/omnichannel/directory/contacts/ContactItemMenu.tsx
This file contains hidden or 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,61 @@ | ||
| import type { ILivechatContactChannel } from '@rocket.chat/core-typings'; | ||
| import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
| import type { GenericMenuItemProps } from '@rocket.chat/ui-client'; | ||
| import { GenericMenu } from '@rocket.chat/ui-client'; | ||
| import { useRouter, useSetModal, usePermission } from '@rocket.chat/ui-contexts'; | ||
| import type { ReactElement } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import RemoveContactModal from './RemoveContactModal'; | ||
|
|
||
| type ContactItemMenuProps = { | ||
| _id: string; | ||
| name: string; | ||
| channels: ILivechatContactChannel[]; | ||
| }; | ||
|
|
||
| const ContactItemMenu = ({ _id, name, channels }: ContactItemMenuProps): ReactElement => { | ||
| const { t } = useTranslation(); | ||
| const setModal = useSetModal(); | ||
| const router = useRouter(); | ||
|
|
||
| const canEditContact = usePermission('update-livechat-contact'); | ||
| const canDeleteContact = usePermission('delete-livechat-contact'); | ||
|
|
||
| const handleContactEdit = useEffectEvent((): void => | ||
| router.navigate({ | ||
| pattern: '/omnichannel-directory/:tab?/:context?/:id?', | ||
| params: { | ||
| tab: 'contacts', | ||
| context: 'edit', | ||
| id: _id, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const handleContactRemoval = useEffectEvent(() => { | ||
| setModal(<RemoveContactModal _id={_id} name={name} channelsCount={channels.length} onClose={() => setModal(null)} />); | ||
| }); | ||
|
|
||
| const menuOptions: GenericMenuItemProps[] = [ | ||
| { | ||
| id: 'edit', | ||
| icon: 'edit', | ||
| content: t('edit'), | ||
| onClick: () => handleContactEdit(), | ||
| disabled: !canEditContact, | ||
| }, | ||
| { | ||
| id: 'delete', | ||
| icon: 'trash', | ||
| content: t('Delete'), | ||
| onClick: () => handleContactRemoval(), | ||
| variant: 'danger', | ||
| disabled: !canDeleteContact, | ||
| }, | ||
| ]; | ||
|
|
||
| return <GenericMenu detached title={t('More_actions')} sections={[{ title: '', items: menuOptions }]} placement='bottom-end' />; | ||
| }; | ||
|
|
||
| export default ContactItemMenu; | ||
This file contains hidden or 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
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
apps/meteor/client/views/omnichannel/directory/contacts/RemoveContactModal.tsx
This file contains hidden or 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,76 @@ | ||
| import { Box, Input } from '@rocket.chat/fuselage'; | ||
| import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
| import { GenericModal } from '@rocket.chat/ui-client'; | ||
| import { useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts'; | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import type { ReactElement, ChangeEvent } from 'react'; | ||
| import { useState, useId } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| type RemoveContactModalProps = { | ||
| _id: string; | ||
| name: string; | ||
| channelsCount: number; | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| const RemoveContactModal = ({ _id, name, channelsCount, onClose }: RemoveContactModalProps): ReactElement => { | ||
| const { t } = useTranslation(); | ||
| const [text, setText] = useState<string>(''); | ||
|
|
||
| const queryClient = useQueryClient(); | ||
| const removeContact = useEndpoint('POST', '/v1/omnichannel/contacts.delete'); | ||
| const dispatchToast = useToastMessageDispatch(); | ||
| const contactDeleteModalId = useId(); | ||
|
|
||
| const handleSubmit = useEffectEvent((event: ChangeEvent<HTMLFormElement>): void => { | ||
| event.preventDefault(); | ||
| removeContactMutation.mutate(); | ||
| }); | ||
|
|
||
| const removeContactMutation = useMutation({ | ||
| mutationFn: () => removeContact({ contactId: _id }), | ||
| onSuccess: async () => { | ||
| dispatchToast({ type: 'success', message: t('Contact_has_been_deleted') }); | ||
| await Promise.all([ | ||
| queryClient.invalidateQueries({ | ||
| queryKey: ['current-contacts'], | ||
| }), | ||
| queryClient.invalidateQueries({ | ||
| queryKey: ['getContactsByIds', _id], | ||
| }), | ||
| ]); | ||
| onClose(); | ||
| }, | ||
| onError: (error) => { | ||
| dispatchToast({ type: 'error', message: t(error.message, { defaultValue: t('error-contact-something-went-wrong') }) }); | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <GenericModal | ||
| wrapperFunction={(props) => <Box is='form' onSubmit={handleSubmit} {...props} />} | ||
| onCancel={onClose} | ||
| confirmText={t('Delete')} | ||
| title={t('Delete_Contact')} | ||
| onClose={onClose} | ||
| variant='danger' | ||
| confirmDisabled={text !== t('Delete').toLowerCase()} | ||
lucas-a-pelegrino marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| > | ||
| <Box is='p' id={`${contactDeleteModalId}-description`} mbe={16}> | ||
| {t('Are_you_sure_delete_contact', { contactName: name, channelsCount })} | ||
| </Box> | ||
| <Box mbe={16} display='flex' justifyContent='stretch'> | ||
| <Input | ||
| value={text} | ||
| name='confirmContactRemoval' | ||
| aria-label={t('Confirm_contact_removal')} | ||
| aria-describedby={`${contactDeleteModalId}-description`} | ||
| onChange={(event: ChangeEvent<HTMLInputElement>) => setText(event.currentTarget.value)} | ||
| /> | ||
| </Box> | ||
| </GenericModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default RemoveContactModal; | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.