The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/views/admin/settings/inputs/ActionSettingInput.js

34 lines
1.1 KiB

import { Button, Field } from '@rocket.chat/fuselage';
import React from 'react';
import { useMethod } from '../../../../contexts/ServerContext';
import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesContext';
import { useTranslation } from '../../../../contexts/TranslationContext';
function ActionSettingInput({ _id, actionText, value, disabled, sectionChanged }) {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const actionMethod = useMethod(value);
const handleClick = async () => {
try {
const data = await actionMethod();
const args = [data.message].concat(data.params);
dispatchToastMessage({ type: 'success', message: t(...args) });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
};
return (
<>
<Field.Row>
<Button data-qa-setting-id={_id} children={t(actionText)} disabled={disabled || sectionChanged} primary onClick={handleClick} />
</Field.Row>
{sectionChanged && <Field.Hint>{t('Save_to_enable_this_action')}</Field.Hint>}
</>
);
}
export default ActionSettingInput;