Unterstützung: Ersteller trägt helfende Personen im Arbeitsblatt ein
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3535f18a2b
commit
d83bbfb48d
5 files changed
+139
-4
No files matched your search
@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react'
|
||||
import { databases, DATABASE_ID, COLLECTIONS, Query, ID } from '../lib/appwrite'
|
||||
import { canEditWorksheetTimes, isGitWorksheet } from '../lib/ticketForm'
|
||||
import { roundUpToStep, isValidStep } from '../lib/timeSteps'
|
||||
import { parseSupporters, serializeSupporters } from '../lib/support'
|
||||
|
||||
const STEP_ERROR = 'Die Arbeitszeit muss in 15-Minuten-Schritten angegeben werden.'
|
||||
|
||||
@@ -181,6 +182,10 @@ export function useWorksheets(woid = null) {
|
||||
countsToPlan: !data.isComment && Boolean(data.countsToPlan),
|
||||
createdAt: new Date().toISOString()
|
||||
}
|
||||
// Nur mitschicken, wenn es Unterstuetzung gibt
|
||||
if (!data.isComment && data.supporters?.length) {
|
||||
worksheetData.supporters = serializeSupporters(data.supporters)
|
||||
}
|
||||
|
||||
console.log('Creating worksheet with data:', worksheetData)
|
||||
|
||||
@@ -232,6 +237,22 @@ export function useWorksheets(woid = null) {
|
||||
const { startDate, startTime, endDate, endTime, totalTime } = times
|
||||
if (!isValidStep(totalTime)) return { success: false, error: STEP_ERROR }
|
||||
const data = { startDate, startTime, endDate, endTime, totalTime }
|
||||
// Unterstuetzung nur schreiben, wenn sie sich geaendert hat. Hat inzwischen jemand anderes
|
||||
// (z. B. ueber "Ich habe unterstuetzt") etwas geaendert, nicht still ueberschreiben.
|
||||
if (times.supporters) {
|
||||
const next = serializeSupporters(times.supporters)
|
||||
if (next !== serializeSupporters(parseSupporters(times.supportersBefore))) {
|
||||
try {
|
||||
const fresh = await databases.getDocument(DATABASE_ID, COLLECTIONS.WORKSHEETS, worksheet.$id)
|
||||
if ((fresh.supporters ?? '') !== (times.supportersBefore ?? '')) {
|
||||
return { success: false, error: 'Inzwischen hat jemand die Unterstützung geändert. Bitte das Formular schließen und neu öffnen.' }
|
||||
}
|
||||
} catch (err) {
|
||||
return { success: false, error: err.message }
|
||||
}
|
||||
data.supporters = next
|
||||
}
|
||||
}
|
||||
// Mit nachgetragener Zeit zaehlt ein Git-Push als Arbeitszeit, nicht mehr als Kommentar
|
||||
if (isGitWorksheet(worksheet)) data.isComment = false
|
||||
return updateWorksheet(worksheet.$id, data)
|
||||
|
||||
Reference in new issue
Block a user