feat: add shift management functionality

This commit is contained in:
2026-08-26 18:53:15 +03:30
parent 2d96978c38
commit aeef95339d
34 changed files with 1953 additions and 15 deletions
@@ -0,0 +1,96 @@
<script setup>
import { computed, ref } from 'vue';
import FullCalendar from '@fullcalendar/vue3';
import timeGridPlugin from '@fullcalendar/timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import faLocale from '@fullcalendar/core/locales/fa';
import UiButton from '../../ui/UiButton.vue';
import { buildShiftEvent, formatJalaliDay, formatJalaliRange } from '../../../../Shared/shiftCalendarEvents';
const props = defineProps({
myShifts: {
type: Array,
required: true
},
openShifts: {
type: Array,
required: true
}
})
const emit = defineEmits(['select-shift']);
const calendarRef = ref(null);
const viewTitle = ref('');
const events = computed(() => [
...props.myShifts.map((shift) => buildShiftEvent(shift, {
title: 'شیفت من',
classNames: [shift.is_active ? 'shift-event--mine' : 'shift-event--mine-inactive'],
})),
...props.openShifts.map((shift) => buildShiftEvent(shift, {
title: 'شیفت آزاد',
classNames: ['shift-event--open'],
})),
])
const calendarOptions = computed(() => ({
plugins: [timeGridPlugin, interactionPlugin],
initialView: 'timeGridWeek',
locale: faLocale,
direction: 'rtl',
firstDay: 6,
headerToolbar: false,
allDaySlot: false,
height: 'auto',
nowIndicator: true,
slotLabelFormat: { hour: '2-digit', minute: '2-digit', hour12: false },
eventTimeFormat: { hour: '2-digit', minute: '2-digit', hour12: false },
dayHeaderContent: (args) => ({
html: `${args.text}<span class="shift-calendar-day-date">${formatJalaliDay(args.date)}</span>`
}),
datesSet: (info) => {
viewTitle.value = formatJalaliRange(info.start, info.end);
},
events: events.value,
eventClick: (info) => {
emit('select-shift', info.event.extendedProps.shift);
},
}))
const goPrev = () => calendarRef.value?.getApi().prev();
const goNext = () => calendarRef.value?.getApi().next();
const goToday = () => calendarRef.value?.getApi().today();
</script>
<template>
<div class="shift-calendar">
<div class="flex flex-wrap items-center justify-between gap-3 pb-4">
<div class="flex items-center gap-2">
<UiButton label="امروز" size="small" outlined @click="goToday" />
<button type="button" class="w-8 h-8 flex items-center justify-center rounded-lg border border-[#DEE3EB] text-[#576989] cursor-pointer" @click="goPrev">
<i class="fi fi-rr-angle-small-right flex text-sm"></i>
</button>
<button type="button" class="w-8 h-8 flex items-center justify-center rounded-lg border border-[#DEE3EB] text-[#576989] cursor-pointer" @click="goNext">
<i class="fi fi-rr-angle-small-left flex text-sm"></i>
</button>
<span class="text-[12px] font-[600] text-[#3E4C63]">{{ viewTitle }}</span>
</div>
<ul class="flex items-center gap-4">
<li class="flex items-center gap-1.5">
<span class="w-3 h-3 rounded bg-[#576989]"></span>
<span class="text-[11px] font-[600] text-[#3E4C63]">شیفت من</span>
</li>
<li class="flex items-center gap-1.5">
<span class="w-3 h-3 rounded border border-dashed border-[#7188AD] bg-[#F6F7F9]"></span>
<span class="text-[11px] font-[600] text-[#3E4C63]">شیفت آزاد</span>
</li>
<li class="flex items-center gap-1.5">
<span class="w-3 h-3 rounded bg-[#C8D2E2]"></span>
<span class="text-[11px] font-[600] text-[#3E4C63]">غیرفعال</span>
</li>
</ul>
</div>
<FullCalendar ref="calendarRef" :options="calendarOptions" />
</div>
</template>