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,25 +17,42 @@ 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'
25- import { ColorText , Text } from 'uiSrc/components/base/text'
23+ import { ColorText , Text , Title } from 'uiSrc/components/base/text'
24+ import { Row } from 'uiSrc/components/base/layout/flex'
2625import { RiIcon } from 'uiSrc/components/base/icons/RiIcon'
2726import { RiSelect } from 'uiSrc/components/base/forms/select/RiSelect'
2827import { Modal } from 'uiSrc/components/base/display'
2928import { CancelIcon } from 'uiSrc/components/base/icons'
3029import { CloudSubscriptionPlanResponse } from 'apiSrc/modules/cloud/subscription/dto'
3130import { OAuthProvider , OAuthProviders } from './constants'
32- import styles from './styles.module.scss'
31+ import {
32+ StyledFooter ,
33+ StyledModalContentBody ,
34+ StyledProvidersSection ,
35+ StyledProvidersSelectionGroup ,
36+ StyledRegion ,
37+ StyledRegionName ,
38+ StyledRegionSelectDescription ,
39+ StyledSubTitle ,
40+ } from './OAuthSelectPlan.styles'
41+ import { BoxSelectionGroupBox , CountryFlag } from '@redis-ui/components'
3342
3443export const DEFAULT_REGIONS = [ 'us-east-2' , 'asia-northeast1' ]
3544export const DEFAULT_PROVIDER = OAuthProvider . AWS
3645
3746const getProviderRegions = ( regions : Region [ ] , provider : OAuthProvider ) =>
3847 ( find ( regions , { provider } ) || { } ) . regions || [ ]
3948
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+
4056const OAuthSelectPlan = ( ) => {
4157 const {
4258 isOpenDialog,
@@ -58,13 +74,15 @@ const OAuthSelectPlan = () => {
5874 const [ providerSelected , setProviderSelected ] =
5975 useState < OAuthProvider > ( DEFAULT_PROVIDER )
6076 const [ rsProviderRegions , setRsProviderRegions ] = useState (
61- getProviderRegions ( rsRegions , providerSelected ) ,
77+ getProviderRegions ( rsRegions , providerSelected as OAuthProvider ) ,
6278 )
6379
6480 const dispatch = useDispatch ( )
6581
6682 useEffect ( ( ) => {
67- setRsProviderRegions ( getProviderRegions ( rsRegions , providerSelected ) )
83+ setRsProviderRegions (
84+ getProviderRegions ( rsRegions , providerSelected as OAuthProvider ) ,
85+ )
6886 } , [ providerSelected , plansInit ] )
6987
7088 useEffect ( ( ) => {
@@ -112,30 +130,31 @@ const OAuthSelectPlan = () => {
112130 const getOptionDisplay = ( item : CloudSubscriptionPlanResponse ) => {
113131 const {
114132 region = '' ,
115- details : { countryName = '' , cityName = '' } ,
133+ details : { countryName = '' , cityName = '' , flag = '' } ,
116134 provider,
117135 } = item
118136 const rsProviderRegions : string [ ] =
119137 find ( rsRegions , { provider } ) ?. regions || [ ]
120138
121139 return (
122- < Text
123- color = "subdued"
124- size = "s"
125- data-testid = { `option-${ region } ` }
126- data-test-subj = { `oauth-region-${ region } ` }
127- >
128- { `${ countryName } (${ cityName } )` }
129- < ColorText className = { styles . regionName } > { region } </ ColorText >
130- { rsProviderRegions ?. includes ( region ) && (
131- < ColorText
132- className = { styles . rspreview }
133- data-testid = { `rs-text-${ region } ` }
134- >
135- (Redis 7.2)
136- </ ColorText >
137- ) }
138- </ Text >
140+ < Row align = "center" gap = "s" >
141+ < CountryFlag countryCode = { flag } />
142+
143+ < Text
144+ color = "primary"
145+ data-testid = { `option-${ region } ` }
146+ data-test-subj = { `oauth-region-${ region } ` }
147+ >
148+ { `${ countryName } (${ cityName } )` }
149+ </ Text >
150+
151+ < Text color = "secondary" >
152+ < StyledRegionName > { region } </ StyledRegionName >
153+ { rsProviderRegions ?. includes ( region ) && (
154+ < ColorText data-testid = { `rs-text-${ region } ` } > (Redis 7.2)</ ColorText >
155+ ) }
156+ </ Text >
157+ </ Row >
139158 )
140159 }
141160
@@ -173,45 +192,38 @@ const OAuthSelectPlan = () => {
173192
174193 return (
175194 < Modal . Compose open >
176- < Modal . Content . Compose className = { styles . container } data-testid = "oauth-select-plan-dialog" >
177- < Modal . Content . Close icon = { CancelIcon } onClick = { handleOnClose } data-testid = "oauth-select-plan-dialog-close-btn" />
195+ < Modal . Content . Compose data-testid = "oauth-select-plan-dialog" >
196+ < Modal . Content . Close
197+ icon = { CancelIcon }
198+ onClick = { handleOnClose }
199+ data-testid = "oauth-select-plan-dialog-close-btn"
200+ />
178201 < Modal . Content . Header . Title >
179- Choose a cloud vendor
202+ < Row justify = "center" >
203+ < Title > Choose a cloud vendor</ Title >
204+ </ Row >
180205 </ Modal . Content . Header . Title >
181206 < Modal . Content . Body . Compose width = "fit-content" >
182- < section className = { styles . content } >
183- < Text className = { styles . subTitle } >
207+ < StyledModalContentBody >
208+ < StyledSubTitle color = "default" >
184209 Select a cloud vendor and region to complete the final step
185210 towards your free Redis Cloud database. No credit card is
186211 required.
187- </ Text >
188- < section className = { styles . providers } >
189- { OAuthProviders . map ( ( { icon, id, label } ) => {
190- const Icon = ( ) => (
191- < RiIcon type = { icon } size = "original" style = { { width : 44 } } />
192- )
193- return (
194- < div className = { styles . provider } key = { id } >
195- { id === providerSelected && (
196- < div className = { cx ( styles . providerActiveIcon ) } >
197- < RiIcon type = "CheckThinIcon" />
198- </ div >
199- ) }
200- < EmptyButton
201- size = "large"
202- icon = { Icon }
203- onClick = { ( ) => setProviderSelected ( id ) }
204- className = { cx ( styles . providerBtn , {
205- [ styles . activeProvider ] : id === providerSelected ,
206- } ) }
207- />
208- < Text className = { styles . providerLabel } > { label } </ Text >
209- </ div >
210- )
211- } ) }
212- </ section >
213- < section className = { styles . region } >
214- < Text className = { styles . regionLabel } > Region</ Text >
212+ </ StyledSubTitle >
213+
214+ < StyledProvidersSection gap = "m" direction = "column" align = "start" >
215+ < Text color = "primary" > Select cloud vendor</ Text >
216+ < StyledProvidersSelectionGroup
217+ boxes = { oAuthProvidersBoxes }
218+ value = { providerSelected }
219+ onChange = { ( value : string ) =>
220+ setProviderSelected ( value as OAuthProvider )
221+ }
222+ />
223+ </ StyledProvidersSection >
224+
225+ < StyledRegion >
226+ < Text color = "secondary" > Region</ Text >
215227 < RiSelect
216228 loading = { loading }
217229 disabled = { loading || ! regionOptions . length }
@@ -227,35 +239,32 @@ const OAuthSelectPlan = () => {
227239 } }
228240 />
229241 { ! regionOptions . length && (
230- < Text
231- className = { styles . selectDescription }
232- data-testid = "select-region-select-description"
233- >
242+ < StyledRegionSelectDescription data-testid = "select-region-select-description" >
234243 No regions available, try another vendor.
235- </ Text >
244+ </ StyledRegionSelectDescription >
236245 ) }
237- </ section >
238- < footer className = { styles . footer } >
239- < SecondaryButton
240- className = { styles . button }
241- onClick = { handleOnClose }
242- data-testid = "close-oauth-select-plan-dialog"
243- aria-labelledby = "close oauth select plan dialog"
244- >
245- Cancel
246- </ SecondaryButton >
247- < PrimaryButton
248- disabled = { loading || ! planIdSelected }
249- loading = { loading }
250- className = { styles . button }
251- onClick = { handleSubmit }
252- data-testid = "submit- oauth- select- plan- dialog"
253- aria-labelledby = "submit oauth select plan dialog"
254- >
255- Create database
256- </ PrimaryButton >
257- </ footer >
258- </ section >
246+ </ StyledRegion >
247+ < StyledFooter >
248+ < Row justify = "end" gap = "m" >
249+ < SecondaryButton
250+ onClick = { handleOnClose }
251+ data-testid = "close-oauth-select-plan-dialog"
252+ aria-labelledby = "close oauth select plan dialog"
253+ >
254+ Cancel
255+ </ SecondaryButton >
256+ < PrimaryButton
257+ disabled = { loading || ! planIdSelected }
258+ loading = { loading }
259+ onClick = { handleSubmit }
260+ data-testid = "submit-oauth-select-plan-dialog"
261+ aria-labelledby = "submit oauth select plan dialog"
262+ >
263+ Create database
264+ </ PrimaryButton >
265+ </ Row >
266+ </ StyledFooter >
267+ </ StyledModalContentBody >
259268 </ Modal . Content . Body . Compose >
260269 </ Modal . Content . Compose >
261270 </ Modal . Compose >
0 commit comments