Implement dynamic selection of primary domain name (#32)
* Add dynamic selection of primary domain * Update alert message * Fix alert message * Update alert message --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
		
							parent
							
								
									f870ab90f7
								
							
						
					
					
						commit
						42ec846ff2
					
				| @ -1,4 +1,4 @@ | |||||||
| import React from 'react'; | import React, { useEffect, useState } from 'react'; | ||||||
| import { Link } from 'react-router-dom'; | import { Link } from 'react-router-dom'; | ||||||
| import { useForm } from 'react-hook-form'; | import { useForm } from 'react-hook-form'; | ||||||
| import { | import { | ||||||
| @ -15,6 +15,7 @@ const SetupDomain = () => { | |||||||
|     handleSubmit, |     handleSubmit, | ||||||
|     formState: { isValid }, |     formState: { isValid }, | ||||||
|     watch, |     watch, | ||||||
|  |     setValue, | ||||||
|   } = useForm({ |   } = useForm({ | ||||||
|     defaultValues: { |     defaultValues: { | ||||||
|       domainName: '', |       domainName: '', | ||||||
| @ -22,6 +23,25 @@ const SetupDomain = () => { | |||||||
|     }, |     }, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   const [domainStr, setDomainStr] = useState(''); | ||||||
|  | 
 | ||||||
|  |   useEffect(() => { | ||||||
|  |     const subscription = watch((value, { name }) => { | ||||||
|  |       if (name === 'domainName' && value.domainName) { | ||||||
|  |         const domainArr = value.domainName.split('www.'); | ||||||
|  |         setDomainStr(domainArr.length > 1 ? domainArr[1] : domainArr[0]); | ||||||
|  | 
 | ||||||
|  |         if (value.domainName.startsWith('www.')) { | ||||||
|  |           setValue('isWWW', 'true'); | ||||||
|  |         } else { | ||||||
|  |           setValue('isWWW', 'false'); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     return () => subscription.unsubscribe(); | ||||||
|  |   }, [watch]); | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <form |     <form | ||||||
|       onSubmit={handleSubmit(() => {})} |       onSubmit={handleSubmit(() => {})} | ||||||
| @ -53,14 +73,14 @@ const SetupDomain = () => { | |||||||
|           <Typography>Primary domain</Typography> |           <Typography>Primary domain</Typography> | ||||||
|           <div className="flex flex-col gap-3"> |           <div className="flex flex-col gap-3"> | ||||||
|             <Radio |             <Radio | ||||||
|               label={watch('domainName')} |               label={domainStr} | ||||||
|               crossOrigin={undefined} |               crossOrigin={undefined} | ||||||
|               {...register('isWWW')} |               {...register('isWWW')} | ||||||
|               value="false" |               value="false" | ||||||
|               type="radio" |               type="radio" | ||||||
|             /> |             /> | ||||||
|             <Radio |             <Radio | ||||||
|               label={`www.${watch('domainName')}`} |               label={`www.${domainStr}`} | ||||||
|               crossOrigin={undefined} |               crossOrigin={undefined} | ||||||
|               {...register('isWWW')} |               {...register('isWWW')} | ||||||
|               value="true" |               value="true" | ||||||
| @ -68,8 +88,11 @@ const SetupDomain = () => { | |||||||
|             /> |             /> | ||||||
|           </div> |           </div> | ||||||
|           <Alert color="blue"> |           <Alert color="blue"> | ||||||
|             <i>^</i> For simplicity, we’ll redirect the www variant to{' '} |             <i>^</i> For simplicity, we’ll redirect the{' '} | ||||||
|             {watch('domainName')}. Redirect preferences can be changed later. |             {watch('isWWW') === 'true' | ||||||
|  |               ? `non-www variant to www.${domainStr}` | ||||||
|  |               : `www variant to ${domainStr}`} | ||||||
|  |             . Redirect preferences can be changed later | ||||||
|           </Alert> |           </Alert> | ||||||
|         </div> |         </div> | ||||||
|       )} |       )} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user