Fix event lock system: banner persistence, stale isEditing guard, and Edit button gating
- Remove isEditing guard from viewLockQuery effect so lock banner shows for user B even after user A transitions into edit mode (fixes banner disappearing) - Disable Edit button proactively when lockInfo.locked is already known from polling, preventing the user from even attempting acquireLock when a lock is active - Fix acquire callback dep array in useEventLock (missing acquireMutation) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c55af91c60
commit
e62503424c
@ -276,16 +276,15 @@ export default function EventDetailPanel({
|
|||||||
refetchInterval: 5_000,
|
refetchInterval: 5_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show/hide lock banner proactively in view mode
|
// Show/hide lock banner proactively in view mode (poll data always authoritative)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewLockQuery.data && !isEditing && !isCreating) {
|
if (!viewLockQuery.data) return;
|
||||||
if (viewLockQuery.data.locked) {
|
if (viewLockQuery.data.locked) {
|
||||||
setLockInfo(viewLockQuery.data);
|
setLockInfo(viewLockQuery.data);
|
||||||
} else {
|
} else {
|
||||||
setLockInfo(null);
|
setLockInfo(null);
|
||||||
}
|
}
|
||||||
}
|
}, [viewLockQuery.data]);
|
||||||
}, [viewLockQuery.data, isEditing, isCreating]);
|
|
||||||
|
|
||||||
const isRecurring = !!(event?.is_recurring || event?.parent_event_id);
|
const isRecurring = !!(event?.is_recurring || event?.parent_event_id);
|
||||||
|
|
||||||
@ -581,8 +580,8 @@ export default function EventDetailPanel({
|
|||||||
size="icon"
|
size="icon"
|
||||||
className="h-7 w-7"
|
className="h-7 w-7"
|
||||||
onClick={handleEditStart}
|
onClick={handleEditStart}
|
||||||
disabled={isAcquiringLock}
|
disabled={isAcquiringLock || !!(lockInfo && lockInfo.locked)}
|
||||||
title="Edit event"
|
title={lockInfo && lockInfo.locked ? `Locked by ${lockInfo.locked_by_name || 'another user'}` : 'Edit event'}
|
||||||
>
|
>
|
||||||
{isAcquiringLock ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Pencil className="h-3.5 w-3.5" />}
|
{isAcquiringLock ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Pencil className="h-3.5 w-3.5" />}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export function useEventLock(eventId: number | null) {
|
|||||||
if (!eventId) return null;
|
if (!eventId) return null;
|
||||||
const data = await acquireMutation.mutateAsync(eventId);
|
const data = await acquireMutation.mutateAsync(eventId);
|
||||||
return data;
|
return data;
|
||||||
}, [eventId]);
|
}, [eventId, acquireMutation]);
|
||||||
|
|
||||||
const release = useCallback(async () => {
|
const release = useCallback(async () => {
|
||||||
const id = activeEventIdRef.current;
|
const id = activeEventIdRef.current;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user