Skip to content

Commit 6ee4f28

Browse files
committed
refactor(ui): rework the "select a cloud provider" modal
- replace the old ui for the cloud provider select and use Redis UI - enhance the region select to show country flag - removed all legacy sass and replaced with styled components re #RI-7415
1 parent f4ae1d1 commit 6ee4f28

File tree

4 files changed

+69
-115
lines changed

4 files changed

+69
-115
lines changed

redisinsight/ui/src/components/oauth/oauth-select-plan/OAuthSelectPlan.styles.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import styled from 'styled-components'
2+
import { BoxSelectionGroup } from '@redis-ui/components'
3+
4+
import { FlexGroup } from 'uiSrc/components/base/layout/flex'
25
import { ColorText, Text } from 'uiSrc/components/base/text'
36

47
export const StyledModalContentBody = styled.section`
@@ -12,6 +15,24 @@ export const StyledSubTitle = styled(Text)`
1215
padding: 0 40px;
1316
`
1417

18+
export const StyledProvidersSection = styled(FlexGroup)`
19+
width: 100%;
20+
padding: 30px 45px 22px;
21+
`
22+
23+
export const StyledProvidersSelectionGroup = styled(BoxSelectionGroup)`
24+
min-height: 68px;
25+
26+
svg {
27+
width: 28px;
28+
height: initial;
29+
}
30+
31+
p {
32+
font-size: 1.2rem;
33+
}
34+
`
35+
1536
export const StyledRegion = styled.section`
1637
padding: 2px 45px;
1738
text-align: left;

redisinsight/ui/src/components/oauth/oauth-select-plan/OAuthSelectPlan.tsx

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useCallback, useEffect, useState } from 'react'
22
import { toNumber, filter, get, find, first } from 'lodash'
33
import { useDispatch, useSelector } from 'react-redux'
4-
import cx from 'classnames'
54

65
import {
76
createFreeDbJob,
@@ -18,7 +17,6 @@ import { FeatureFlags } from 'uiSrc/constants'
1817
import { Region } from 'uiSrc/slices/interfaces'
1918

2019
import {
21-
EmptyButton,
2220
PrimaryButton,
2321
SecondaryButton,
2422
} from 'uiSrc/components/base/forms/buttons'
@@ -30,22 +28,31 @@ import { Modal } from 'uiSrc/components/base/display'
3028
import { CancelIcon } from 'uiSrc/components/base/icons'
3129
import { CloudSubscriptionPlanResponse } from 'apiSrc/modules/cloud/subscription/dto'
3230
import { OAuthProvider, OAuthProviders } from './constants'
33-
import styles from './styles.module.scss'
3431
import {
3532
StyledFooter,
3633
StyledModalContentBody,
34+
StyledProvidersSection,
35+
StyledProvidersSelectionGroup,
3736
StyledRegion,
3837
StyledRegionName,
3938
StyledRegionSelectDescription,
4039
StyledSubTitle,
4140
} from './OAuthSelectPlan.styles'
41+
import { BoxSelectionGroupBox, CountryFlag } from '@redis-ui/components'
4242

4343
export const DEFAULT_REGIONS = ['us-east-2', 'asia-northeast1']
4444
export const DEFAULT_PROVIDER = OAuthProvider.AWS
4545

4646
const getProviderRegions = (regions: Region[], provider: OAuthProvider) =>
4747
(find(regions, { provider }) || {}).regions || []
4848

49+
const oAuthProvidersBoxes: BoxSelectionGroupBox<OAuthProvider>[] =
50+
OAuthProviders.map(({ id, label, icon }) => ({
51+
value: id,
52+
label,
53+
icon: () => <RiIcon type={icon} size="XL" />,
54+
}))
55+
4956
const OAuthSelectPlan = () => {
5057
const {
5158
isOpenDialog,
@@ -64,16 +71,19 @@ const OAuthSelectPlan = () => {
6471

6572
const [plans, setPlans] = useState(plansInit || [])
6673
const [planIdSelected, setPlanIdSelected] = useState('')
67-
const [providerSelected, setProviderSelected] =
68-
useState<OAuthProvider>(DEFAULT_PROVIDER)
74+
const [providerSelected, setProviderSelected] = useState<
75+
OAuthProvider | string
76+
>(DEFAULT_PROVIDER)
6977
const [rsProviderRegions, setRsProviderRegions] = useState(
70-
getProviderRegions(rsRegions, providerSelected),
78+
getProviderRegions(rsRegions, providerSelected as OAuthProvider),
7179
)
7280

7381
const dispatch = useDispatch()
7482

7583
useEffect(() => {
76-
setRsProviderRegions(getProviderRegions(rsRegions, providerSelected))
84+
setRsProviderRegions(
85+
getProviderRegions(rsRegions, providerSelected as OAuthProvider),
86+
)
7787
}, [providerSelected, plansInit])
7888

7989
useEffect(() => {
@@ -121,30 +131,31 @@ const OAuthSelectPlan = () => {
121131
const getOptionDisplay = (item: CloudSubscriptionPlanResponse) => {
122132
const {
123133
region = '',
124-
details: { countryName = '', cityName = '' },
134+
details: { countryName = '', cityName = '', flag = '' },
125135
provider,
126136
} = item
127137
const rsProviderRegions: string[] =
128138
find(rsRegions, { provider })?.regions || []
129139

130140
return (
131-
<Text
132-
color="subdued"
133-
size="s"
134-
data-testid={`option-${region}`}
135-
data-test-subj={`oauth-region-${region}`}
136-
>
137-
{`${countryName} (${cityName})`}
138-
<StyledRegionName>{region}</StyledRegionName>
139-
{rsProviderRegions?.includes(region) && (
140-
<ColorText
141-
className={styles.rspreview}
142-
data-testid={`rs-text-${region}`}
143-
>
144-
(Redis 7.2)
145-
</ColorText>
146-
)}
147-
</Text>
141+
<Row align="center" gap="s">
142+
<CountryFlag countryCode={flag} />
143+
144+
<Text
145+
color="primary"
146+
data-testid={`option-${region}`}
147+
data-test-subj={`oauth-region-${region}`}
148+
>
149+
{`${countryName} (${cityName})`}
150+
</Text>
151+
152+
<Text color="secondary">
153+
<StyledRegionName>{region}</StyledRegionName>
154+
{rsProviderRegions?.includes(region) && (
155+
<ColorText data-testid={`rs-text-${region}`}>(Redis 7.2)</ColorText>
156+
)}
157+
</Text>
158+
</Row>
148159
)
149160
}
150161

@@ -200,33 +211,18 @@ const OAuthSelectPlan = () => {
200211
towards your free Redis Cloud database. No credit card is
201212
required.
202213
</StyledSubTitle>
203-
<section className={styles.providers}>
204-
{OAuthProviders.map(({ icon, id, label }) => {
205-
const Icon = () => (
206-
<RiIcon type={icon} size="original" style={{ width: 44 }} />
207-
)
208-
return (
209-
<div className={styles.provider} key={id}>
210-
{id === providerSelected && (
211-
<div className={cx(styles.providerActiveIcon)}>
212-
<RiIcon type="CheckThinIcon" />
213-
</div>
214-
)}
215-
<EmptyButton
216-
size="large"
217-
icon={Icon}
218-
onClick={() => setProviderSelected(id)}
219-
className={cx(styles.providerBtn, {
220-
[styles.activeProvider]: id === providerSelected,
221-
})}
222-
/>
223-
<Text>{label}</Text>
224-
</div>
225-
)
226-
})}
227-
</section>
214+
215+
<StyledProvidersSection gap="m" direction="column" align="start">
216+
<Text color="primary">Select cloud vendor</Text>
217+
<StyledProvidersSelectionGroup
218+
boxes={oAuthProvidersBoxes}
219+
value={providerSelected}
220+
onChange={setProviderSelected}
221+
/>
222+
</StyledProvidersSection>
223+
228224
<StyledRegion>
229-
<Text className={styles.regionLabel}>Region</Text>
225+
<Text color="secondary">Region</Text>
230226
<RiSelect
231227
loading={loading}
232228
disabled={loading || !regionOptions.length}
@@ -242,10 +238,7 @@ const OAuthSelectPlan = () => {
242238
}}
243239
/>
244240
{!regionOptions.length && (
245-
<StyledRegionSelectDescription
246-
className={styles.selectDescription}
247-
data-testid="select-region-select-description"
248-
>
241+
<StyledRegionSelectDescription data-testid="select-region-select-description">
249242
No regions available, try another vendor.
250243
</StyledRegionSelectDescription>
251244
)}

redisinsight/ui/src/components/oauth/oauth-select-plan/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AllIconsType } from 'uiSrc/components/base/icons/RiIcon'
2-
import styles from './styles.module.scss'
32

43
export enum OAuthProvider {
54
AWS = 'AWS',
@@ -11,13 +10,11 @@ export const OAuthProviders: {
1110
id: OAuthProvider
1211
icon: AllIconsType
1312
label: string
14-
className?: string
1513
}[] = [
1614
{
1715
id: OAuthProvider.AWS,
1816
icon: 'Awss3Icon',
1917
label: 'Amazon Web Services',
20-
className: styles.awsIcon,
2118
},
2219
{
2320
id: OAuthProvider.Google,

redisinsight/ui/src/components/oauth/oauth-select-plan/styles.module.scss

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)