fix: scope create form priorities to selected group; reset on group change
This commit is contained in:
@@ -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'))
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user