fix: scope create form priorities to selected group; reset on group change

This commit is contained in:
Joel Wedemire
2026-04-08 19:06:38 -07:00
parent 652829ab90
commit f2b614abb7
2 changed files with 14 additions and 2 deletions

View File

@@ -91,7 +91,7 @@
</template>
<script setup>
import { computed } from 'vue'
import { computed, watch } from 'vue'
import { Link, useForm } from '@inertiajs/vue3'
const props = defineProps({
@@ -113,6 +113,14 @@ const filteredPriorities = computed(() => {
return props.priorities.filter(p => !p.group_id || p.group_id === Number(form.group_id))
})
// Reset priority if it's no longer valid for the newly selected group
watch(() => form.group_id, () => {
const valid = filteredPriorities.value.some(p => p.id === form.priority_id)
if (!valid) {
form.priority_id = null
}
})
function submit() {
form.post(route('ticketing.store'))
}

View File

@@ -245,7 +245,11 @@ class TicketController extends Controller
]);
}
$priorities = PriorityLevel::orderBy('sort_order')->get();
// Only pass global priorities + priorities scoped to accessible groups
$groupIds = $groups->pluck('id')->toArray();
$priorities = PriorityLevel::where(fn($q) => $q->whereNull('group_id')->orWhereIn('group_id', $groupIds))
->orderBy('sort_order')
->get();
return Inertia::render('Ticketing/Create', [
'groups' => $groups,