Allow attaching a photo when adding a meter reading
This commit is contained in:
parent
85c843c9ef
commit
b1aa3bc0c7
1 changed files with 7 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ export default function Readings() {
|
||||||
const [value, setValue] = useState('')
|
const [value, setValue] = useState('')
|
||||||
const [date, setDate] = useState(new Date().toISOString().slice(0, 10))
|
const [date, setDate] = useState(new Date().toISOString().slice(0, 10))
|
||||||
const [notes, setNotes] = useState('')
|
const [notes, setNotes] = useState('')
|
||||||
|
const [photo, setPhoto] = useState<File | null>(null)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [info, setInfo] = useState<string | null>(null)
|
const [info, setInfo] = useState<string | null>(null)
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
|
|
@ -43,8 +44,10 @@ export default function Readings() {
|
||||||
setInfo(null)
|
setInfo(null)
|
||||||
try {
|
try {
|
||||||
const r = await api.createReading({ meter_id: Number(meterId), reading_value: parseFloat(value), reading_date: date, notes: notes || undefined })
|
const r = await api.createReading({ meter_id: Number(meterId), reading_value: parseFloat(value), reading_date: date, notes: notes || undefined })
|
||||||
|
if (photo) await api.uploadReadingPhoto(r.id, photo)
|
||||||
setValue('')
|
setValue('')
|
||||||
setNotes('')
|
setNotes('')
|
||||||
|
setPhoto(null)
|
||||||
if (r.warning) setInfo(r.warning)
|
if (r.warning) setInfo(r.warning)
|
||||||
loadReadings()
|
loadReadings()
|
||||||
loadMeters()
|
loadMeters()
|
||||||
|
|
@ -101,6 +104,10 @@ export default function Readings() {
|
||||||
<label>Notes</label>
|
<label>Notes</label>
|
||||||
<input type="text" value={notes} onChange={e => setNotes(e.target.value)} placeholder="optional" />
|
<input type="text" value={notes} onChange={e => setNotes(e.target.value)} placeholder="optional" />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="field" style={{ marginBottom: 0 }}>
|
||||||
|
<label>Photo</label>
|
||||||
|
<input type="file" accept="image/*" onChange={e => setPhoto(e.target.files?.[0] || null)} style={{ fontSize: 11 }} />
|
||||||
|
</div>
|
||||||
<button className="btn btn-primary" onClick={submit} disabled={saving} style={{ marginBottom: 1 }}>
|
<button className="btn btn-primary" onClick={submit} disabled={saving} style={{ marginBottom: 1 }}>
|
||||||
{saving ? 'Saving…' : 'Add reading'}
|
{saving ? 'Saving…' : 'Add reading'}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue