feat(store): add lifecycle/inspection/estimate-version mutators
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
import React, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
import { STAGE_PROGRESS } from './lifecycle';
|
||||||
|
|
||||||
// Fixed "today" for the demo so seeded dates never go stale or land in the future.
|
// Fixed "today" for the demo so seeded dates never go stale or land in the future.
|
||||||
export const DEMO_TODAY = new Date('2026-05-29T12:00:00');
|
export const DEMO_TODAY = new Date('2026-05-29T12:00:00');
|
||||||
@@ -8485,6 +8486,43 @@ export const MockStoreProvider = ({ children }) => {
|
|||||||
updateProject: (projectId, data) => {
|
updateProject: (projectId, data) => {
|
||||||
setProjects(prev => prev.map(p => p.id === projectId ? { ...p, ...data } : p));
|
setProjects(prev => prev.map(p => p.id === projectId ? { ...p, ...data } : p));
|
||||||
},
|
},
|
||||||
|
// Lifecycle: set stage, log the transition, sync completionPercentage from the stage map.
|
||||||
|
advanceLifecycleStage: (projectId, stage, note, by) => {
|
||||||
|
setProjects(prev => prev.map(p => p.id === projectId ? {
|
||||||
|
...p,
|
||||||
|
lifecycleStage: stage,
|
||||||
|
completionPercentage: stage === 'Work In Progress'
|
||||||
|
? Math.max(p.completionPercentage || 0, 55) // WIP is milestone-driven; never regress within it
|
||||||
|
: (STAGE_PROGRESS[stage] ?? p.completionPercentage),
|
||||||
|
stageHistory: [...(p.stageHistory || []), { stage, date: new Date().toISOString().slice(0, 10), by: by || 'Owner', note: note || '' }],
|
||||||
|
} : p));
|
||||||
|
},
|
||||||
|
addInspection: (projectId, inspection) => {
|
||||||
|
setProjects(prev => prev.map(p => p.id === projectId
|
||||||
|
? { ...p, inspections: [...(p.inspections || []), { ...inspection, id: inspection.id || `insp_${Date.now()}` }] }
|
||||||
|
: p));
|
||||||
|
},
|
||||||
|
addInspectionIssue: (projectId, inspectionId, issue) => {
|
||||||
|
setProjects(prev => prev.map(p => p.id === projectId ? {
|
||||||
|
...p,
|
||||||
|
inspections: (p.inspections || []).map(ins => ins.id === inspectionId
|
||||||
|
? { ...ins, issues: [...(ins.issues || []), { ...issue, id: issue.id || `iss_${Date.now()}`, status: 'open' }] }
|
||||||
|
: ins),
|
||||||
|
} : p));
|
||||||
|
},
|
||||||
|
resolveInspectionIssue: (projectId, inspectionId, issueId) => {
|
||||||
|
setProjects(prev => prev.map(p => p.id === projectId ? {
|
||||||
|
...p,
|
||||||
|
inspections: (p.inspections || []).map(ins => ins.id === inspectionId
|
||||||
|
? { ...ins, issues: (ins.issues || []).map(iss => iss.id === issueId ? { ...iss, status: 'fixed' } : iss) }
|
||||||
|
: ins),
|
||||||
|
} : p));
|
||||||
|
},
|
||||||
|
addEstimateVersion: (projectId, version) => {
|
||||||
|
setProjects(prev => prev.map(p => p.id === projectId
|
||||||
|
? { ...p, estimateVersions: [...(p.estimateVersions || []), version] }
|
||||||
|
: p));
|
||||||
|
},
|
||||||
addJobTeamMember: (projectId, member) => {
|
addJobTeamMember: (projectId, member) => {
|
||||||
setProjects(prev => prev.map(p => p.id === projectId
|
setProjects(prev => prev.map(p => p.id === projectId
|
||||||
? { ...p, teamMembers: [...(p.teamMembers || []), { ...member, id: `jtm_${Date.now()}` }] }
|
? { ...p, teamMembers: [...(p.teamMembers || []), { ...member, id: `jtm_${Date.now()}` }] }
|
||||||
|
|||||||
Reference in New Issue
Block a user