Skip to content

Commit 7dcc346

Browse files
Move new Decision edit workflow out of prototype and into /organisation/{orgId}/decision/{decisionId}/edit
1 parent b462d0f commit 7dcc346

File tree

7 files changed

+82
-60
lines changed

7 files changed

+82
-60
lines changed

app/admin/prototypes/page.tsx

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use client'
2+
3+
import WorkflowAccordion from '@/components/workflow/WorkflowAccordion'
4+
import { notFound } from 'next/navigation'
5+
import { useState } from 'react'
6+
import { DecisionWorkflowStep, DecisionWorkflowSteps } from '@/lib/domain/Decision'
7+
8+
interface EditDecisionClientProps {
9+
organisationId: string
10+
id: string
11+
}
12+
13+
export default function EditDecisionClient({ organisationId, id }: EditDecisionClientProps) {
14+
const [currentStep, setCurrentStep] = useState<DecisionWorkflowStep>(DecisionWorkflowSteps.IDENTIFY)
15+
16+
if (!organisationId || !id) {
17+
return notFound()
18+
}
19+
20+
const handleStepChange = (nextStep: DecisionWorkflowStep) => {
21+
setCurrentStep(nextStep)
22+
}
23+
24+
return (
25+
<div className="container mx-auto py-8">
26+
<WorkflowAccordion
27+
organisationId={organisationId}
28+
decisionId={id}
29+
currentStep={currentStep}
30+
onStepChange={handleStepChange}
31+
/>
32+
</div>
33+
)
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { use } from 'react'
2+
import EditDecisionClient from './EditDecisionClient'
3+
4+
interface EditDecisionPageProps {
5+
params: {
6+
organisationId: string
7+
id: string
8+
}
9+
}
10+
11+
export default function EditDecisionPage({ params }: EditDecisionPageProps) {
12+
const resolvedParams = use(Promise.resolve(params))
13+
14+
return (
15+
<EditDecisionClient
16+
organisationId={resolvedParams.organisationId}
17+
id={resolvedParams.id}
18+
/>
19+
)
20+
}

app/admin/prototypes/WorkflowAccordion.tsx renamed to components/workflow/WorkflowAccordion.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { useState, useEffect } from 'react'
1+
'use client';
2+
3+
import React, { useState, useEffect, useCallback, useMemo } from 'react'
24
import {
35
Accordion,
46
AccordionContent,
@@ -7,6 +9,7 @@ import {
79
} from "@/components/ui/accordion"
810
import {
911
DecisionWorkflowStep,
12+
DecisionWorkflowSteps,
1013
DecisionWorkflowStepsSequence,
1114
WorkflowNavigator,
1215
Cost,
@@ -48,16 +51,16 @@ import { STYLE_CLASSES } from './WorkflowAccordionConstants'
4851
import { StepHeader, ProgressBar, NextButton } from './WorkflowAccordionComponents'
4952

5053
interface WorkflowAccordionProps {
51-
currentStep: DecisionWorkflowStep
52-
onStepComplete?: (step: DecisionWorkflowStep) => void
54+
currentStep?: DecisionWorkflowStep
55+
onStepChange?: (nextStep: DecisionWorkflowStep) => void
5356
className?: string
5457
organisationId?: string
5558
decisionId?: string
5659
}
5760

5861
export default function WorkflowAccordion({
59-
currentStep,
60-
onStepComplete,
62+
currentStep = DecisionWorkflowSteps.IDENTIFY,
63+
onStepChange,
6164
className,
6265
organisationId = "9HY1YTkOdqxOTFOMZe8r",
6366
decisionId = "KRWdpmQTU2DRR76jrlC4"
@@ -217,6 +220,13 @@ export default function WorkflowAccordion({
217220
updateDecisionCriteria(newCriteria)
218221
}
219222

223+
const handleStepComplete = useCallback((step: DecisionWorkflowStep) => {
224+
const nextStep = WorkflowNavigator.getNextStep(step);
225+
if (nextStep && onStepChange) {
226+
onStepChange(nextStep);
227+
}
228+
}, [onStepChange]);
229+
220230
const renderStepContent = (step: DecisionWorkflowStep) => {
221231
if (step.key === 'identify' && decision && stakeholders) {
222232
const uniqueOrgStakeholders = stakeholders.sort((a, b) => a.displayName.localeCompare(b.displayName));
@@ -583,7 +593,9 @@ export default function WorkflowAccordion({
583593
{isCurrent && (
584594
<div className="flex justify-between items-center mt-8">
585595
<NextButton
586-
onComplete={() => onStepComplete?.(step)}
596+
onComplete={() => {
597+
handleStepComplete(step);
598+
}}
587599
stepLabel={step.label}
588600
/>
589601
<ProgressBar

app/admin/prototypes/WorkflowAccordionComponents.tsx renamed to components/workflow/WorkflowAccordionComponents.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { cn } from '@/lib/utils'
24
import { ArrowDown } from 'lucide-react'
35
import { DecisionWorkflowStep, DecisionWorkflowStepKey, StepRoles } from '@/lib/domain/Decision'
@@ -82,10 +84,16 @@ interface NextButtonProps {
8284
}
8385

8486
export function NextButton({ onComplete, stepLabel }: NextButtonProps) {
87+
if (typeof onComplete !== 'function') {
88+
return null;
89+
}
90+
8591
return (
8692
<button
87-
onClick={onComplete}
88-
className="mr-4 px-4 py-2 bg-primary text-primary-foreground rounded-md inline-flex items-center gap-2 hover:bg-primary/90 transition-colors"
93+
onClick={() => {
94+
onComplete();
95+
}}
96+
className="mr-4 px-4 py-2 bg-primary text-primary-foreground rounded-md inline-flex items-center gap-2 hover:bg-primary/90 transition-colors hover:scale-105 active:scale-95"
8997
aria-label={`Complete ${stepLabel} and proceed to next step`}
9098
>
9199
Next
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)