From 013b675806212b18a428bad860c7d25082d5319d Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Thu, 28 Sep 2023 07:09:26 -0300 Subject: [PATCH 1/3] init --- .../setupWizard/steps/RegisterServerStep.tsx | 43 ++++++------------- .../rocketchat-i18n/i18n/en.i18n.json | 10 ++--- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx b/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx index 6bc2e25259b6..a5596380212d 100644 --- a/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx +++ b/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx @@ -1,5 +1,4 @@ -import { RegisterServerPage, StandaloneServerPage } from '@rocket.chat/onboarding-ui'; -import { useRoute } from '@rocket.chat/ui-contexts'; +import { RegisterServerPage, RegisterOfflinePage } from '@rocket.chat/onboarding-ui'; import type { ReactElement, ComponentProps } from 'react'; import React, { useState } from 'react'; @@ -7,51 +6,37 @@ 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 { goToPreviousStep, currentStep, goToNextStep, goToStep, setSetupWizardData, registerServer, maxSteps, offline } = useSetupWizardContext(); const [serverOption, setServerOption] = useState(SERVER_OPTIONS.REGISTERED); - const router = useRoute('cloud'); - - const handleRegisterOffline: ComponentProps['onSubmit'] = async () => { - await completeSetupWizard(); - router.push({}, { register: 'true' }); - }; - - const handleRegister: ComponentProps['onSubmit'] = async (data) => { - if (data.registerType !== 'standalone') { - setSetupWizardData((prevState) => ({ ...prevState, serverData: data })); - await registerServer(data); - } + const handleRegister: ComponentProps['onSubmit'] = async (data: { email: string; resend?: boolean }) => { + goToNextStep(); + setSetupWizardData((prevState) => ({ ...prevState, serverData: data })); + await registerServer(data); }; - const handleConfirmStandalone: ComponentProps['onSubmit'] = async ({ registerType }) => { - if (registerType !== 'registered') { - return completeSetupWizard(); - } + const handleConfirmOffline: ComponentProps['onSubmit'] = async (/* data: unknown*/) => { + // TODO: CALL REGISTER WITH TOKEN + return goToStep(4); }; - if (serverOption === SERVER_OPTIONS.STANDALONE) { + if (serverOption === SERVER_OPTIONS.OFFLINE) { return ( - setServerOption(SERVER_OPTIONS.REGISTERED)} - onSubmit={handleConfirmStandalone} - stepCount={maxSteps} - /> + setServerOption(SERVER_OPTIONS.REGISTERED)} onSubmit={handleConfirmOffline} /> ); } return ( setServerOption(SERVER_OPTIONS.STANDALONE)} + onClickRegisterOffline={(): void => setServerOption(SERVER_OPTIONS.OFFLINE)} onBackButtonClick={goToPreviousStep} stepCount={maxSteps} - onSubmit={offline ? handleRegisterOffline : handleRegister} + onSubmit={handleRegister} currentStep={currentStep} offline={offline} /> diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 0df90c85bd8e..2fba84161d6b 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -5855,7 +5855,8 @@ "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.termsAndConditions": "I agree with <1>Terms and Conditions and <3>Privacy Policy", "onboarding.component.emailCodeFallback": "Didn’t receive email? <1>Resend or <3>Change email", @@ -5909,6 +5910,9 @@ "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.description": "If for any reason your workspace can’t be connected to the internet, follow these steps:<1>1. Go to: <2>cloud.rocket.chat > Workspaces and click “<3>Register self-managed”<4>2. Copy the token and paste it below", + "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)", @@ -5919,10 +5923,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", From 93864e8950bffc4bc421e4cd14f767a9bbf79398 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Tue, 3 Oct 2023 17:28:59 -0300 Subject: [PATCH 2/3] seems done --- .../setupWizard/steps/RegisterServerStep.tsx | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx b/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx index a5596380212d..f615a8fad0f3 100644 --- a/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx +++ b/apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx @@ -1,7 +1,10 @@ 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 = { @@ -10,7 +13,8 @@ const SERVER_OPTIONS = { }; const RegisterServerStep = (): ReactElement => { - const { goToPreviousStep, currentStep, goToNextStep, goToStep, setSetupWizardData, registerServer, maxSteps, offline } = + const t = useTranslation(); + const { goToPreviousStep, currentStep, goToNextStep, completeSetupWizard, setSetupWizardData, registerServer, maxSteps, offline } = useSetupWizardContext(); const [serverOption, setServerOption] = useState(SERVER_OPTIONS.REGISTERED); @@ -20,14 +24,38 @@ const RegisterServerStep = (): ReactElement => { await registerServer(data); }; - const handleConfirmOffline: ComponentProps['onSubmit'] = async (/* data: unknown*/) => { - // TODO: CALL REGISTER WITH TOKEN - return goToStep(4); + const [clientKey, setClientKey] = useState(''); + + const registerManually = useEndpoint('POST', '/v1/cloud.manualRegister'); + const getWorkspaceRegisterData = useMethod('cloud:getWorkspaceRegisterData'); + + useEffect(() => { + const loadWorkspaceRegisterData = async (): Promise => { + const clientKey = await getWorkspaceRegisterData(); + setClientKey(clientKey); + }; + + loadWorkspaceRegisterData(); + }, [getWorkspaceRegisterData]); + + const handleConfirmOffline: ComponentProps['onSubmit'] = async ({ token }) => { + try { + await registerManually({ cloudBlob: token }); + queryClient.invalidateQueries(['licenses']); + + return completeSetupWizard(); + } catch (error) { + dispatchToastMessage({ type: 'error', message: t('Cloud_register_error') }); + } }; if (serverOption === SERVER_OPTIONS.OFFLINE) { return ( - setServerOption(SERVER_OPTIONS.REGISTERED)} onSubmit={handleConfirmOffline} /> + setServerOption(SERVER_OPTIONS.REGISTERED)} + onSubmit={handleConfirmOffline} + /> ); } From 1f3607253b41e438b33d976da6e238b939738c23 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Tue, 3 Oct 2023 17:34:40 -0300 Subject: [PATCH 3/3] i18n --- apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index bbf48a5dcda8..5694dff8622c 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -5860,6 +5860,8 @@ "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 and <3>Privacy Policy", "onboarding.component.emailCodeFallback": "Didn’t receive email? <1>Resend or <3>Change email", "onboarding.page.form.title": "Let's launch your workspace", @@ -5913,7 +5915,8 @@ "onboarding.form.organizationInfoForm.fields.country.label": "Country", "onboarding.form.organizationInfoForm.fields.country.placeholder": "Select", "onboarding.form.registerOfflineForm.title": "Register Offline", - "onboarding.form.registerOfflineForm.description": "If for any reason your workspace can’t be connected to the internet, follow these steps:<1>1. Go to: <2>cloud.rocket.chat > Workspaces and click “<3>Register self-managed”<4>2. Copy the token and paste it below", + "onboarding.form.registerOfflineForm.copyStep.description": "If for any reason your workspace can’t be connected to the internet, follow these steps:<1>1. Go to: <2>cloud.rocket.chat > Workspaces and click “<3>Register self-managed”<4>2. Click “<5>Continue offline”<6>3. In the <7>Register offline workspace dialog in cloud.rocket.chat, paste the token in the box below", + "onboarding.form.registerOfflineForm.pasteStep.description": "1. In <1>cloud.rocket.chat 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",