@@ -182,31 +182,39 @@ const SearchApplicationSettings: React.FC = () => {
182182 const [ searchPersonaOptions , setSearchPersonaOptions ] = useState ( [ "admin" ] ) ;
183183
184184 // Populate personas dropdown options
185- useEffect ( ( ) => {
185+ useEffect ( ( ) => {
186186 ( async ( ) => {
187187 const fetchedPersonas = await fetchPersonaOptions ( )
188188 setSearchPersonaOptions ( fetchedPersonas )
189189 } ) ( )
190190 } , [ ] )
191191
192192 // Ensure we have an API key and override the "missing" default
193- useEffect ( ( ) => {
194- ( async ( ) => {
193+ useEffect ( ( ) => {
194+ ( async ( ) => {
195195 if ( searchPersonaAPIKey == "missing" ) {
196196 const createdAPIKey = await createPersonaAPIKey ( searchPersona )
197197 updateSearchPersonaAPIKey ( createdAPIKey )
198198 }
199199 } ) ( )
200200 } , [ ] )
201201
202+ // Ensure that the API key is updated when searchPersona changes
203+ useEffect ( ( ) => {
204+ ( async ( ) => {
205+ const apiKey = await createPersonaAPIKey ( searchPersona ) ;
206+ updateSearchPersonaAPIKey ( apiKey ) ;
207+ } ) ( )
208+ } , [ searchPersona ] ) ;
209+
202210 const [ isOpen , setIsOpen ] = useState ( false ) ;
203211
204212 const toggleDropdown = ( ) => {
205213 setIsOpen ( ! isOpen ) ;
206214 } ;
207215
208216 const handlePersonaChange = async ( value : string ) => {
209- updateSearchPersona ( value , await createPersonaAPIKey ( value ) ) ;
217+ updateSearchPersona ( value ) ;
210218 } ;
211219
212220 const handleSave = ( ) => {
@@ -222,7 +230,7 @@ const SearchApplicationSettings: React.FC = () => {
222230
223231 const updateSearchEndpoint = ( e ) => dispatch ( updateSettings ( { appName, appUser, appPassword, searchEndpoint : e . target . value , searchPersona, searchPersonaAPIKey} ) )
224232
225- const updateSearchPersona = ( persona , apiKey ) => dispatch ( updateSettings ( { appName, appUser, appPassword, searchEndpoint, searchPersona : persona , searchPersonaAPIKey : apiKey } ) )
233+ const updateSearchPersona = ( persona ) => dispatch ( updateSettings ( { appName, appUser, appPassword, searchEndpoint, searchPersona : persona , searchPersonaAPIKey} ) )
226234
227235 const updateSearchPersonaAPIKey = ( apiKey ) => dispatch ( updateSettings ( { appName, appUser, appPassword, searchEndpoint, searchPersona, searchPersonaAPIKey : apiKey } ) )
228236
0 commit comments