feat: add useShiftDetailStore for shift detail panel state
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
53
apps/app/src/stores/useShiftDetailStore.ts
Normal file
53
apps/app/src/stores/useShiftDetailStore.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { ShiftAssignment } from '@/types/shiftAssignment'
|
||||
import { ShiftAssignmentStatus } from '@/types/shiftAssignment'
|
||||
|
||||
export const useShiftDetailStore = defineStore('shiftDetail', () => {
|
||||
const isOpen = ref(false)
|
||||
const selectedShiftId = ref<string | null>(null)
|
||||
const selectedSectionId = ref<string | null>(null)
|
||||
const selectedAssignmentIds = ref<string[]>([])
|
||||
|
||||
function openPanel(shiftId: string, sectionId: string) {
|
||||
selectedShiftId.value = shiftId
|
||||
selectedSectionId.value = sectionId
|
||||
selectedAssignmentIds.value = []
|
||||
isOpen.value = true
|
||||
}
|
||||
|
||||
function closePanel() {
|
||||
isOpen.value = false
|
||||
selectedShiftId.value = null
|
||||
selectedSectionId.value = null
|
||||
selectedAssignmentIds.value = []
|
||||
}
|
||||
|
||||
function toggleAssignmentSelection(id: string) {
|
||||
const idx = selectedAssignmentIds.value.indexOf(id)
|
||||
if (idx === -1) selectedAssignmentIds.value.push(id)
|
||||
else selectedAssignmentIds.value.splice(idx, 1)
|
||||
}
|
||||
|
||||
function selectAllPending(assignments: ShiftAssignment[]) {
|
||||
selectedAssignmentIds.value = assignments
|
||||
.filter(a => a.status === ShiftAssignmentStatus.PENDING_APPROVAL)
|
||||
.map(a => a.id)
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedAssignmentIds.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
isOpen,
|
||||
selectedShiftId,
|
||||
selectedSectionId,
|
||||
selectedAssignmentIds,
|
||||
openPanel,
|
||||
closePanel,
|
||||
toggleAssignmentSelection,
|
||||
selectAllPending,
|
||||
clearSelection,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user