Fixed handoff staying on original user temporarily
This commit is contained in:
+25
-4
@@ -25,7 +25,7 @@ export interface Task {
|
|||||||
priority: number; // 1-10
|
priority: number; // 1-10
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
ownerId: string; // Add ownerId to interface
|
ownerId: string | null; // Add ownerId to interface
|
||||||
content?: string; // HTML content from Tiptap
|
content?: string; // HTML content from Tiptap
|
||||||
deletedAt?: number; // Timestamp of soft delete
|
deletedAt?: number; // Timestamp of soft delete
|
||||||
created: string; // ISO string from PB
|
created: string; // ISO string from PB
|
||||||
@@ -389,7 +389,7 @@ const mapRecordToTask = (r: any): Task => {
|
|||||||
priority: r.priority,
|
priority: r.priority,
|
||||||
completed: r.completed,
|
completed: r.completed,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
ownerId: r.user,
|
ownerId: r.user || null,
|
||||||
content: r.content,
|
content: r.content,
|
||||||
deletedAt: r.deletedAt ? new Date(r.deletedAt).getTime() : undefined,
|
deletedAt: r.deletedAt ? new Date(r.deletedAt).getTime() : undefined,
|
||||||
created: r.created,
|
created: r.created,
|
||||||
@@ -1097,6 +1097,19 @@ const checkForHandoffs = (task: Task, updates: Partial<Task>): Partial<Task> =>
|
|||||||
|
|
||||||
if (rule) {
|
if (rule) {
|
||||||
console.log(`Handoff triggered by tag "${tag}" -> Transferring to ${rule.targetUserId}`);
|
console.log(`Handoff triggered by tag "${tag}" -> Transferring to ${rule.targetUserId}`);
|
||||||
|
|
||||||
|
// Check if it's a bucket tag (target is self, but tag is a bucket)
|
||||||
|
const isBucketRule = rule.targetUserId === currentUserId && store.tagDefinitions.find(t => t.name === tag)?.isBucket;
|
||||||
|
|
||||||
|
if (isBucketRule) {
|
||||||
|
return {
|
||||||
|
...updates,
|
||||||
|
ownerId: null, // Unassign from current user (null is better for PB relations)
|
||||||
|
// Remove current user from sharedWith to ensure it disappears from their view
|
||||||
|
sharedWith: (task.sharedWith || []).filter(s => s.userId !== currentUserId)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...updates,
|
...updates,
|
||||||
ownerId: rule.targetUserId,
|
ownerId: rule.targetUserId,
|
||||||
@@ -1132,8 +1145,8 @@ export const updateTask = async (id: string, updates: Partial<Task>) => {
|
|||||||
// Check for specific fields being updated
|
// Check for specific fields being updated
|
||||||
const pbUpdates: any = { ...finalUpdates };
|
const pbUpdates: any = { ...finalUpdates };
|
||||||
|
|
||||||
if (finalUpdates.ownerId) {
|
if (finalUpdates.ownerId !== undefined) {
|
||||||
pbUpdates.user = finalUpdates.ownerId; // Map ownerId to 'user' field in PB
|
pbUpdates.user = finalUpdates.ownerId || null; // Map ownerId to 'user' field in PB
|
||||||
delete pbUpdates.ownerId;
|
delete pbUpdates.ownerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1335,6 +1348,7 @@ export const syncSystemTagsAndRules = async () => {
|
|||||||
|
|
||||||
const normalizedRules = pbRules.map(r => ({
|
const normalizedRules = pbRules.map(r => ({
|
||||||
id: r.id,
|
id: r.id,
|
||||||
|
ownerId: r.ownerId,
|
||||||
targetUserId: r.targetUserId,
|
targetUserId: r.targetUserId,
|
||||||
type: r.type,
|
type: r.type,
|
||||||
tagName: r.tagName
|
tagName: r.tagName
|
||||||
@@ -1364,6 +1378,13 @@ export const syncSystemTagsAndRules = async () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Failed to create bucket tag ${bucket.name}`, e);
|
console.error(`Failed to create bucket tag ${bucket.name}`, e);
|
||||||
}
|
}
|
||||||
|
} else if (!tagExists.isBucket) {
|
||||||
|
try {
|
||||||
|
await pb.collection(TAGS_COLLECTION).update(tagExists.id, { isBucket: true });
|
||||||
|
setStore("tagDefinitions", d => d.id === tagExists.id, { isBucket: true });
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to flag tag ${bucket.name} as bucket`, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// --- Sync Bucket System Rule ---
|
// --- Sync Bucket System Rule ---
|
||||||
// Ensure a ShareRule exists for this bucket so it appears in "System Rules"
|
// Ensure a ShareRule exists for this bucket so it appears in "System Rules"
|
||||||
|
|||||||
Reference in New Issue
Block a user