11import React , { useCallback , useEffect , useState } from 'react'
22import { toNumber , filter , get , find , first } from 'lodash'
33import { useDispatch , useSelector } from 'react-redux'
4- import cx from 'classnames'
54
65import {
76 createFreeDbJob ,
@@ -18,7 +17,6 @@ import { FeatureFlags } from 'uiSrc/constants'
1817import { Region } from 'uiSrc/slices/interfaces'
1918
2019import {
21- EmptyButton ,
2220 PrimaryButton ,
2321 SecondaryButton ,
2422} from 'uiSrc/components/base/forms/buttons'
@@ -30,22 +28,31 @@ import { Modal } from 'uiSrc/components/base/display'
3028import { CancelIcon } from 'uiSrc/components/base/icons'
3129import { CloudSubscriptionPlanResponse } from 'apiSrc/modules/cloud/subscription/dto'
3230import { OAuthProvider , OAuthProviders } from './constants'
33- import styles from './styles.module.scss'
3431import {
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
4343export const DEFAULT_REGIONS = [ 'us-east-2' , 'asia-northeast1' ]
4444export const DEFAULT_PROVIDER = OAuthProvider . AWS
4545
4646const 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+
4956const 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 ) }
0 commit comments