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

feat: Replace registration as standalone by offline #30516

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
63 changes: 38 additions & 25 deletions apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,70 @@
import { RegisterServerPage, StandaloneServerPage } from '@rocket.chat/onboarding-ui';
import { useRoute } from '@rocket.chat/ui-contexts';
import { RegisterServerPage, RegisterOfflinePage } from '@rocket.chat/onboarding-ui';
import { useEndpoint, useMethod, useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement, ComponentProps } from 'react';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { queryClient } from '../../../lib/queryClient';
import { dispatchToastMessage } from '../../../lib/toast';
import { useSetupWizardContext } from '../contexts/SetupWizardContext';

const SERVER_OPTIONS = {
REGISTERED: 'REGISTERED',
STANDALONE: 'STANDALONE',
OFFLINE: 'OFFLINE',
};

const RegisterServerStep = (): ReactElement => {
const { goToPreviousStep, currentStep, setSetupWizardData, registerServer, maxSteps, offline, completeSetupWizard } =
const t = useTranslation();
const { goToPreviousStep, currentStep, goToNextStep, completeSetupWizard, setSetupWizardData, registerServer, maxSteps, offline } =
useSetupWizardContext();
const [serverOption, setServerOption] = useState(SERVER_OPTIONS.REGISTERED);

const router = useRoute('cloud');

const handleRegisterOffline: ComponentProps<typeof RegisterServerPage>['onSubmit'] = async () => {
await completeSetupWizard();
router.push({}, { register: 'true' });
const handleRegister: ComponentProps<typeof RegisterServerPage>['onSubmit'] = async (data: { email: string; resend?: boolean }) => {
goToNextStep();
setSetupWizardData((prevState) => ({ ...prevState, serverData: data }));
await registerServer(data);
};

const handleRegister: ComponentProps<typeof RegisterServerPage>['onSubmit'] = async (data) => {
if (data.registerType !== 'standalone') {
setSetupWizardData((prevState) => ({ ...prevState, serverData: data }));
await registerServer(data);
}
};
const [clientKey, setClientKey] = useState('');

const registerManually = useEndpoint('POST', '/v1/cloud.manualRegister');
const getWorkspaceRegisterData = useMethod('cloud:getWorkspaceRegisterData');

useEffect(() => {
const loadWorkspaceRegisterData = async (): Promise<void> => {
const clientKey = await getWorkspaceRegisterData();
setClientKey(clientKey);
};

loadWorkspaceRegisterData();
}, [getWorkspaceRegisterData]);

const handleConfirmOffline: ComponentProps<typeof RegisterOfflinePage>['onSubmit'] = async ({ token }) => {
try {
await registerManually({ cloudBlob: token });
queryClient.invalidateQueries(['licenses']);

const handleConfirmStandalone: ComponentProps<typeof StandaloneServerPage>['onSubmit'] = async ({ registerType }) => {
if (registerType !== 'registered') {
return completeSetupWizard();
} catch (error) {
dispatchToastMessage({ type: 'error', message: t('Cloud_register_error') });
}
};

if (serverOption === SERVER_OPTIONS.STANDALONE) {
if (serverOption === SERVER_OPTIONS.OFFLINE) {
return (
<StandaloneServerPage
currentStep={currentStep}
<RegisterOfflinePage
clientKey={clientKey}
onBackButtonClick={(): void => setServerOption(SERVER_OPTIONS.REGISTERED)}
onSubmit={handleConfirmStandalone}
stepCount={maxSteps}
onSubmit={handleConfirmOffline}
/>
);
}

return (
<RegisterServerPage
onClickRegisterLater={(): void => setServerOption(SERVER_OPTIONS.STANDALONE)}
onClickRegisterOffline={(): void => setServerOption(SERVER_OPTIONS.OFFLINE)}
onBackButtonClick={goToPreviousStep}
stepCount={maxSteps}
onSubmit={offline ? handleRegisterOffline : handleRegister}
onSubmit={handleRegister}
currentStep={currentStep}
offline={offline}
/>
Expand Down
13 changes: 8 additions & 5 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5867,8 +5867,11 @@
"onboarding.component.form.action.next": "Next",
"onboarding.component.form.action.skip": "Skip this step",
"onboarding.component.form.action.register": "Register",
"onboarding.component.form.action.registerNow": "Register now",
"onboarding.component.form.action.registerWorkspace": "Register workspace",
"onboarding.component.form.action.registerOffline": "Register offline",
"onboarding.component.form.action.confirm": "Confirm",
"onboarding.component.form.action.pasteHere": "Paste here...",
"onboarding.component.form.action.completeRegistration": "Complete registration",
"onboarding.component.form.termsAndConditions": "I agree with <1>Terms and Conditions</1> and <3>Privacy Policy</3>",
"onboarding.component.emailCodeFallback": "Didn’t receive email? <1>Resend</1> or <3>Change email</3>",
"onboarding.page.form.title": "Let's launch your workspace",
Expand Down Expand Up @@ -5921,6 +5924,10 @@
"onboarding.form.organizationInfoForm.fields.organizationSize.placeholder": "Select",
"onboarding.form.organizationInfoForm.fields.country.label": "Country",
"onboarding.form.organizationInfoForm.fields.country.placeholder": "Select",
"onboarding.form.registerOfflineForm.title": "Register Offline",
"onboarding.form.registerOfflineForm.copyStep.description": "If for any reason your workspace can’t be connected to the internet, follow these steps:<1></1>1. Go to: <2>cloud.rocket.chat > Workspaces</2> and click “<3>Register self-managed</3>”<4></4>2. Click “<5>Continue offline</5>”<6></6>3. In the <7>Register offline workspace</7> dialog in cloud.rocket.chat, paste the token in the box below",
"onboarding.form.registerOfflineForm.pasteStep.description": "1. In <1>cloud.rocket.chat</1> get the generated text and paste below to complete your registration process",
"onboarding.form.registerOfflineForm.fields.registrationToken.inputLabel": "Registration token",
"onboarding.form.registeredServerForm.title": "Register your workspace",
"onboarding.form.registeredServerForm.included.push": "Mobile push notifications",
"onboarding.form.registeredServerForm.included.externalProviders": "Integration with external providers (WhatsApp, Facebook, Telegram, Twitter)",
Expand All @@ -5931,10 +5938,6 @@
"onboarding.form.registeredServerForm.registerLater": "Register later",
"onboarding.form.registeredServerForm.notConnectedToInternet": "The server is not connected to the internet, so you’ll have to do an offline registration for this workspace.",
"onboarding.form.registeredServerForm.registrationEngagement": "Registration allows automatic license updates, notifications of critical vulnerabilities and access to Rocket.Chat Cloud services. No sensitive workspace data is shared; statistics sent to Rocket.Chat is made visible to you within the administration area.",
"onboarding.form.standaloneServerForm.title": "Standalone Server Confirmation",
"onboarding.form.standaloneServerForm.servicesUnavailable": "Some of the services will be unavailable or will require manual setup",
"onboarding.form.standaloneServerForm.publishOwnApp": "In order to send push notitications you need to compile and publish your own app to Google Play and App Store",
"onboarding.form.standaloneServerForm.manuallyIntegrate": "Need to manually integrate with external services",
"Something_Went_Wrong": "Something went wrong",
"Toolbox_room_actions": "Primary Room actions",
"Theme_light": "Light",
Expand Down