feat(workspace): 增加工作活动日报引擎
This commit is contained in:
@@ -4,6 +4,12 @@ import type { VersionPlan, PlanType } from '@/lib/version-plan';
|
||||
import { loadServerData, saveServerData } from '@/lib/server-data';
|
||||
import { getPlanCompletionState } from '@/lib/version-plan-workflow';
|
||||
import type { PlanResultPayload } from '@/lib/version-plan-workflow';
|
||||
import {
|
||||
makeVersionPlanCompletedActivity,
|
||||
makeVersionPlanCreatedActivity,
|
||||
makeVersionPlanStartedActivity,
|
||||
} from '@/lib/work-activity-factory';
|
||||
import { useWorkActivityStore } from './useWorkActivityStore';
|
||||
|
||||
const MOCK_PLANS: VersionPlan[] = [];
|
||||
|
||||
@@ -40,10 +46,12 @@ export const useVersionPlanStore = create<VersionPlanState>((set, get) => ({
|
||||
const plans = [...get().plans, plan];
|
||||
set({ plans });
|
||||
saveStored(plans);
|
||||
useWorkActivityStore.getState().addActivity(makeVersionPlanCreatedActivity(plan, plan.addedBy || plan.owner));
|
||||
},
|
||||
|
||||
updatePlan: (id, data) => {
|
||||
const now = new Date().toISOString();
|
||||
const activities: ReturnType<typeof makeVersionPlanStartedActivity>[] = [];
|
||||
const plans = get().plans.map((p) => {
|
||||
if (p.id !== id) return p;
|
||||
const patch = { ...data };
|
||||
@@ -53,10 +61,18 @@ export const useVersionPlanStore = create<VersionPlanState>((set, get) => ({
|
||||
if (patch.status === 'completed' && !p.completedAt) {
|
||||
(patch as any).completedAt = now;
|
||||
}
|
||||
return { ...p, ...patch };
|
||||
const next = { ...p, ...patch };
|
||||
if (p.status !== 'in_progress' && next.status === 'in_progress') {
|
||||
activities.push(makeVersionPlanStartedActivity(next, next.owner));
|
||||
}
|
||||
if (p.status !== 'completed' && next.status === 'completed') {
|
||||
activities.push(makeVersionPlanCompletedActivity(next, next.owner));
|
||||
}
|
||||
return next;
|
||||
});
|
||||
set({ plans });
|
||||
saveStored(plans);
|
||||
activities.forEach((activity) => useWorkActivityStore.getState().addActivity(activity));
|
||||
},
|
||||
|
||||
completePlan: (id, result) => {
|
||||
@@ -70,6 +86,7 @@ export const useVersionPlanStore = create<VersionPlanState>((set, get) => ({
|
||||
return p;
|
||||
}
|
||||
response = { ok: true };
|
||||
useWorkActivityStore.getState().addActivity(makeVersionPlanCompletedActivity(next, next.owner));
|
||||
return next;
|
||||
});
|
||||
set({ plans });
|
||||
|
||||
Reference in New Issue
Block a user