2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  SettingsTab  from  "./tab" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  SettingsOption  from  "./option" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  TextInput  }  from  "@mantine/core" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  useCallback ,  useMemo  }  from  "react" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  useAppDispatch ,  useAppSelector  }  from  "../../store" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  selectOpenAIApiKey ,  setOpenAIApiKeyFromEvent  }  from  "../../store/api-keys" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  selectSettingsOption  }  from  "../../store/settings-ui" ;  
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  FormattedMessage ,  useIntl  }  from  "react-intl" ;  
						 
					
						
							
								
									
										
										
										
											2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  function  UserOptionsTab ( props : any )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  option  =  useAppSelector ( selectSettingsOption ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  openaiApiKey  =  useAppSelector ( selectOpenAIApiKey ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  intl  =  useIntl ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  dispatch  =  useAppDispatch ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  onOpenAIApiKeyChange  =  useCallback ( ( event : React.ChangeEvent < HTMLInputElement > )  = >  dispatch ( setOpenAIApiKeyFromEvent ( event ) ) ,  [ dispatch ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  elem  =  useMemo ( ( )  = >  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < SettingsTab  name = "user" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-16 20:05:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            < SettingsOption  heading = { intl . formatMessage ( {  defaultMessage :  "Your OpenAI API Key" ,  description :  "Heading for the OpenAI API key setting on the settings screen"  } ) } 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            focused = { option  ===  'openai-api-key' } > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                < TextInput 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    placeholder = { intl . formatMessage ( {  defaultMessage :  "Paste your API key here"  } ) } 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    value = { openaiApiKey  ||  '' } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    onChange = { onOpenAIApiKeyChange }  / > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                < p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    < a  href = "https://platform.openai.com/account/api-keys"  target = "_blank"  rel = "noreferrer" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-16 20:05:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        < FormattedMessage  defaultMessage = "Find your API key here."  description = "Label for the link that takes the user to the page on the OpenAI website where they can find their API key."  / > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 11:00:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    < / a > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    < FormattedMessage  defaultMessage = "Your API key is stored only on this device and never transmitted to anyone except OpenAI."  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < / p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    < FormattedMessage  defaultMessage = "OpenAI API key usage is billed at a pay-as-you-go rate, separate from your ChatGPT subscription."  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < / p > 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-10 14:00:37 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            < / SettingsOption > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < / SettingsTab > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) ,  [ option ,  openaiApiKey ,  onOpenAIApiKeyChange ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  elem ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}