Skip to content

Commit 17b24ff

Browse files
author
jakub-przepiora
committed
feat: step 3 drag & drop reordering for production steps
1 parent 5486ac5 commit 17b24ff

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

backend/resources/views/onboarding/step3-process-template.blade.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@
55
<p class="text-gray-600 mb-6">A process template defines the production steps (recipe) for your product. Add each step in the order they happen during production.</p>
66

77
<form method="POST" action="{{ route('onboarding.step3') }}" x-data="{
8-
steps: [{ name: '', estimated_duration_minutes: '' }],
9-
addStep() { this.steps.push({ name: '', estimated_duration_minutes: '' }) },
10-
removeStep(i) { if (this.steps.length > 1) this.steps.splice(i, 1) }
8+
steps: [{ name: '', estimated_duration_minutes: '', id: Date.now() }],
9+
dragIndex: null,
10+
dragOverIndex: null,
11+
addStep() { this.steps.push({ name: '', estimated_duration_minutes: '', id: Date.now() + Math.random() }) },
12+
removeStep(i) { if (this.steps.length > 1) this.steps.splice(i, 1) },
13+
dragStart(i) { this.dragIndex = i },
14+
dragOver(i) { this.dragOverIndex = i },
15+
drop(i) {
16+
if (this.dragIndex === null || this.dragIndex === i) { this.dragIndex = null; this.dragOverIndex = null; return; }
17+
const item = this.steps.splice(this.dragIndex, 1)[0];
18+
this.steps.splice(i, 0, item);
19+
this.dragIndex = null;
20+
this.dragOverIndex = null;
21+
},
22+
dragEnd() { this.dragIndex = null; this.dragOverIndex = null; }
1123
}">
1224
@csrf
1325
<div class="space-y-5">
@@ -20,23 +32,37 @@ class="w-full rounded-lg border border-gray-300 px-4 py-2.5 text-gray-900 placeh
2032

2133
<div>
2234
<label class="block text-sm font-medium text-gray-700 mb-1">Production Steps <span class="text-red-500">*</span></label>
23-
<p class="text-xs text-gray-500 mb-3">Add each production step in order. For each step, enter a name and optionally how long it takes (in minutes).</p>
35+
<p class="text-xs text-gray-500 mb-3">Add steps in order. Drag the handle to reorder.</p>
2436
@error('steps') <p class="mb-2 text-sm text-red-600">{{ $message }}</p> @enderror
2537

2638
{{-- Column headers --}}
2739
<div class="flex gap-2 mb-2 text-xs font-medium text-gray-500 uppercase tracking-wider">
28-
<span class="w-6"></span>
40+
<span class="w-10"></span>
2941
<span class="flex-1">Step Name</span>
3042
<span class="w-28 text-center">Duration (min)</span>
3143
<span class="w-8"></span>
3244
</div>
3345

34-
<template x-for="(step, index) in steps" :key="index">
35-
<div class="flex gap-2 mb-2 items-center">
36-
<span class="flex items-center justify-center text-sm text-gray-400 w-6 font-medium" x-text="index + 1 + '.'"></span>
46+
<template x-for="(step, index) in steps" :key="step.id">
47+
<div class="flex gap-2 mb-2 items-center rounded-lg transition-all"
48+
:class="{
49+
'bg-blue-50 border border-blue-200 border-dashed': dragOverIndex === index && dragIndex !== index,
50+
'opacity-50': dragIndex === index
51+
}"
52+
draggable="true"
53+
@dragstart="dragStart(index)"
54+
@dragover.prevent="dragOver(index)"
55+
@drop.prevent="drop(index)"
56+
@dragend="dragEnd()">
57+
{{-- Drag handle --}}
58+
<span class="flex items-center justify-center w-10 cursor-grab active:cursor-grabbing text-gray-300 hover:text-gray-500 select-none" title="Drag to reorder">
59+
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
60+
<path d="M7 2a2 2 0 10.001 4.001A2 2 0 007 2zm0 6a2 2 0 10.001 4.001A2 2 0 007 8zm0 6a2 2 0 10.001 4.001A2 2 0 007 14zm6-8a2 2 0 10-.001-4.001A2 2 0 0013 6zm0 2a2 2 0 10.001 4.001A2 2 0 0013 8zm0 6a2 2 0 10.001 4.001A2 2 0 0013 14z"/>
61+
</svg>
62+
</span>
3763
<input type="text" :name="'steps[' + index + '][name]'" x-model="step.name" required
3864
class="flex-1 rounded-lg border border-gray-300 px-4 py-2.5 text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 outline-none transition"
39-
placeholder="e.g. Assembly, Injection, Packaging...">
65+
:placeholder="'Step ' + (index + 1) + ' (e.g. Assembly, Packaging...)'">
4066
<input type="number" :name="'steps[' + index + '][estimated_duration_minutes]'" x-model="step.estimated_duration_minutes"
4167
class="w-28 rounded-lg border border-gray-300 px-3 py-2.5 text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 outline-none transition text-center"
4268
placeholder="min" min="0">

0 commit comments

Comments
 (0)