@@ -4,16 +4,16 @@ import {
4
4
Input ,
5
5
Switch ,
6
6
} from "@nextui-org/react" ;
7
- import React from "react" ;
8
- import clsx from "clsx" ;
9
7
import { useFetcher , useLocation , useNavigate } from "@remix-run/react" ;
10
- import { organizeModelsAndProviders } from "#/utils/organizeModelsAndProviders" ;
11
- import { ModelSelector } from "#/components/modals/settings/ModelSelector" ;
12
- import { Settings } from "#/services/settings" ;
8
+ import clsx from "clsx" ;
9
+ import React from "react" ;
13
10
import { ModalBackdrop } from "#/components/modals/modal-backdrop" ;
14
- import ModalButton from "../buttons/ModalButton " ;
11
+ import { ModelSelector } from "#/components/modals/settings/ModelSelector " ;
15
12
import { clientAction } from "#/routes/settings" ;
13
+ import { Settings } from "#/services/settings" ;
16
14
import { extractModelAndProvider } from "#/utils/extractModelAndProvider" ;
15
+ import { organizeModelsAndProviders } from "#/utils/organizeModelsAndProviders" ;
16
+ import ModalButton from "../buttons/ModalButton" ;
17
17
import { DangerModal } from "../modals/confirmation-modals/danger-modal" ;
18
18
19
19
interface SettingsFormProps {
@@ -44,9 +44,8 @@ export function SettingsForm({
44
44
navigate ( "/" ) ;
45
45
onClose ( ) ;
46
46
}
47
- } , [ fetcher . data ] ) ;
47
+ } , [ fetcher . data , navigate , onClose ] ) ;
48
48
49
- // Figure out if the advanced options should be enabled by default
50
49
const advancedAlreadyInUse = React . useMemo ( ( ) => {
51
50
if ( models . length > 0 ) {
52
51
const organizedModels = organizeModelsAndProviders ( models ) ;
@@ -79,6 +78,7 @@ export function SettingsForm({
79
78
React . useState ( false ) ;
80
79
const [ confirmEndSessionModalOpen , setConfirmEndSessionModalOpen ] =
81
80
React . useState ( false ) ;
81
+ const [ showWarningModal , setShowWarningModal ] = React . useState ( false ) ;
82
82
83
83
const submitForm = ( formData : FormData ) => {
84
84
if ( location . pathname === "/app" ) formData . set ( "end-session" , "true" ) ;
@@ -98,15 +98,41 @@ export function SettingsForm({
98
98
99
99
const handleSubmit = ( event : React . FormEvent < HTMLFormElement > ) => {
100
100
event . preventDefault ( ) ;
101
+ const formData = new FormData ( event . currentTarget ) ;
102
+ const apiKey = formData . get ( "api-key" ) ;
101
103
102
- if ( location . pathname === "/app" ) {
104
+ if ( ! apiKey ) {
105
+ setShowWarningModal ( true ) ;
106
+ } else if ( location . pathname === "/app" ) {
103
107
setConfirmEndSessionModalOpen ( true ) ;
104
108
} else {
105
- const formData = new FormData ( event . currentTarget ) ;
106
109
submitForm ( formData ) ;
107
110
}
108
111
} ;
109
112
113
+ const handleCloseClick = ( ) => {
114
+ const formData = new FormData ( formRef . current ?? undefined ) ;
115
+ const apiKey = formData . get ( "api-key" ) ;
116
+
117
+ if ( ! apiKey ) {
118
+ setShowWarningModal ( true ) ;
119
+ } else {
120
+ onClose ( ) ;
121
+ }
122
+ } ;
123
+
124
+ const handleWarningConfirm = ( ) => {
125
+ setShowWarningModal ( false ) ;
126
+ const formData = new FormData ( formRef . current ?? undefined ) ;
127
+ formData . set ( "api-key" , "" ) ; // Set null value for API key
128
+ submitForm ( formData ) ;
129
+ onClose ( ) ;
130
+ } ;
131
+
132
+ const handleWarningCancel = ( ) => {
133
+ setShowWarningModal ( false ) ;
134
+ } ;
135
+
110
136
return (
111
137
< div >
112
138
< fetcher . Form
@@ -125,7 +151,7 @@ export function SettingsForm({
125
151
onValueChange = { setShowAdvancedOptions }
126
152
classNames = { {
127
153
thumb : clsx (
128
- "bg-[#5D5D5D] w-3 h-3" ,
154
+ "bg-[#5D5D5D] w-3 h-3 z-0 " ,
129
155
"group-data-[selected=true]:bg-white" ,
130
156
) ,
131
157
wrapper : clsx (
@@ -325,7 +351,7 @@ export function SettingsForm({
325
351
< ModalButton
326
352
text = "Close"
327
353
className = "bg-[#737373] w-full"
328
- onClick = { onClose }
354
+ onClick = { handleCloseClick }
329
355
/>
330
356
</ div >
331
357
< ModalButton
@@ -373,6 +399,24 @@ export function SettingsForm({
373
399
/>
374
400
</ ModalBackdrop >
375
401
) }
402
+ { showWarningModal && (
403
+ < ModalBackdrop >
404
+ < DangerModal
405
+ title = "Are you sure?"
406
+ description = "You haven't set an API key. Without an API key, you won't be able to use the AI features. Are you sure you want to close the settings?"
407
+ buttons = { {
408
+ danger : {
409
+ text : "Yes, close settings" ,
410
+ onClick : handleWarningConfirm ,
411
+ } ,
412
+ cancel : {
413
+ text : "Cancel" ,
414
+ onClick : handleWarningCancel ,
415
+ } ,
416
+ } }
417
+ />
418
+ </ ModalBackdrop >
419
+ ) }
376
420
</ div >
377
421
) ;
378
422
}
0 commit comments