Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add Offline License Endpoint #26282

Merged
merged 14 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/info/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const LicenseCard = (): ReactElement => {
const t = useTranslation();
const setModal = useSetModal();

const currentLicense = useSetting('Enterprise_License');
const licenseStatus = useSetting('Enterprise_License_Status');
const currentLicense = useSetting('Enterprise_License') as string;
const licenseStatus = useSetting('Enterprise_License_Status') as string;

const isAirGapped = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Modal, Box, ButtonGroup, Button, Scrollable, Callout, Margins, Icon } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React, { useState } from 'react';
import { useEndpoint, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ComponentProps, FormEvent, ReactElement, useState } from 'react';

import { useEndpointActionExperimental } from '../../../hooks/useEndpointActionExperimental';
type OfflineLicenseModalProps = {
onClose: () => void;
license: string;
licenseStatus: string;
} & ComponentProps<typeof Modal>;

const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }: OfflineLicenseModalProps): ReactElement => {
const t = useTranslation();

const dispatchToastMessage = useToastMessageDispatch();
Expand All @@ -15,14 +19,12 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
const [status, setStatus] = useState(licenseStatus);
const [lastSetLicense, setLastSetLicense] = useState(license);

const handleNewLicense = (e) => {
const handleNewLicense = (e: FormEvent<HTMLInputElement>): void => {
setNewLicense(e.currentTarget.value);
};

const hasChanges = lastSetLicense !== newLicense;

const addLicense = useEndpointActionExperimental('POST', '/v1/licenses.add', t('Cloud_License_applied_successfully'));

const handlePaste = useMutableCallback(async () => {
try {
const text = await navigator.clipboard.readText();
Expand All @@ -32,16 +34,21 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
}
});

const addLicense = useEndpoint('POST', '/v1/licenses.add');

const handleApplyLicense = useMutableCallback(async () => {
setIsUpdating(true);
setLastSetLicense(newLicense);
const data = await addLicense({ license: newLicense });
if (data.success) {

try {
setIsUpdating(true);
await addLicense({ license: newLicense });
dispatchToastMessage({ type: 'success', message: t('Cloud_License_applied_successfully') });
onClose();
return;
} catch (error) {
dispatchToastMessage({ type: 'error', message: error instanceof Error ? error : String(error) });
setIsUpdating(false);
setStatus('invalid');
}
setIsUpdating(false);
setStatus('invalid');
});

return (
Expand All @@ -62,7 +69,7 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
pb='x8'
flexGrow={1}
backgroundColor='neutral-800'
mb={status === 'invalid' && 'x8'}
mb={status === 'invalid' ? 'x8' : undefined}
>
<Margins block='x8'>
<Scrollable vertical>
Expand Down