Skip to content

Commit

Permalink
new design changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoevanp committed Oct 3, 2023
1 parent ea788da commit 88d9050
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 104 deletions.
11 changes: 9 additions & 2 deletions packages/onboarding-ui/.i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"registerWorkspace": "Register workspace",
"register": "Register",
"registerOffline": "Register offline",
"confirm": "Confirm"
"confirm": "Confirm",
"pasteHere": "Paste here...",
"completeRegistration": "Complete registration"
},
"termsAndConditions": "I agree with <1>Terms and Conditions</1> and <3>Privacy Policy</3>"
},
Expand Down Expand Up @@ -213,7 +215,12 @@
},
"registerOfflineForm": {
"title": "Register Offline",
"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. Copy the token and paste it below",
"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"
},
"pasteStep": {
"description": "1. In <1>cloud.rocket.chat</1> get the generated text and paste below to complete your registration process"
},
"fields": {
"registrationToken": {
"inputLabel": "Registration token"
Expand Down
1 change: 1 addition & 0 deletions packages/onboarding-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"typescript": "~5.0.4"
},
"dependencies": {
"clipboard": "~2.0.11",
"i18next": "~21.6.16",
"react-hook-form": "~7.27.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default {
actions: { argTypesRegex: '^on.*' },
},
args: {
currentStep: 1,
stepCount: 1,
clientKey:
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
} as Meta<Args>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import {
Box,
ButtonGroup,
Button,
Field,
CheckBox,
FieldLabel,
FieldRow,
FieldError,
TextInput,
Label,
} from '@rocket.chat/fuselage';
import { useUniqueId, useBreakpoints } from '@rocket.chat/fuselage-hooks';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import { useState, type ReactElement } from 'react';
import type { SubmitHandler } from 'react-hook-form';
import { useForm, FormProvider } from 'react-hook-form';
import { useTranslation, Trans } from 'react-i18next';
import { useTranslation } from 'react-i18next';

import CopyStep from './steps/CopyStep';
import PasteStep from './steps/PasteStep';

export type RegisterOfflinePayload = {
token: string;
Expand All @@ -25,21 +15,26 @@ export type RegisterOfflinePayload = {
type RegisterOfflineFormProps = {
termsHref: string;
policyHref: string;
clientKey: string;
onSubmit: SubmitHandler<RegisterOfflinePayload>;
onBackButtonClick: () => void;
};

export const Steps = {
COPY: 'copy',
PASTE: 'paste',
};

const RegisterOfflineForm = ({
termsHref,
policyHref,
clientKey,
onSubmit,
onBackButtonClick,
}: RegisterOfflineFormProps): ReactElement => {
const { t } = useTranslation();
const emailField = useUniqueId();

const breakpoints = useBreakpoints();
const isMobile = !breakpoints.includes('md');
const [step, setStep] = useState(Steps.COPY);

const form = useForm<RegisterOfflinePayload>({
mode: 'onChange',
Expand All @@ -49,95 +44,25 @@ const RegisterOfflineForm = ({
},
});

const {
register,
formState: { isSubmitting, isValid, errors },
handleSubmit,
} = form;
const { handleSubmit } = form;

return (
<FormProvider {...form}>
<Form onSubmit={handleSubmit(onSubmit)}>
<Form.Header>
<Form.Title>{t('form.registerOfflineForm.title')}</Form.Title>
</Form.Header>
<Form.Container>
<Box mbe='24px' fontScale='p2'>
<Trans key={'form.registerOfflineForm.description'}>
If for any reason your workspace can’t be connected to the
internet, follow these steps:
<Box mbe='24px' />
1. Go to: <strong>{'cloud.rocket.chat > Workspaces'}</strong> and
click “<strong>Register self-managed</strong><br />
2. Copy the token and paste it below"
</Trans>
</Box>
<Field>
<FieldLabel
required
display='flex'
alignItems='center'
htmlFor={emailField}
>
{t(
'form.registerOfflineForm.fields.registrationToken.inputLabel'
)}
</FieldLabel>
<FieldRow>
<TextInput
{...register('token', {
required: true,
})}
id={emailField}
/>
</FieldRow>
{errors.token && (
<FieldError>{t('component.form.requiredField')}</FieldError>
)}
</Field>
<Box mbs={24}>
<Box
display='flex'
flexDirection='row'
alignItems='flex-start'
color='default'
fontScale='c1'
lineHeight={20}
>
<Box mie={8}>
<CheckBox {...register('agreement', { required: true })} />{' '}
</Box>
<Label required htmlFor='agreement' withRichContent>
<Trans i18nKey='component.form.termsAndConditions'>
I agree with
<a href={termsHref} target='_blank' rel='noopener noreferrer'>
Terms and Conditions
</a>
and
<a
href={policyHref}
target='_blank'
rel='noopener noreferrer'
>
Privacy Policy
</a>
</Trans>
</Label>
</Box>
</Box>
</Form.Container>
<Form.Footer>
<Box display='flex' flexDirection='column'>
<ButtonGroup vertical={isMobile} flexGrow={1}>
<Button type='submit' primary disabled={isSubmitting || !isValid}>
{t('component.form.action.register')}
</Button>
<Button type='button' onClick={onBackButtonClick}>
{t('component.form.action.back')}
</Button>
</ButtonGroup>
</Box>
</Form.Footer>
{step === Steps.COPY ? (
<CopyStep
termsHref={termsHref}
policyHref={policyHref}
clientKey={clientKey}
setStep={setStep}
onBackButtonClick={onBackButtonClick}
/>
) : (
<PasteStep setStep={setStep} />
)}
</Form>
</FormProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import {
Box,
Button,
ButtonGroup,
CheckBox,
Label,
Scrollable,
} from '@rocket.chat/fuselage';
import { useBreakpoints } from '@rocket.chat/fuselage-hooks';
import { Form } from '@rocket.chat/layout';
import Clipboard from 'clipboard';
import { useRef, type ReactElement, useEffect } from 'react';
import { useFormContext } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';

import { Steps } from '../RegisterOfflineForm';

type CopyStepProps = {
termsHref: string;
policyHref: string;
clientKey: string;
onBackButtonClick: () => void;
setStep: (step: string) => void;
};

const CopyStep = ({
termsHref,
policyHref,
clientKey,
setStep,
onBackButtonClick,
}: CopyStepProps): ReactElement => {
const { t } = useTranslation();
const breakpoints = useBreakpoints();
const isMobile = !breakpoints.includes('md');
const copyRef = useRef<HTMLButtonElement>(null);
const {
register,
formState: { isValid },
} = useFormContext();

useEffect(() => {
if (!copyRef.current) {
return;
}

const clipboard = new Clipboard(copyRef.current);

return (): void => {
clipboard.destroy();
};
}, []);

return (
<>
<Form.Container>
<Box mbe='24px' fontScale='p2'>
<Trans key={'form.registerOfflineForm.copyStep.description'}>
If for any reason your workspace can’t be connected to the internet,
follow these steps:
<Box mbe='24px' />
1. Go to: <strong>{'cloud.rocket.chat > Workspaces'}</strong> and
click “<strong>Register self-managed</strong><br />
2. Click “<strong>Continue offline</strong>
<br />
3. In the <strong>Register offline workspace</strong> dialog in
cloud.rocket.chat, paste the token in the box below
</Trans>
</Box>
<Box
display='flex'
flexDirection='column'
alignItems='stretch'
padding={16}
flexGrow={1}
backgroundColor='dark'
>
<Scrollable vertical>
<Box
height='x108'
fontFamily='mono'
fontScale='p2'
color='white'
style={{ wordBreak: 'break-all' }}
>
{clientKey}
</Box>
</Scrollable>
<Button
icon='copy'
ref={copyRef}
primary
data-clipboard-text={clientKey}
/>
</Box>
<Box mbs={24}>
<Box
display='flex'
flexDirection='row'
alignItems='flex-start'
color='default'
fontScale='c1'
lineHeight={20}
>
<Box mie={8}>
<CheckBox {...register('agreement', { required: true })} />{' '}
</Box>
<Label required htmlFor='agreement' withRichContent>
<Trans i18nKey='component.form.termsAndConditions'>
I agree with
<a href={termsHref} target='_blank' rel='noopener noreferrer'>
Terms and Conditions
</a>
and
<a href={policyHref} target='_blank' rel='noopener noreferrer'>
Privacy Policy
</a>
</Trans>
</Label>
</Box>
</Box>
</Form.Container>
<Form.Footer>
<Box display='flex' flexDirection='column'>
<ButtonGroup vertical={isMobile} flexGrow={1}>
<Button
type='button'
primary
disabled={!isValid}
onClick={() => {
setStep(Steps.PASTE);
}}
>
{t('component.form.action.next')}
</Button>
<Button type='button' onClick={onBackButtonClick}>
{t('component.form.action.back')}
</Button>
</ButtonGroup>
</Box>
</Form.Footer>
</>
);
};

export default CopyStep;
Loading

0 comments on commit 88d9050

Please sign in to comment.