Skip to content

Commit d2c69db

Browse files
authored
feat(onboarding-ui): update props and fix bugs in CreateCloudWorkspac… (#675)
* feat(onboarding-ui): update props and fix bugs in CreateCloudWorkspacePage * feat: add optional onBackButtonClick prop * feat: add required rule to the select fields * refactor: email and url error handling and add default values * fix: rerun ci test
1 parent aea7c9a commit d2c69db

File tree

5 files changed

+36
-45
lines changed

5 files changed

+36
-45
lines changed

packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
['pt', 'Português'],
2424
],
2525
domain: 'rocket.chat',
26-
validateUrl: async (url) => url !== 'rocket',
26+
validateUrl: async (url) => (url === 'rocket' ? 'invalid url' : true),
2727
validateEmail: async (email) =>
2828
email === 'rocket@rocket.chat' ? 'invalid email' : true,
2929
},

packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.tsx

+26-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Grid,
1313
} from '@rocket.chat/fuselage';
1414
import type { ReactElement } from 'react';
15-
import type { SubmitHandler } from 'react-hook-form';
15+
import type { SubmitHandler, Validate } from 'react-hook-form';
1616
import { useForm, Controller } from 'react-hook-form';
1717
import { useTranslation, Trans } from 'react-i18next';
1818

@@ -31,20 +31,23 @@ type CreateCloudWorkspaceFormPayload = {
3131
};
3232

3333
type CreateCloudWorkspaceFormProps = {
34+
defaultValues?: CreateCloudWorkspaceFormPayload;
3435
onSubmit: SubmitHandler<CreateCloudWorkspaceFormPayload>;
3536
serverRegionOptions: SelectOption[];
3637
languageOptions: SelectOption[];
3738
domain: string;
38-
onBackButtonClick: () => void;
39-
validateUrl: (url: string) => Promise<boolean>;
40-
validateEmail: (url: string) => Promise<boolean>;
39+
onBackButtonClick?: () => void;
40+
validateUrl: Validate<string>;
41+
validateEmail: Validate<string>;
4142
};
4243

4344
const CreateCloudWorkspaceForm = ({
45+
defaultValues,
4446
onSubmit,
4547
domain,
4648
serverRegionOptions,
4749
languageOptions,
50+
onBackButtonClick,
4851
validateUrl,
4952
validateEmail,
5053
}: CreateCloudWorkspaceFormProps): ReactElement => {
@@ -68,20 +71,16 @@ const CreateCloudWorkspaceForm = ({
6871
</Field.Label>
6972
<Field.Row>
7073
<EmailInput
71-
error={errors?.organizationEmail?.type || undefined}
7274
{...register('organizationEmail', {
7375
required: true,
7476
validate: validateEmail,
7577
})}
78+
defaultValue={defaultValues?.organizationEmail}
79+
error={errors?.organizationEmail?.type || undefined}
7680
/>
7781
</Field.Row>
78-
{errors.organizationEmail?.type === 'required' && (
79-
<Field.Error>{t('component.form.requiredField')}</Field.Error>
80-
)}
81-
{errors.organizationEmail?.type === 'validate' && (
82-
<Field.Error>
83-
{t('form.createCloudWorkspace.fields.orgEmail.invalid')}
84-
</Field.Error>
82+
{errors?.organizationEmail && (
83+
<Field.Error>{errors.organizationEmail.message}</Field.Error>
8584
)}
8685
</Field>
8786

@@ -93,8 +92,9 @@ const CreateCloudWorkspaceForm = ({
9392
</Field.Label>
9493
<Field.Row>
9594
<TextInput
96-
error={errors?.workspaceName?.type || undefined}
9795
{...register('workspaceName', { required: true })}
96+
defaultValue={defaultValues?.workspaceName}
97+
error={errors?.workspaceName?.type || undefined}
9898
/>
9999
</Field.Row>
100100
{errors.workspaceName && (
@@ -115,15 +115,11 @@ const CreateCloudWorkspaceForm = ({
115115
required: true,
116116
validate: validateUrl,
117117
})}
118+
defaultValue={defaultValues?.workspaceURL}
118119
/>
119120
</Field.Row>
120-
{errors.workspaceURL?.type === 'required' && (
121-
<Field.Error>{t('component.form.requiredField')}</Field.Error>
122-
)}
123-
{errors.workspaceURL?.type === 'validate' && (
124-
<Field.Error>
125-
{t('form.createCloudWorkspace.fields.workspaceUrl.exists')}
126-
</Field.Error>
121+
{errors?.workspaceURL && (
122+
<Field.Error>{errors.workspaceURL.message}</Field.Error>
127123
)}
128124
</Field>
129125

@@ -144,6 +140,8 @@ const CreateCloudWorkspaceForm = ({
144140
<Controller
145141
name='serverRegion'
146142
control={control}
143+
rules={{ required: true }}
144+
defaultValue={defaultValues?.serverRegion}
147145
render={({ field }) => (
148146
<Select
149147
{...field}
@@ -172,6 +170,8 @@ const CreateCloudWorkspaceForm = ({
172170
<Controller
173171
name='language'
174172
control={control}
173+
rules={{ required: true }}
174+
defaultValue={defaultValues?.language}
175175
render={({ field }) => (
176176
<Select
177177
{...field}
@@ -228,6 +228,12 @@ const CreateCloudWorkspaceForm = ({
228228

229229
<Form.Footer>
230230
<ButtonGroup>
231+
{onBackButtonClick && (
232+
<Button disabled={isSubmitting} onClick={onBackButtonClick}>
233+
{t('component.form.action.back')}
234+
</Button>
235+
)}
236+
231237
<Button
232238
type='submit'
233239
primary

packages/onboarding-ui/src/pages/CreateCloudWorkspacePage/CreateCloudWorkspacePage.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
['pt', 'Português'],
2323
],
2424
domain: 'rocket.chat',
25-
validateUrl: async (url) => url !== 'rocket',
25+
validateUrl: async (url) => (url === 'rocket' ? 'invalid url' : true),
2626
validateEmail: async (email) =>
2727
email === 'rocket@rocket.chat' ? 'invalid email' : true,
2828
},

packages/onboarding-ui/src/pages/CreateCloudWorkspacePage/CreateCloudWorkspacePage.tsx

+5-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import type { SelectOption } from '@rocket.chat/fuselage';
21
import { Box } from '@rocket.chat/fuselage';
3-
import type { ReactElement } from 'react';
4-
import type { SubmitHandler } from 'react-hook-form';
2+
import type { ComponentProps, ReactElement } from 'react';
53
import { useTranslation, Trans } from 'react-i18next';
64

75
import BackgroundLayer from '../../common/BackgroundLayer';
@@ -10,23 +8,9 @@ import CreateCloudWorkspaceForm from '../../forms/CreateCloudWorkspaceForm';
108
import Description from './Description';
119
import TitleCreateCloudPage from './TitleCreateCloudPage';
1210

13-
type CreateCloudWorkspacePageProps = {
14-
onSubmit: SubmitHandler<{
15-
organizationEmail: string;
16-
workspaceName: string;
17-
workspaceURL: string;
18-
serverRegion: string;
19-
language: string;
20-
agreement: boolean;
21-
updates: boolean;
22-
}>;
23-
domain: string;
24-
serverRegionOptions: SelectOption[];
25-
languageOptions: SelectOption[];
26-
onBackButtonClick: () => void;
27-
validateUrl: (url: string) => Promise<boolean>;
28-
validateEmail: (url: string) => Promise<boolean>;
29-
};
11+
type CreateCloudWorkspacePageProps = ComponentProps<
12+
typeof CreateCloudWorkspaceForm
13+
>;
3014

3115
const CreateCloudWorkspacePage = (
3216
props: CreateCloudWorkspacePageProps
@@ -41,6 +25,7 @@ const CreateCloudWorkspacePage = (
4125
subtitle={t('page.createCloudWorkspace.tryGold')}
4226
>
4327
<CreateCloudWorkspaceForm {...props} />
28+
4429
<Box mbs='x28' display='inline' textAlign='center'>
4530
<Trans i18nKey='page.alreadyHaveAccount'>
4631
Already have an account?

packages/onboarding-ui/src/pages/CreateCloudWorkspacePage/Description.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const Description = (): ReactElement => {
3232
[color]
3333
);
3434

35-
const listItem = (text: string) => (
36-
<List.Item fontScale='p1'>
35+
const listItem = (text: string, id: number) => (
36+
<List.Item key={id} fontScale='p1'>
3737
<Icon name='check' size='x24' mie='x12' />
3838
{text}
3939
</List.Item>
@@ -43,7 +43,7 @@ const Description = (): ReactElement => {
4343
<Box>
4444
<Box>
4545
<List color={color} spacing='x16' icon={icon}>
46-
{featuresList.map((text) => listItem(text))}
46+
{featuresList.map((text, id) => listItem(text, id))}
4747
</List>
4848
</Box>
4949
</Box>

0 commit comments

Comments
 (0)