Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions components/process-progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
CheckCircle2,
Circle,
GitBranch,
Loader2,
SkipForward,
Undo2,
Expand Down Expand Up @@ -134,6 +135,46 @@
);
}

function BranchPicker({
children,
onPick,
onDismiss,
}: {
children: PurchaseProcessStep[];
onPick: (step: PurchaseProcessStep) => void;
onDismiss: () => void;
}) {
return (
<div className="animate-in slide-in-from-top-1 fade-in-0 flex flex-col gap-2 border-t px-3 py-2.5 duration-200">
<p className="text-muted-foreground flex items-center gap-1.5 text-xs font-medium">
<GitBranch className="size-3" />
Choose next step
</p>
<div className="flex flex-wrap gap-2">
{children.map((child) => (
<Button
key={child.id}
size="sm"
variant="outline"
className="h-7 px-3 text-xs"
onClick={() => onPick(child)}
>
{child.name}
</Button>
))}
<Button
size="sm"
variant="ghost"
className="text-muted-foreground h-7 px-3 text-xs"
onClick={onDismiss}
>
Decide later
</Button>
</div>
</div>
);
}

const PURCHASE_PROCESS_KEY = (purchaseId: string) => [
'purchase-process',
purchaseId,
Expand All @@ -149,6 +190,9 @@
const queryClient = useQueryClient();
const [mutatingStepId, setMutatingStepId] = useState<string | null>(null);
const [expandedStepId, setExpandedStepId] = useState<string | null>(null);
const [branchPickerParentId, setBranchPickerParentId] = useState<
string | null
>(null);

const { data, isLoading } = useQuery({
queryKey: PURCHASE_PROCESS_KEY(purchaseId),
Expand Down Expand Up @@ -197,6 +241,11 @@
),
});
setExpandedStepId(null);
const stepChildren = data.steps.filter(
(s) => s.parentStepId === step.id,

Check failure on line 245 in components/process-progress.tsx

View workflow job for this annotation

GitHub Actions / run-tsc-check

Property 'parentStepId' does not exist on type 'PurchaseProcessStep'.
);
if (stepChildren.length === 1) setExpandedStepId(stepChildren[0].id);
else if (stepChildren.length > 1) setBranchPickerParentId(step.id);
},
},
);
Expand All @@ -221,6 +270,7 @@
s.id === stepId ? { ...s, completion: null } : s,
),
});
setBranchPickerParentId(null);
},
});
void result;
Expand Down Expand Up @@ -325,6 +375,18 @@
/>
</div>
)}
{branchPickerParentId === step.id && (
<BranchPicker
children={data.steps.filter(

Check failure on line 380 in components/process-progress.tsx

View workflow job for this annotation

GitHub Actions / run-linting-check

Do not pass children as props. Instead, nest children between the opening and closing tags
(s) => s.parentStepId === step.id,

Check failure on line 381 in components/process-progress.tsx

View workflow job for this annotation

GitHub Actions / run-tsc-check

Property 'parentStepId' does not exist on type 'PurchaseProcessStep'.
)}
onPick={(child) => {
setBranchPickerParentId(null);
setExpandedStepId(child.id);
}}
onDismiss={() => setBranchPickerParentId(null)}
/>
)}
</div>
);
})}
Expand Down
Loading