@ -16,6 +16,7 @@ interface State {
disablePublicMemos : boolean ;
additionalStyle : string ;
additionalScript : string ;
openAIConfig : OpenAIConfig ;
}
const SystemSection = ( ) = > {
@ -29,10 +30,7 @@ const SystemSection = () => {
additionalStyle : systemStatus.additionalStyle ,
additionalScript : systemStatus.additionalScript ,
disablePublicMemos : systemStatus.disablePublicMemos ,
} ) ;
const [ openAIConfig , setOpenAIConfig ] = useState < OpenAIConfig > ( {
key : "" ,
host : "" ,
openAIConfig : systemStatus.openAIConfig ,
} ) ;
useEffect ( ( ) = > {
@ -47,18 +45,10 @@ const SystemSection = () => {
additionalStyle : systemStatus.additionalStyle ,
additionalScript : systemStatus.additionalScript ,
disablePublicMemos : systemStatus.disablePublicMemos ,
openAIConfig : systemStatus.openAIConfig ,
} ) ;
} , [ systemStatus ] ) ;
useEffect ( ( ) = > {
api . getSystemSetting ( ) . then ( ( { data : { data : systemSettings } } ) = > {
const openAIConfigSetting = systemSettings . find ( ( setting ) = > setting . name === "openai-config" ) ;
if ( openAIConfigSetting ) {
setOpenAIConfig ( JSON . parse ( openAIConfigSetting . value ) ) ;
}
} ) ;
} , [ ] ) ;
const handleAllowSignUpChanged = async ( value : boolean ) = > {
setState ( {
. . . state ,
@ -97,9 +87,12 @@ const SystemSection = () => {
} ;
const handleOpenAIConfigKeyChanged = ( value : string ) = > {
setOpenAIConfig ( {
. . . openAIConfig ,
key : value ,
setState ( {
. . . state ,
openAIConfig : {
. . . state . openAIConfig ,
key : value ,
} ,
} ) ;
} ;
@ -107,8 +100,9 @@ const SystemSection = () => {
try {
await api . upsertSystemSetting ( {
name : "openai-config" ,
value : JSON.stringify ( openAIConfig) ,
value : JSON.stringify ( state. openAIConfig) ,
} ) ;
globalStore . setSystemStatus ( { openAIConfig : state.openAIConfig } ) ;
} catch ( error ) {
console . error ( error ) ;
return ;
@ -117,9 +111,12 @@ const SystemSection = () => {
} ;
const handleOpenAIConfigHostChanged = ( value : string ) = > {
setOpenAIConfig ( {
. . . openAIConfig ,
host : value ,
setState ( {
. . . state ,
openAIConfig : {
. . . state . openAIConfig ,
host : value ,
} ,
} ) ;
} ;
@ -225,7 +222,7 @@ const SystemSection = () => {
fontSize : "14px" ,
} }
placeholder = { t ( "setting.system-section.openai-api-key-placeholder" ) }
value = { openAIConfig. key }
value = { state. openAIConfig. key }
onChange = { ( event ) = > handleOpenAIConfigKeyChanged ( event . target . value ) }
/ >
< div className = "form-label mt-2" >
@ -238,7 +235,7 @@ const SystemSection = () => {
fontSize : "14px" ,
} }
placeholder = { t ( "setting.system-section.openai-api-host-placeholder" ) }
value = { openAIConfig. host }
value = { state. openAIConfig. host }
onChange = { ( event ) = > handleOpenAIConfigHostChanged ( event . target . value ) }
/ >
< Divider className = "!mt-3 !my-4" / >