Skip to content

Commit 4ac2333

Browse files
committed
fixed time in fira not being correct, refactored input of api key
1 parent ae6bba8 commit 4ac2333

3 files changed

Lines changed: 51 additions & 18 deletions

File tree

backend/fira.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export async function handleOrderFiscalization(order, options = {}) {
6464

6565

6666
// Format datetime for FIRA API (LocalDateTime format without timezone)
67-
const createdAt = new Date(order.createdAt).toISOString().slice(0, 19);
67+
const d = new Date(order.createdAt);
68+
const pad = (n) => String(n).padStart(2, '0');
69+
const createdAt = `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
6870

6971
// Billing address for FIRA API
7072
// Include email if available - FIRA will send email invoice if configured

backend/index.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -932,15 +932,6 @@ app.put('/api/settings/active-location', requireAuth, async (req, res) => {
932932
app.get('/api/prodajna-mjesta', requireAuth, async (req, res) => {
933933
try {
934934
const locations = await prisma.prodajnoMjesto.findMany();
935-
// TODO: re-enable masking
936-
// const safeLocations = locations.map(loc => {
937-
// let maskedKey = "********";
938-
// try {
939-
// const real = decrypt(loc.firaApiKey);
940-
// maskedKey = `****${real.slice(-4)}`;
941-
// } catch { /* leave as ******** if decryption fails */ }
942-
// return { ...loc, firaApiKey: maskedKey };
943-
// });
944935
const safeLocations = locations.map(loc => {
945936
try {
946937
return { ...loc, firaApiKey: decrypt(loc.firaApiKey) };

frontend/src/pages/admin/ProdajnaMjesta.jsx

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)