Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export type SettingsSectionProps = {
groupId: string;
hasReset?: boolean;
sectionName: string;
sectionTitle?: string;
currentTab?: string;
solo: boolean;
help?: ReactNode;
children?: ReactNode;
};

function SettingsSection({ groupId, hasReset = true, sectionName, currentTab, solo, help, children }: SettingsSectionProps) {
function SettingsSection({ groupId, hasReset = true, sectionTitle, sectionName, currentTab, solo, help, children }: SettingsSectionProps) {
const { t } = useTranslation();

const editableSettings = useEditableSettings(
Expand Down Expand Up @@ -74,7 +75,7 @@ function SettingsSection({ groupId, hasReset = true, sectionName, currentTab, so
<AccordionItem
data-qa-section={sectionName}
noncollapsible={solo || !sectionName}
title={sectionName && t(sectionName as TranslationKey)}
title={sectionTitle || (sectionName && t(sectionName as TranslationKey))}
>
{help && (
<Box is='p' color='hint' fontScale='p2'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Box } from '@rocket.chat/fuselage';
import { Accordion, Box } from '@rocket.chat/fuselage';
import { PageScrollableContentWithShadow } from '@rocket.chat/ui-client';
import { useRouter } from '@rocket.chat/ui-contexts';
import { useCallback } from 'react';
import type { MouseEvent } from 'react';
import { Trans } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';

import { useEditableSettingsGroupSections } from '../../EditableSettingsContext';
import SettingsGroupPage from '../SettingsGroupPage';
import Section from '../SettingsSection';

type EnterpriseGroupPageProps = {
_id: string;
Expand All @@ -27,9 +29,11 @@ const useRedirectToRouteLink = (onClick: (event: MouseEvent<HTMLAnchorElement>)
return { href: '#', onClick: handleClick };
};

const EnterpriseGroupPage = ({ _id, i18nLabel, onClickBack, ...props }: EnterpriseGroupPageProps) => {
const EnterpriseGroupPage = ({ _id, i18nLabel, hasReset, currentTab, onClickBack, ...props }: EnterpriseGroupPageProps) => {
const { t } = useTranslation();
const { navigate } = useRouter();
const redirectProps = useRedirectToRouteLink(() => navigate('/admin/subscription'));
const sections = useEditableSettingsGroupSections(_id);

return (
<SettingsGroupPage isCustom _id={_id} i18nLabel={i18nLabel} onClickBack={onClickBack} {...props}>
Expand All @@ -39,6 +43,19 @@ const EnterpriseGroupPage = ({ _id, i18nLabel, onClickBack, ...props }: Enterpri
i18nKey='Workspace_license_is_now_managed_from_the_subscription_page'
components={{ a: <Box is='a' fontScale='p2' color='info' {...redirectProps} /> }}
/>
<Accordion>
{sections.map((sectionName) => (
<Section
Comment thread
dougfabris marked this conversation as resolved.
Resolved
key={sectionName || ''}
Comment thread
dougfabris marked this conversation as resolved.
Resolved
hasReset={hasReset}
groupId={_id}
sectionName={sectionName}
sectionTitle={t('Manual_license_management_deprecated')}
currentTab={currentTab}
solo={false}
/>
))}
</Accordion>
</Box>
</PageScrollableContentWithShadow>
</SettingsGroupPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ it('should apply a valid license and close the modal', async () => {
await waitFor(() => expect(onCancel).toHaveBeenCalled());
});

it('should keep the apply button disabled after erasing a valid license', async () => {
render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(),
});

expect(await screen.findByText('Valid_license')).toBeInTheDocument();

const applyButton = screen.getByRole('button', { name: 'Apply_license' });

await userEvent.clear(screen.getByRole('textbox'));

expect(applyButton).toBeDisabled();
await waitFor(() => expect(applyButton).toBeDisabled());
});

it('should ask for confirmation before removing the current license', async () => {
render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ManageLicenseModal = ({ enterpriseLicense, onCancel }: ManageLicenseModalP

const isCurrentLicense = !isEmpty && trimmedLicense === enterpriseLicense.trim();

const isLicenseValid = !fileError && !isError && validation?.valid === true;
const isLicenseValid = isPlausible && !fileError && !isError && validation?.valid === true;

const invalidMessage = (() => {
if (fileError) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import { IconButton, Divider, Box } from '@rocket.chat/fuselage';
import { useClipboard } from '@rocket.chat/fuselage-hooks';
import { ActionLink } from '@rocket.chat/layout';
import { useSetModal, useSetting } from '@rocket.chat/ui-contexts';
import { usePermission, useSetModal, useSetting } from '@rocket.chat/ui-contexts';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import ManageLicenseModal from './ManageLicenseModal';
import useClipboardWithToast from '../../../../../../hooks/useClipboardWithToast';
import { useServerInfo } from '../../../../../../hooks/useWorkspaceInfo';

const PlanCardLicenseDetails = () => {
const { t } = useTranslation();
const setModal = useSetModal();
const hasPermission = usePermission('edit-privileged-setting');
const siteURL = useSetting('Site_Url', '');
const enterpriseLicense = useSetting('Enterprise_License', '');
const { data: serverInfo } = useServerInfo();

const hashedSiteURL = serverInfo?.hashedWorkspaceUrl ?? '';
const { copy: copySiteURL, hasCopied: hasCopiedSiteURL } = useClipboard(siteURL);
const { copy: copyHashed, hasCopied: hasCopiedHashed } = useClipboard(hashedSiteURL);
const { copy: copySiteURL, hasCopied: hasCopiedSiteURL } = useClipboardWithToast(siteURL);
const { copy: copyHashed, hasCopied: hasCopiedHashed } = useClipboardWithToast(hashedSiteURL);

const handleOpenModal = useCallback(
() => setModal(<ManageLicenseModal enterpriseLicense={enterpriseLicense} onCancel={() => setModal(null)} />),
[enterpriseLicense, setModal],
);

if (!hasPermission) {
return null;
}

return (
<>
<Divider />
Expand All @@ -32,7 +38,7 @@ const PlanCardLicenseDetails = () => {
{hasCopiedSiteURL ? (
<IconButton success icon='check' mini />
) : (
<IconButton title={t('Copy')} icon='clipboard' mini onClick={() => copySiteURL()} />
<IconButton title={t('Copy')} icon='clipboard' mini onClick={() => !hasCopiedSiteURL && copySiteURL()} />
)}
</Box>
<Box withTruncatedText fontScale='p2'>
Expand All @@ -45,26 +51,14 @@ const PlanCardLicenseDetails = () => {
{hasCopiedHashed ? (
<IconButton success icon='check' mini />
) : (
<IconButton title={t('Copy')} icon='clipboard' mini onClick={() => copyHashed()} />
<IconButton title={t('Copy')} icon='clipboard' mini onClick={() => !hasCopiedHashed && copyHashed()} />
)}
</Box>
<Box withTruncatedText fontScale='p2'>
{hashedSiteURL}
</Box>
</Box>
<Box>
<Box display='flex'>
<Box mie={4}>{t('License_key')}</Box>
{enterpriseLicense && <IconButton title={t('Manage_license')} icon='cog' mini onClick={handleOpenModal} />}
</Box>
{enterpriseLicense ? (
<Box withTruncatedText fontScale='p2'>
{enterpriseLicense}
</Box>
) : (
<ActionLink onClick={handleOpenModal}>{t('Add_license')}</ActionLink>
)}
</Box>
<ActionLink onClick={handleOpenModal}>{t('Manage_license')}</ActionLink>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@
"Add_email": "Add email",
"Add_emoji": "Add emoji",
"Add_files_from": "Add files from",
"Add_license": "Add license",
"Add_link": "Add link",
"Add_manager": "Add manager",
"Add_members": "Add Members",
Expand Down Expand Up @@ -3416,6 +3415,7 @@
"Managers": "Managers",
"Managing_assets": "Managing assets",
"Managing_integrations": "Managing integrations",
"Manual_license_management_deprecated": "Manual license management (deprecated)",
"Manual_Selection": "Manual Selection",
"Manually_created_users_briefing": "Manually created users will initially be shown as pending. Once they log in for the first time, they will be shown as active.",
"Manufacturing": "Manufacturing",
Expand Down
Loading