-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
link
action to composer toolbar (#31679)
Co-authored-by: Douglas Fabris <[email protected]>
- Loading branch information
1 parent
6e3fe3a
commit 3efefa3
Showing
7 changed files
with
150 additions
and
23 deletions.
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,6 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/i18n": minor | ||
--- | ||
|
||
Added a new formatter shortcut to add hyperlinks to a message |
65 changes: 65 additions & 0 deletions
65
apps/meteor/app/ui-message/client/messageBox/AddLinkComposerActionModal.tsx
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,65 @@ | ||
import { Field, FieldGroup, TextInput, FieldLabel, FieldRow, Box } from '@rocket.chat/fuselage'; | ||
import { useUniqueId } from '@rocket.chat/fuselage-hooks'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React, { useEffect } from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
import GenericModal from '../../../../client/components/GenericModal'; | ||
|
||
type AddLinkComposerActionModalProps = { | ||
selectedText?: string; | ||
onConfirm: (url: string, text: string) => void; | ||
onClose: () => void; | ||
}; | ||
|
||
const AddLinkComposerActionModal = ({ selectedText, onClose, onConfirm }: AddLinkComposerActionModalProps) => { | ||
const t = useTranslation(); | ||
const textField = useUniqueId(); | ||
const urlField = useUniqueId(); | ||
|
||
const { handleSubmit, setFocus, control } = useForm({ | ||
mode: 'onBlur', | ||
defaultValues: { | ||
text: selectedText || '', | ||
url: '', | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
setFocus(selectedText ? 'url' : 'text'); | ||
}, [selectedText, setFocus]); | ||
|
||
const onClickConfirm = ({ url, text }: { url: string; text: string }) => { | ||
onConfirm(url, text); | ||
}; | ||
|
||
const submit = handleSubmit(onClickConfirm); | ||
|
||
return ( | ||
<GenericModal | ||
variant='warning' | ||
icon={null} | ||
confirmText={t('Add')} | ||
onCancel={onClose} | ||
wrapperFunction={(props) => <Box is='form' onSubmit={(e) => void submit(e)} {...props} />} | ||
title={t('Add_link')} | ||
> | ||
<FieldGroup> | ||
<Field> | ||
<FieldLabel htmlFor={textField}>{t('Text')}</FieldLabel> | ||
<FieldRow> | ||
<Controller control={control} name='text' render={({ field }) => <TextInput autoComplete='off' id={textField} {...field} />} /> | ||
</FieldRow> | ||
</Field> | ||
<Field> | ||
<FieldLabel htmlFor={urlField}>{t('URL')}</FieldLabel> | ||
<FieldRow> | ||
<Controller control={control} name='url' render={({ field }) => <TextInput autoComplete='off' id={urlField} {...field} />} /> | ||
</FieldRow> | ||
</Field> | ||
</FieldGroup> | ||
</GenericModal> | ||
); | ||
}; | ||
|
||
export default AddLinkComposerActionModal; |
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
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
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
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
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