snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
||||
import { act, renderHook, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import { useCancelSubscriptionModal } from './useCancelSubscriptionModal';
|
||||
import createDeferredMockFn from '../../../../../tests/mocks/utils/createDeferredMockFn';
|
||||
|
||||
jest.mock('@rocket.chat/ui-client', () => ({
|
||||
...jest.requireActual('@rocket.chat/ui-client'),
|
||||
useLicenseName: () => ({ data: 'Starter' }),
|
||||
}));
|
||||
|
||||
it('should open modal when open method is called', () => {
|
||||
const { result } = renderHook(() => useCancelSubscriptionModal(), {
|
||||
wrapper: mockAppRoot()
|
||||
.withTranslations('en', 'core', {
|
||||
Cancel__planName__subscription: 'Cancel {{planName}} subscription',
|
||||
})
|
||||
.build(),
|
||||
});
|
||||
|
||||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument();
|
||||
|
||||
act(() => result.current.open());
|
||||
|
||||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should close modal cancel is clicked', async () => {
|
||||
const { result } = renderHook(() => useCancelSubscriptionModal(), {
|
||||
wrapper: mockAppRoot()
|
||||
.withTranslations('en', 'core', {
|
||||
Cancel__planName__subscription: 'Cancel {{planName}} subscription',
|
||||
})
|
||||
.build(),
|
||||
});
|
||||
|
||||
act(() => result.current.open());
|
||||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Dont_cancel' }));
|
||||
|
||||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should call remove license endpoint when confirm is clicked', async () => {
|
||||
const { fn: removeLicenseEndpoint, resolve } = createDeferredMockFn<{ success: boolean }>();
|
||||
|
||||
const { result } = renderHook(() => useCancelSubscriptionModal(), {
|
||||
wrapper: mockAppRoot()
|
||||
.withEndpoint('POST', '/v1/cloud.removeLicense', removeLicenseEndpoint)
|
||||
.withTranslations('en', 'core', {
|
||||
Cancel__planName__subscription: 'Cancel {{planName}} subscription',
|
||||
})
|
||||
.build(),
|
||||
});
|
||||
|
||||
act(() => result.current.open());
|
||||
expect(result.current.isLoading).toBeFalsy();
|
||||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Cancel_subscription' }));
|
||||
expect(result.current.isLoading).toBeTruthy();
|
||||
act(() => resolve({ success: true }));
|
||||
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
|
||||
|
||||
expect(removeLicenseEndpoint).toHaveBeenCalled();
|
||||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useLicenseName } from '@rocket.chat/ui-client';
|
||||
import { useSetModal } from '@rocket.chat/ui-contexts';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { useRemoveLicense } from './useRemoveLicense';
|
||||
import { CancelSubscriptionModal } from '../components/CancelSubscriptionModal';
|
||||
|
||||
export const useCancelSubscriptionModal = () => {
|
||||
const { data: planName = '' } = useLicenseName();
|
||||
const removeLicense = useRemoveLicense();
|
||||
const setModal = useSetModal();
|
||||
|
||||
const open = useCallback(() => {
|
||||
const closeModal = () => setModal(null);
|
||||
|
||||
const handleConfirm = () => {
|
||||
removeLicense.mutateAsync();
|
||||
closeModal();
|
||||
};
|
||||
|
||||
setModal(<CancelSubscriptionModal planName={planName} onConfirm={handleConfirm} onCancel={closeModal} />);
|
||||
}, [removeLicense, planName, setModal]);
|
||||
|
||||
return {
|
||||
open,
|
||||
isLoading: removeLicense.isPending,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useAbsoluteUrl } from '@rocket.chat/ui-contexts';
|
||||
|
||||
export const useCheckoutUrl = () => {
|
||||
const absoluteUrl = useAbsoluteUrl()('/links/manage-subscription');
|
||||
|
||||
return (query?: Record<string, string>) => {
|
||||
const url = new URL(absoluteUrl);
|
||||
if (query) {
|
||||
Object.entries(query).forEach(([key, value]) => {
|
||||
url.searchParams.append(key, value.toString());
|
||||
});
|
||||
}
|
||||
return url.toString();
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useInvalidateLicense } from '@rocket.chat/ui-client';
|
||||
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export const useRemoveLicense = () => {
|
||||
const { t } = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const invalidateLicense = useInvalidateLicense();
|
||||
|
||||
const removeLicense = useEndpoint('POST', '/v1/cloud.removeLicense');
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => removeLicense(),
|
||||
onSuccess: () => {
|
||||
invalidateLicense(100);
|
||||
dispatchToastMessage({
|
||||
type: 'success',
|
||||
message: t('Removed'),
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
dispatchToastMessage({
|
||||
type: 'error',
|
||||
message: error,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { BehaviorWithContext } from '@rocket.chat/core-typings';
|
||||
import { useEndpoint } from '@rocket.chat/ui-contexts';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
// Real licenses are well over this length; shorter input is still being typed.
|
||||
export const MIN_LICENSE_LENGTH = 100;
|
||||
|
||||
export const isPlausibleLicense = (license: string): boolean => license.trim().length >= MIN_LICENSE_LENGTH;
|
||||
|
||||
// RestApiClient unwraps failures into their parsed body, so a rejection is the failure body, not a Response.
|
||||
const isValidationFailure = (error: unknown): error is { reasons: BehaviorWithContext[] } =>
|
||||
typeof error === 'object' && error !== null && Array.isArray((error as { reasons?: unknown }).reasons);
|
||||
|
||||
export const useValidateLicense = (license: string, enabled = true) => {
|
||||
const validateLicense = useEndpoint('POST', '/v1/licenses.validate');
|
||||
const trimmedLicense = license.trim();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['licenses.validate', trimmedLicense] as const,
|
||||
queryFn: async (): Promise<{ valid: boolean; reasons: BehaviorWithContext[] }> => {
|
||||
try {
|
||||
await validateLicense({ license: trimmedLicense });
|
||||
return { valid: true, reasons: [] };
|
||||
} catch (error) {
|
||||
if (isValidationFailure(error)) {
|
||||
return { valid: false, reasons: error.reasons };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
enabled: enabled && isPlausibleLicense(trimmedLicense),
|
||||
staleTime: Infinity,
|
||||
gcTime: Infinity,
|
||||
retry: false,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export const useWorkspaceSync = () => {
|
||||
const { t } = useTranslation();
|
||||
const cloudSync = useEndpoint('POST', '/v1/cloud.syncWorkspace');
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => cloudSync(),
|
||||
onSuccess: () => {
|
||||
dispatchToastMessage({
|
||||
type: 'success',
|
||||
message: t('Sync_success'),
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
dispatchToastMessage({
|
||||
type: 'error',
|
||||
message: error,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user