@@ -6,6 +6,8 @@ export default function ProdajnaMjesta() {
66 const [ loading , setLoading ] = useState ( true ) ;
77 const [ showForm , setShowForm ] = useState ( false ) ;
88 const [ editingId , setEditingId ] = useState ( null ) ;
9+ const [ changingKey , setChangingKey ] = useState ( false ) ;
10+ const [ originalKey , setOriginalKey ] = useState ( "" ) ;
911 const [ activeLocationId , setActiveLocationId ] = useState ( null ) ;
1012 const [ savingActive , setSavingActive ] = useState ( false ) ;
1113
@@ -60,6 +62,8 @@ export default function ProdajnaMjesta() {
6062 firaApiKey : "" ,
6163 } ) ;
6264 setEditingId ( null ) ;
65+ setChangingKey ( false ) ;
66+ setOriginalKey ( "" ) ;
6367 } ;
6468
6569 const handleSubmit = async ( e ) => {
@@ -70,11 +74,14 @@ export default function ProdajnaMjesta() {
7074 : `${ import . meta. env . VITE_API_URL } /api/prodajna-mjesta` ;
7175 const method = editingId ? "PUT" : "POST" ;
7276
77+ const body = { ...formData } ;
78+ if ( editingId && ! changingKey ) delete body . firaApiKey ;
79+
7380 const response = await fetch ( url , {
7481 method,
7582 headers : { "Content-Type" : "application/json" } ,
7683 credentials : "include" ,
77- body : JSON . stringify ( formData ) ,
84+ body : JSON . stringify ( body ) ,
7885 } ) ;
7986
8087 if ( response . ok ) {
@@ -95,7 +102,9 @@ export default function ProdajnaMjesta() {
95102 paymentDevice : loc . paymentDevice ,
96103 firaApiKey : loc . firaApiKey || "" ,
97104 } ) ;
105+ setOriginalKey ( loc . firaApiKey || "" ) ;
98106 setEditingId ( loc . id ) ;
107+ setChangingKey ( false ) ;
99108 setShowForm ( true ) ;
100109 } ;
101110
@@ -190,13 +199,44 @@ export default function ProdajnaMjesta() {
190199
191200 < div className = "form-group" >
192201 < label > FIRA API Ključ:</ label >
193- < input
194- type = "password"
195- value = { formData . firaApiKey }
196- onChange = { ( e ) => setFormData ( { ...formData , firaApiKey : e . target . value } ) }
197- required
198- placeholder = "Unesite ključ"
199- />
202+ { editingId ? (
203+ < >
204+ < p style = { { margin : "4px 0 8px" , color : "#555" } } >
205+ Ključ je unesen: < code > ****{ originalKey . slice ( - 4 ) } </ code >
206+ </ p >
207+ < label style = { { display : "flex" , alignItems : "center" , gap : "8px" , fontWeight : "normal" , cursor : "pointer" } } >
208+ < input
209+ type = "checkbox"
210+ checked = { changingKey }
211+ onChange = { ( e ) => {
212+ setChangingKey ( e . target . checked ) ;
213+ setFormData ( { ...formData , firaApiKey : e . target . checked ? "" : originalKey } ) ;
214+ } }
215+ />
216+ Promjeni ključ
217+ </ label >
218+ { changingKey && (
219+ < input
220+ type = "text"
221+ value = { formData . firaApiKey }
222+ onChange = { ( e ) => setFormData ( { ...formData , firaApiKey : e . target . value } ) }
223+ required
224+ placeholder = "Unesite novi ključ"
225+ style = { { marginTop : "8px" } }
226+ autoComplete = "off"
227+ />
228+ ) }
229+ </ >
230+ ) : (
231+ < input
232+ type = "text"
233+ value = { formData . firaApiKey }
234+ onChange = { ( e ) => setFormData ( { ...formData , firaApiKey : e . target . value } ) }
235+ required
236+ placeholder = "Unesite ključ"
237+ autoComplete = "off"
238+ />
239+ ) }
200240 </ div >
201241
202242 < div style = { { display : "flex" , gap : "10px" } } >
0 commit comments