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/apps/meteor/client/views/admin/cloud/PasteStep.tsx

83 lines
2.4 KiB

import { Box, Button, Scrollable, Throbber, Modal } from '@rocket.chat/fuselage';
import { useToastMessageDispatch, useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import type { ChangeEvent, FC } from 'react';
import React, { useState } from 'react';
import { queryClient } from '../../../lib/queryClient';
type PasteStepProps = {
onBackButtonClick: () => void;
onFinish: () => void;
};
const PasteStep: FC<PasteStepProps> = ({ onBackButtonClick, onFinish }) => {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const [isLoading, setLoading] = useState(false);
const [cloudKey, setCloudKey] = useState('');
const handleCloudKeyChange = (e: ChangeEvent<HTMLInputElement>): void => {
setCloudKey(e.currentTarget.value);
};
Chore: RestApiClient as Package (#25469) <!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. --> <!-- Your Pull Request name should start with one of the following tags [NEW] For new features [IMPROVE] For an improvement (performance or little improvements) in existing features [FIX] For bug fixes that affect the end-user [BREAK] For pull requests including breaking changes Chore: For small tasks Doc: For documentation --> <!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat - Lint and unit tests pass locally with my changes - I have added tests that prove my fix is effective or that my feature works (if applicable) - I have added necessary documentation (if applicable) - Any dependent changes have been merged and published in downstream modules --> ## Proposed changes (including videos or screenshots) <!-- CHANGELOG --> <!-- Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue below. This description will appear in the release notes if we accept the contribution. --> <!-- END CHANGELOG --> ## Issue(s) <!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 --> ## Steps to test or reproduce <!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable --> ## Further comments <!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... --> Co-authored-by: Tasso Evangelista <2263066+tassoevan@users.noreply.github.com>
4 years ago
const registerManually = useEndpoint('POST', '/v1/cloud.manualRegister');
const handleFinishButtonClick = async (): Promise<void> => {
setLoading(true);
try {
await registerManually({ cloudBlob: cloudKey });
queryClient.invalidateQueries(['licenses']);
dispatchToastMessage({ type: 'success', message: t('Cloud_register_success') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: t('Cloud_register_error') });
} finally {
setLoading(false);
onFinish?.();
}
};
return (
<>
<Modal.Content>
<Box withRichContent>
<p>{t('Cloud_register_offline_finish_helper')}</p>
</Box>
<Box display='flex' flexDirection='column' alignItems='stretch' padding='x16' flexGrow={1} backgroundColor='dark'>
<Scrollable vertical>
<Box
is='textarea'
height='x108'
fontFamily='mono'
fontScale='p2'
color='white'
style={{ wordBreak: 'break-all', resize: 'none' }}
placeholder={t('Paste_here')}
disabled={isLoading}
value={cloudKey}
autoComplete='off'
autoCorrect='off'
autoCapitalize='off'
spellCheck='false'
onChange={handleCloudKeyChange}
/>
</Scrollable>
</Box>
</Modal.Content>
<Modal.Footer>
<Modal.FooterControllers>
<Button disabled={isLoading} onClick={onBackButtonClick}>
{t('Back')}
</Button>
<Button primary disabled={isLoading || !cloudKey.trim()} marginInlineStart='auto' onClick={handleFinishButtonClick}>
{isLoading ? <Throbber inheritColor /> : t('Finish_Registration')}
</Button>
</Modal.FooterControllers>
</Modal.Footer>
</>
);
};
export default PasteStep;