1
1
'use client'
2
2
3
- import React , { useEffect } from 'react'
3
+ import React , { useEffect , useState } from 'react'
4
4
import { zodResolver } from '@hookform/resolvers/zod'
5
5
import { useMutation , useQuery } from '@tanstack/react-query'
6
6
import { useForm } from 'react-hook-form'
@@ -23,6 +23,7 @@ export default function KnowledgeBasePrompts() {
23
23
useKnowledgeStore ( )
24
24
25
25
const { user } = useTokenStore ( )
26
+ const [ buttonDisabled , setButtonDisabled ] = useState ( true )
26
27
27
28
interface Data {
28
29
user : string | null
@@ -58,6 +59,7 @@ export default function KnowledgeBasePrompts() {
58
59
title : 'Prompt Settings' ,
59
60
description : 'Prompt Settings has Successfully Updated' ,
60
61
} )
62
+ setButtonDisabled ( true )
61
63
} ,
62
64
} )
63
65
// ..........................
@@ -67,6 +69,21 @@ export default function KnowledgeBasePrompts() {
67
69
reset ( )
68
70
}
69
71
72
+ const handlePromptChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
73
+ setPrompt ( e . target . value )
74
+ setButtonDisabled ( false )
75
+ }
76
+
77
+ const handleTemperatureChange = ( value : number [ ] ) => {
78
+ setModelConfiguration ( { ...modelConfiguration , temperature : value [ 0 ] } )
79
+ setButtonDisabled ( false )
80
+ }
81
+
82
+ const handleTopChange = ( value : number [ ] ) => {
83
+ setModelConfiguration ( { ...modelConfiguration , topP : value [ 0 ] } )
84
+ setButtonDisabled ( false )
85
+ }
86
+
70
87
// getPrompt
71
88
const { data : PromptData , isLoading : FileLoading } = useQuery ( {
72
89
queryKey : [ 'getPrompt' ] ,
@@ -75,6 +92,7 @@ export default function KnowledgeBasePrompts() {
75
92
useEffect ( ( ) => {
76
93
if ( PromptData && PromptData ?. prompt [ 0 ] ?. prompt ) {
77
94
setPrompt ( PromptData . prompt [ 0 ] . prompt )
95
+ setButtonDisabled ( true )
78
96
}
79
97
} , [ PromptData ] )
80
98
// .......................
@@ -98,7 +116,7 @@ export default function KnowledgeBasePrompts() {
98
116
required
99
117
rows = { 10 }
100
118
value = { prompt }
101
- onChange = { ( e ) => setPrompt ( e . target . value ) }
119
+ onChange = { handlePromptChange }
102
120
className = 'focus:border-gray-400 focus:ring-0'
103
121
/>
104
122
{ errors . prompt && < > { errors . prompt . message } </ > }
@@ -107,7 +125,7 @@ export default function KnowledgeBasePrompts() {
107
125
< Button
108
126
className = 'bg-black text-dashboardSecondary hover:bg-gray-800'
109
127
onClick = { handleSubmit ( handleClick ) }
110
- disabled = { promptPending }
128
+ disabled = { buttonDisabled }
111
129
>
112
130
Save changes
113
131
</ Button >
@@ -149,12 +167,7 @@ export default function KnowledgeBasePrompts() {
149
167
min = { 0 }
150
168
max = { 2 }
151
169
step = { 0.1 }
152
- onValueChange = { ( value ) =>
153
- setModelConfiguration ( {
154
- ...modelConfiguration ,
155
- temperature : value [ 0 ] ,
156
- } )
157
- }
170
+ onValueChange = { handleTemperatureChange }
158
171
/>
159
172
</ div >
160
173
@@ -172,16 +185,14 @@ export default function KnowledgeBasePrompts() {
172
185
min = { 0 }
173
186
max = { 1 }
174
187
step = { 0.01 }
175
- onValueChange = { ( value ) =>
176
- setModelConfiguration ( { ...modelConfiguration , topP : value [ 0 ] } )
177
- }
188
+ onValueChange = { handleTopChange }
178
189
/>
179
190
</ div >
180
191
</ div >
181
192
182
193
< Button
183
194
onClick = { handleSubmit ( handleClick ) }
184
- disabled = { promptPending }
195
+ disabled = { buttonDisabled }
185
196
className = 'mt-2 bg-[#EAEAEA] text-dashboardHeading hover:bg-neutral-200'
186
197
>
187
198
Save as preset
0 commit comments