snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
128
apps/meteor/client/views/admin/customEmoji/AddCustomEmoji.tsx
Normal file
128
apps/meteor/client/views/admin/customEmoji/AddCustomEmoji.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
import { Box, Button, ButtonGroup, Margins, TextInput, Field, FieldLabel, FieldRow, FieldError, IconButton } from '@rocket.chat/fuselage';
|
||||
import { ContextualbarScrollableContent, ContextualbarFooter } from '@rocket.chat/ui-client';
|
||||
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import type { ChangeEvent } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useEndpointUploadMutation } from '../../../hooks/useEndpointUploadMutation';
|
||||
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';
|
||||
|
||||
export type AddCustomEmojiProps = {
|
||||
close: () => void;
|
||||
onChange: () => void;
|
||||
};
|
||||
|
||||
const AddCustomEmoji = ({ close, onChange, ...props }: AddCustomEmojiProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = useState('');
|
||||
const [aliases, setAliases] = useState('');
|
||||
const [emojiFile, setEmojiFile] = useState<Blob>();
|
||||
const [newEmojiPreview, setNewEmojiPreview] = useState('');
|
||||
const [errors, setErrors] = useState({ name: false, emoji: false, aliases: false });
|
||||
|
||||
const setEmojiPreview = useCallback(
|
||||
async (file: Blob) => {
|
||||
setEmojiFile(file);
|
||||
setNewEmojiPreview(URL.createObjectURL(file));
|
||||
setErrors((prevState) => ({ ...prevState, emoji: false }));
|
||||
},
|
||||
[setEmojiFile],
|
||||
);
|
||||
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { mutateAsync: saveAction } = useEndpointUploadMutation('/v1/emoji-custom.create', {
|
||||
onSuccess: () => {
|
||||
dispatchToastMessage({ type: 'success', message: t('Custom_Emoji_Added_Successfully') });
|
||||
queryClient.invalidateQueries({ queryKey: ['emoji-custom.list'] });
|
||||
onChange();
|
||||
close();
|
||||
},
|
||||
});
|
||||
|
||||
const handleSave = useCallback(async () => {
|
||||
if (!name) {
|
||||
return setErrors((prevState) => ({ ...prevState, name: true }));
|
||||
}
|
||||
|
||||
if (name === aliases) {
|
||||
return setErrors((prevState) => ({ ...prevState, aliases: true }));
|
||||
}
|
||||
|
||||
if (!emojiFile) {
|
||||
return setErrors((prevState) => ({ ...prevState, emoji: true }));
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('emoji', emojiFile);
|
||||
formData.append('name', name);
|
||||
formData.append('aliases', aliases);
|
||||
await saveAction(formData);
|
||||
}, [emojiFile, name, aliases, saveAction]);
|
||||
|
||||
const [clickUpload] = useSingleFileInput(setEmojiPreview, 'emoji');
|
||||
|
||||
const handleChangeName = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
if (e.currentTarget.value !== '') {
|
||||
setErrors((prevState) => ({ ...prevState, name: false }));
|
||||
}
|
||||
|
||||
return setName(e.currentTarget.value);
|
||||
};
|
||||
|
||||
const handleChangeAliases = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
if (e.currentTarget.value !== name) {
|
||||
setErrors((prevState) => ({ ...prevState, aliases: false }));
|
||||
}
|
||||
|
||||
return setAliases(e.currentTarget.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContextualbarScrollableContent {...props}>
|
||||
<Field>
|
||||
<FieldLabel>{t('Name')}</FieldLabel>
|
||||
<FieldRow>
|
||||
<TextInput value={name} onChange={handleChangeName} placeholder={t('Name')} />
|
||||
</FieldRow>
|
||||
{errors.name && <FieldError>{t('Required_field', { field: t('Name') })}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>{t('Aliases')}</FieldLabel>
|
||||
<FieldRow>
|
||||
<TextInput value={aliases} onChange={handleChangeAliases} placeholder={t('Aliases')} />
|
||||
</FieldRow>
|
||||
{errors.aliases && <FieldError>{t('Custom_Emoji_Error_Same_Name_And_Alias')}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel alignSelf='stretch' display='flex' justifyContent='space-between' alignItems='center'>
|
||||
{t('Custom_Emoji')}
|
||||
<IconButton secondary small icon='upload' onClick={clickUpload} />
|
||||
</FieldLabel>
|
||||
{errors.emoji && <FieldError>{t('Required_field', { field: t('Custom_Emoji') })}</FieldError>}
|
||||
{newEmojiPreview && (
|
||||
<Box display='flex' flexDirection='row' marginInline='neg-x4' justifyContent='center'>
|
||||
<Margins inline={4}>
|
||||
<Box is='img' objectFit='contain' width='x120' height='x120' src={newEmojiPreview} />
|
||||
</Margins>
|
||||
</Box>
|
||||
)}
|
||||
</Field>
|
||||
</ContextualbarScrollableContent>
|
||||
<ContextualbarFooter>
|
||||
<ButtonGroup stretch>
|
||||
<Button onClick={close}>{t('Cancel')}</Button>
|
||||
<Button primary onClick={handleSave}>
|
||||
{t('Save')}
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</ContextualbarFooter>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddCustomEmoji;
|
||||
Reference in New Issue
Block a user