feat: add feature limit enforcement UI (Phase 4 Batch 1)
Implementiert User-freundliches Limit-Feedback für Daten-Einträge:
- Button wird deaktiviert wenn Limit erreicht
- Hover-Tooltip erklärt warum ("Limit erreicht X/Y")
- Button-Text zeigt "🔒 Limit erreicht"
- Error-Handling für alle API-Fehler
- Usage-Badge wird nach Speichern aktualisiert
Betrifft: Weight, Circumference, Caliper Screens
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf522190c6
commit
0f019f87a4
3 files changed
+131
-21
No files matched your search
@@ -3,6 +3,7 @@ import { Pencil, Trash2, Check, X, Camera, BookOpen } from 'lucide-react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { api } from '../utils/api'
|
||||
import { CIRCUMFERENCE_POINTS } from '../utils/guideData'
|
||||
import UsageBadge from '../components/UsageBadge'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const FIELDS = ['c_neck','c_chest','c_waist','c_belly','c_hip','c_thigh','c_calf','c_arm']
|
||||
@@ -16,18 +17,32 @@ export default function CircumScreen() {
|
||||
const [editing, setEditing] = useState(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [saved, setSaved] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const [photoFile, setPhotoFile] = useState(null)
|
||||
const [photoPreview, setPhotoPreview] = useState(null)
|
||||
const [circumUsage, setCircumUsage] = useState(null) // Phase 4: Usage badge
|
||||
const fileRef = useRef()
|
||||
const nav = useNavigate()
|
||||
|
||||
const load = () => api.listCirc().then(setEntries)
|
||||
useEffect(()=>{ load() },[])
|
||||
|
||||
const loadUsage = () => {
|
||||
api.getFeatureUsage().then(features => {
|
||||
const circumFeature = features.find(f => f.feature_id === 'circumference_entries')
|
||||
setCircumUsage(circumFeature)
|
||||
}).catch(err => console.error('Failed to load usage:', err))
|
||||
}
|
||||
|
||||
useEffect(()=>{
|
||||
load()
|
||||
loadUsage()
|
||||
},[])
|
||||
|
||||
const set = (k,v) => setForm(f=>({...f,[k]:v}))
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
const payload = {}
|
||||
payload.date = form.date
|
||||
@@ -38,10 +53,18 @@ export default function CircumScreen() {
|
||||
payload.photo_id = pr.id
|
||||
}
|
||||
await api.upsertCirc(payload)
|
||||
setSaved(true); await load()
|
||||
setSaved(true)
|
||||
await load()
|
||||
await loadUsage() // Reload usage after save
|
||||
setTimeout(()=>setSaved(false),2000)
|
||||
setForm(empty()); setPhotoFile(null); setPhotoPreview(null)
|
||||
} finally { setSaving(false) }
|
||||
} catch (err) {
|
||||
console.error('Save failed:', err)
|
||||
setError(err.message || 'Fehler beim Speichern')
|
||||
setTimeout(()=>setError(null), 5000)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const startEdit = (e) => setEditing({...e})
|
||||
@@ -72,7 +95,10 @@ export default function CircumScreen() {
|
||||
|
||||
{/* Eingabe */}
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">Neue Messung</div>
|
||||
<div className="card-title badge-container-right">
|
||||
<span>Neue Messung</span>
|
||||
{circumUsage && <UsageBadge {...circumUsage} />}
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Datum</label>
|
||||
<input type="date" className="form-input" style={{width:140}} value={form.date} onChange={e=>set('date',e.target.value)}/>
|
||||
@@ -99,8 +125,22 @@ export default function CircumScreen() {
|
||||
<button className="btn btn-secondary btn-full" onClick={()=>fileRef.current.click()}>
|
||||
<Camera size={14}/> {photoPreview?'Foto ändern':'Foto hinzufügen'}
|
||||
</button>
|
||||
<button className="btn btn-primary btn-full" style={{marginTop:8}} onClick={handleSave} disabled={saving}>
|
||||
{saved ? <><Check size={14}/> Gespeichert!</> : saving ? '…' : 'Speichern'}
|
||||
{error && (
|
||||
<div style={{padding:'10px',background:'var(--danger-bg)',border:'1px solid var(--danger)',borderRadius:8,fontSize:13,color:'var(--danger)',marginTop:8}}>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
className="btn btn-primary btn-full"
|
||||
style={{marginTop:8, cursor: (circumUsage && !circumUsage.allowed) ? 'not-allowed' : 'pointer'}}
|
||||
onClick={handleSave}
|
||||
disabled={saving || (circumUsage && !circumUsage.allowed)}
|
||||
title={circumUsage && !circumUsage.allowed ? `Limit erreicht (${circumUsage.used}/${circumUsage.limit}). Kontaktiere den Admin oder warte bis zum nächsten Reset.` : ''}
|
||||
>
|
||||
{saved ? <><Check size={14}/> Gespeichert!</>
|
||||
: saving ? '…'
|
||||
: (circumUsage && !circumUsage.allowed) ? '🔒 Limit erreicht'
|
||||
: 'Speichern'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user