Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into monorepo-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 11, 2022
2 parents 11f5aca + 3d86825 commit fbccf8e
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 330 deletions.
31 changes: 0 additions & 31 deletions apps/meteor/app/livechat/imports/server/rest/messages.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../imports/server/rest/rooms.js';
import '../imports/server/rest/appearance.js';
import '../imports/server/rest/triggers.js';
import '../imports/server/rest/integrations.js';
import '../imports/server/rest/messages.js';
import '../imports/server/rest/visitors.js';
import '../imports/server/rest/visitors.ts';
import '../imports/server/rest/dashboards.js';
Expand Down
20 changes: 0 additions & 20 deletions apps/meteor/app/livechat/server/api/lib/messages.js

This file was deleted.

2 changes: 0 additions & 2 deletions apps/meteor/app/models/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import LivechatDepartmentAgents from './models/LivechatDepartmentAgents';
import LivechatRooms from './models/LivechatRooms';
import LivechatVisitors from './models/LivechatVisitors';
import LivechatInquiry from './models/LivechatInquiry';
import LivechatExternalMessage from './models/LivechatExternalMessages';
import OmnichannelQueue from './models/OmnichannelQueue';
import ImportData from './models/ImportData';

Expand All @@ -35,7 +34,6 @@ export {
LivechatDepartmentAgents,
LivechatRooms,
LivechatVisitors,
LivechatExternalMessage,
LivechatInquiry,
OmnichannelQueue,
ImportData,
Expand Down
18 changes: 0 additions & 18 deletions apps/meteor/app/models/server/models/LivechatExternalMessages.js

This file was deleted.

9 changes: 0 additions & 9 deletions apps/meteor/app/models/server/raw/LivechatExternalMessages.js

This file was deleted.

3 changes: 0 additions & 3 deletions apps/meteor/app/models/server/raw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { LivechatBusinessHoursRaw } from './LivechatBusinessHours';
import { LivechatCustomFieldRaw } from './LivechatCustomField';
import { LivechatDepartmentAgentsRaw } from './LivechatDepartmentAgents';
import { LivechatDepartmentRaw } from './LivechatDepartment';
import { LivechatExternalMessageRaw } from './LivechatExternalMessages';
import { LivechatInquiryRaw } from './LivechatInquiry';
import { LivechatRoomsRaw } from './LivechatRooms';
import { LivechatTriggerRaw } from './LivechatTrigger';
Expand Down Expand Up @@ -58,7 +57,6 @@ import LivechatBusinessHoursModel from '../models/LivechatBusinessHours';
import LivechatCustomFieldModel from '../models/LivechatCustomField';
import LivechatDepartmentAgentsModel from '../models/LivechatDepartmentAgents';
import LivechatDepartmentModel from '../models/LivechatDepartment';
import LivechatExternalMessagesModel from '../models/LivechatExternalMessages';
import LivechatInquiryModel from '../models/LivechatInquiry';
import LivechatRoomsModel from '../models/LivechatRooms';
import LivechatVisitorsModel from '../models/LivechatVisitors';
Expand All @@ -85,7 +83,6 @@ export const LivechatDepartmentAgents = new LivechatDepartmentAgentsRaw(
);
export const LivechatRooms = new LivechatRoomsRaw(LivechatRoomsModel.model.rawCollection(), trashCollection);
export const Messages = new MessagesRaw(MessagesModel.model.rawCollection(), trashCollection);
export const LivechatExternalMessage = new LivechatExternalMessageRaw(LivechatExternalMessagesModel.model.rawCollection(), trashCollection);
export const LivechatVisitors = new LivechatVisitorsRaw(LivechatVisitorsModel.model.rawCollection(), trashCollection);
export const LivechatInquiry = new LivechatInquiryRaw(LivechatInquiryModel.model.rawCollection(), trashCollection);
export const LivechatBusinessHours = new LivechatBusinessHoursRaw(LivechatBusinessHoursModel.model.rawCollection(), trashCollection);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/contexts/ServerContext/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type ServerMethods = {
'getUsersOfRoom': (...args: any[]) => any;
'hideRoom': (...args: any[]) => any;
'ignoreUser': (...args: any[]) => any;
'insertOrUpdateSound': (...args: any[]) => any;
'insertOrUpdateSound': (args: { previousName?: string; name?: string; _id?: string; extension: string }) => string;
'insertOrUpdateUserStatus': (...args: any[]) => any;
'instances/get': (...args: any[]) => any;
'jitsi:generateAccessToken': (...args: any[]) => any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, TextInput, Box, Icon, Margins, Button, ButtonGroup } from '@rocket.chat/fuselage';
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, ReactElement, FormEvent } from 'react';

import VerticalBar from '../../../components/VerticalBar';
import { useMethod } from '../../../contexts/ServerContext';
Expand All @@ -8,12 +8,18 @@ import { useTranslation } from '../../../contexts/TranslationContext';
import { useFileInput } from '../../../hooks/useFileInput';
import { validate, createSoundData } from './lib';

function AddCustomSound({ goToNew, close, onChange, ...props }) {
type AddCustomSoundProps = {
goToNew: (where: string) => () => void;
close: () => void;
onChange: () => void;
};

const AddCustomSound = function AddCustomSound({ goToNew, close, onChange, ...props }: AddCustomSoundProps): ReactElement {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

const [name, setName] = useState('');
const [sound, setSound] = useState();
const [sound, setSound] = useState<{ name: string }>();

const uploadCustomSound = useMethod('uploadCustomSound');

Expand All @@ -26,54 +32,56 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
const [clickUpload] = useFileInput(handleChangeFile, 'audio/mp3');

const saveAction = useCallback(
async (name, soundFile) => {
const soundData = createSoundData(soundFile, name);
const validation = validate(soundData, soundFile);
if (validation.length === 0) {
let soundId;
try {
soundId = await insertOrUpdateSound(soundData);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
async (name, soundFile): Promise<string | undefined> => {
const soundData = createSoundData(soundFile, name) as { extension: string; _id?: string; name: string; newFile?: true };
const validation = validate(soundData, soundFile) as Array<Parameters<typeof t>[0]>;

validation.forEach((error) => {
throw new Error(t('error-the-field-is-required', { field: t(error) }));
});

try {
const soundId = await insertOrUpdateSound(soundData);

soundData._id = soundId;
soundData.random = Math.round(Math.random() * 1000);

if (soundId) {
dispatchToastMessage({ type: 'success', message: t('Uploading_file') });

const reader = new FileReader();
reader.readAsBinaryString(soundFile);
reader.onloadend = () => {
try {
uploadCustomSound(reader.result, soundFile.type, soundData);
dispatchToastMessage({ type: 'success', message: t('File_uploaded') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
};
if (!soundId) {
return undefined;
}

dispatchToastMessage({ type: 'success', message: t('Uploading_file') });

const reader = new FileReader();
reader.readAsBinaryString(soundFile);
reader.onloadend = (): void => {
try {
uploadCustomSound(reader.result, soundFile.type, {
...soundData,
_id: soundId,
random: Math.round(Math.random() * 1000),
});
dispatchToastMessage({ type: 'success', message: t('File_uploaded') });
} catch (error) {
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
};
return soundId;
} catch (error) {
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
validation.forEach((error) => {
throw new Error({
type: 'error',
message: t('error-the-field-is-required', { field: t(error) }),
});
});
},
[dispatchToastMessage, insertOrUpdateSound, t, uploadCustomSound],
);

const handleSave = useCallback(async () => {
try {
const result = await saveAction(name, sound);
if (!result) {
throw new Error('error-something-went-wrong');
}
goToNew(result);
dispatchToastMessage({ type: 'success', message: t('Custom_Sound_Saved_Successfully') });
goToNew(result)();
onChange();
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
}, [dispatchToastMessage, goToNew, name, onChange, saveAction, sound, t]);

Expand All @@ -82,7 +90,11 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
<Field>
<Field.Label>{t('Name')}</Field.Label>
<Field.Row>
<TextInput value={name} onChange={(e) => setName(e.currentTarget.value)} placeholder={t('Name')} />
<TextInput
value={name}
onChange={(e: FormEvent<HTMLInputElement>): void => setName(e.currentTarget.value)}
placeholder={t('Name')}
/>
</Field.Row>
</Field>
<Field>
Expand All @@ -92,7 +104,7 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
<Button square onClick={clickUpload}>
<Icon name='upload' size='x20' />
</Button>
{(sound && sound.name) || 'none'}
{sound?.name || t('None')}
</Margins>
</Box>
</Field>
Expand All @@ -110,6 +122,6 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
</Field>
</VerticalBar.ScrollableContent>
);
}
};

export default AddCustomSound;
61 changes: 0 additions & 61 deletions apps/meteor/client/views/admin/customSounds/AdminSounds.js

This file was deleted.

Loading

0 comments on commit fbccf8e

Please sign in to comment.