feat: bump client-services (accumulated feature work + deploy fixes)
Snapshot of in-progress work across local_backend, manager_dashboard, and waiter_pwa (pricing, chat, fiscal, prep zones, recovery codes, CRM, inventory, permissions), plus the nginx/docker-compose deploy fixes for the Unraid + NPM reverse-proxy setup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Shield, Lock, LogOut, User, KeyRound } from 'lucide-react'
|
||||
import { Shield, Lock, LogOut, User, KeyRound, ShieldCheck, Copy, RefreshCw, X } from 'lucide-react'
|
||||
import client from '../../../api/client'
|
||||
import { PANEL_CLASS } from '../../../ui/tokens'
|
||||
import Button from '../../../ui/Button'
|
||||
@@ -114,6 +115,143 @@ function TimeSelect({ value, onChange, disabled }) {
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Recovery Codes section ───────────────────────────────────────────────────
|
||||
|
||||
function RecoveryCodesSection() {
|
||||
const [revealedCodes, setRevealedCodes] = useState(null)
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
|
||||
const { data: statusData, refetch: refetchStatus } = useQuery({
|
||||
queryKey: ['recovery-code-status'],
|
||||
queryFn: () => client.get('/api/recovery/status').then(r => r.data),
|
||||
})
|
||||
|
||||
const generateMut = useMutation({
|
||||
mutationFn: () => client.post('/api/recovery/generate').then(r => r.data),
|
||||
onSuccess: (data) => {
|
||||
setRevealedCodes(data.codes)
|
||||
setConfirming(false)
|
||||
refetchStatus()
|
||||
},
|
||||
onError: () => toast.error('Σφάλμα δημιουργίας κωδικών'),
|
||||
})
|
||||
|
||||
const unused = statusData?.unused_count ?? null
|
||||
|
||||
function copyAll() {
|
||||
if (!revealedCodes) return
|
||||
navigator.clipboard.writeText(revealedCodes.join('\n'))
|
||||
toast.success('Οι κωδικοί αντιγράφηκαν!')
|
||||
}
|
||||
|
||||
return (
|
||||
<SectionCard
|
||||
icon={ShieldCheck}
|
||||
title="Κωδικοί Ανάκτησης"
|
||||
description="Μονόχρηστοι κωδικοί έκτακτης ανάγκης. Κάθε κωδικός χρησιμοποιείται μία φορά και καίγεται."
|
||||
>
|
||||
<div className="px-5 py-4 space-y-4">
|
||||
|
||||
{/* Status badge */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm text-gray-700">Διαθέσιμοι κωδικοί:</span>
|
||||
{unused === null ? (
|
||||
<span className="text-xs text-gray-400">Φόρτωση…</span>
|
||||
) : (
|
||||
<span className={`text-sm font-bold ${
|
||||
unused === 0 ? 'text-rose-600' : unused <= 2 ? 'text-amber-600' : 'text-emerald-600'
|
||||
}`}>
|
||||
{unused} / 5
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{unused === 0 && (
|
||||
<span className="text-[11px] bg-rose-50 text-rose-600 border border-rose-200 rounded-full px-2 py-0.5 font-medium">
|
||||
Δεν υπάρχουν κωδικοί!
|
||||
</span>
|
||||
)}
|
||||
{unused > 0 && unused <= 2 && (
|
||||
<span className="text-[11px] bg-amber-50 text-amber-600 border border-amber-200 rounded-full px-2 py-0.5 font-medium">
|
||||
Λίγοι κωδικοί
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Revealed codes (shown once after generation) */}
|
||||
{revealedCodes && (
|
||||
<div className="rounded-xl border border-emerald-200 bg-emerald-50 p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-[12px] font-semibold text-emerald-800">
|
||||
Αντιγράψτε τώρα — δεν θα εμφανιστούν ξανά!
|
||||
</p>
|
||||
<button onClick={() => setRevealedCodes(null)} className="text-emerald-500 hover:text-emerald-700">
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
{revealedCodes.map((code, i) => (
|
||||
<div key={i} className="flex items-center justify-between rounded-lg bg-white border border-emerald-200 px-3 py-2">
|
||||
<span className="font-mono text-sm font-semibold text-emerald-900 tracking-wider">{code}</span>
|
||||
<button
|
||||
onClick={() => { navigator.clipboard.writeText(code); toast.success('Αντιγράφηκε') }}
|
||||
className="text-emerald-400 hover:text-emerald-600"
|
||||
>
|
||||
<Copy className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Button variant="secondary" className="w-full justify-center gap-2 text-[13px]" onClick={copyAll}>
|
||||
<Copy className="h-3.5 w-3.5" /> Αντιγραφή όλων
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Generate / confirm */}
|
||||
{!revealedCodes && (
|
||||
confirming ? (
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50 p-4 space-y-3">
|
||||
<p className="text-[13px] text-amber-800">
|
||||
Αυτό θα <strong>ακυρώσει</strong> τους {unused} υπάρχοντες κωδικούς και θα δημιουργήσει 5 νέους.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
className="flex-1 justify-center text-[13px]"
|
||||
onClick={() => generateMut.mutate()}
|
||||
disabled={generateMut.isPending}
|
||||
>
|
||||
{generateMut.isPending ? 'Δημιουργία…' : 'Ναι, δημιούργησε νέους'}
|
||||
</Button>
|
||||
<Button variant="secondary" className="flex-1 justify-center text-[13px]" onClick={() => setConfirming(false)}>
|
||||
Άκυρο
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
variant={unused === 0 ? 'primary' : 'secondary'}
|
||||
className="w-full justify-center gap-2 text-[13px]"
|
||||
onClick={() => unused > 0 ? setConfirming(true) : generateMut.mutate()}
|
||||
disabled={generateMut.isPending}
|
||||
>
|
||||
<RefreshCw className="h-3.5 w-3.5" />
|
||||
{unused === 0 ? 'Δημιουργία κωδικών ανάκτησης' : 'Αναδημιουργία κωδικών'}
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
|
||||
<p className="text-[11px] text-gray-400">
|
||||
Αποθηκεύστε τους σε ασφαλές μέρος. Κάθε κωδικός δουλεύει μόνο μία φορά.
|
||||
Χρησιμοποιείται στη σελίδα σύνδεσης με το όνομα χρήστη + κωδικό ανάκτησης.
|
||||
</p>
|
||||
</div>
|
||||
</SectionCard>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// ─── Main tab ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function SecurityTab() {
|
||||
@@ -265,6 +403,9 @@ export default function SecurityTab() {
|
||||
)}
|
||||
</SectionCard>
|
||||
|
||||
{/* ── Κωδικοί Ανάκτησης ────────────────────────────────────────────── */}
|
||||
<RecoveryCodesSection />
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user