diff --git a/apps/web/src/components/activities/ActivityPostponeSheet.vue b/apps/web/src/components/activities/ActivityPostponeSheet.vue index 00821da..df578f0 100644 --- a/apps/web/src/components/activities/ActivityPostponeSheet.vue +++ b/apps/web/src/components/activities/ActivityPostponeSheet.vue @@ -8,7 +8,7 @@ import { import UiIcon from '@/components/UiIcon.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue'; -type PostponeKey = 'm15' | 'm30' | 'h1' | 'tomorrow-am' | 'tomorrow-pm' | 'custom'; +type PostponeKey = 'h1' | 'tomorrow-am' | 'next-saturday' | 'next-week' | 'custom'; const props = defineProps<{ dueAt?: string | null; @@ -21,7 +21,7 @@ const emit = defineEmits<{ }>(); const nowTick = ref(Date.now()); -const selected = ref(null); +const customOpen = ref(false); const customLocal = ref(''); let tickTimer: number | null = null; @@ -43,47 +43,50 @@ function tomorrowAt(hour: number, minute = 0) { return d; } +/** شنبهٔ بعد، ساعت ۱۰. اگر امروز شنبه باشد، شنبهٔ هفتهٔ بعد. */ +function nextSaturdayMorning() { + const d = startOfLocalDay(new Date(nowTick.value)); + const untilSaturday = (6 - d.getDay() + 7) % 7; + d.setDate(d.getDate() + (untilSaturday === 0 ? 7 : untilSaturday)); + d.setHours(10, 0, 0, 0); + return d; +} + +function nextWeekSameTime() { + const d = new Date(base.value.getTime()); + d.setDate(d.getDate() + 7); + return d; +} + const options = computed(() => { - const m15 = addMinutes(15); - const m30 = addMinutes(30); const h1 = addMinutes(60); const am = tomorrowAt(10); - const pm = tomorrowAt(13); + const saturday = nextSaturdayMorning(); + const week = nextWeekSameTime(); return [ - { - key: 'm15' as const, - icon: 'refresh' as const, - label: 'یک ربع دیرتر', - time: formatClockFa(m15), - at: m15, - }, - { - key: 'm30' as const, - icon: 'refresh' as const, - label: 'نیم ساعت دیرتر', - time: formatClockFa(m30), - at: m30, - }, { key: 'h1' as const, - icon: 'refresh' as const, label: 'یک ساعت دیرتر', time: formatClockFa(h1), at: h1, }, { key: 'tomorrow-am' as const, - icon: 'calendar-sun' as const, label: 'فردا صبح', - time: `فردا ${formatClockFa(am)}`, + time: formatClockFa(am), at: am, }, { - key: 'tomorrow-pm' as const, - icon: 'calendar-sun' as const, - label: 'فردا بعد از ظهر', - time: `فردا ${formatClockFa(pm)}`, - at: pm, + key: 'next-saturday' as const, + label: 'شنبه آینده', + time: formatJalaliDayClock(saturday), + at: saturday, + }, + { + key: 'next-week' as const, + label: 'هفته آینده', + time: formatJalaliDayClock(week), + at: week, }, ]; }); @@ -100,31 +103,27 @@ const customDate = computed(() => { }); const customPreview = computed(() => - customDate.value ? formatJalaliDayClock(customDate.value) : 'تاریخ و ساعت را انتخاب کنید', + customDate.value ? formatJalaliDayClock(customDate.value) : '', ); -const canSubmit = computed(() => { - if (props.saving || !selected.value) return false; - if (selected.value === 'custom') return Boolean(customDate.value); - return true; -}); - -function chosenDate(): Date | null { - if (selected.value === 'custom') return customDate.value; - return options.value.find((item) => item.key === selected.value)?.at ?? null; +function apply(at: Date) { + if (props.saving) return; + emit('submit', at.toISOString()); } function pick(key: PostponeKey) { - selected.value = key; - if (key === 'custom' && !customLocal.value) { - customLocal.value = toLocalInput(addMinutes(60)); + if (key === 'custom') { + customOpen.value = true; + if (!customLocal.value) customLocal.value = toLocalInput(addMinutes(60)); + return; } + const at = options.value.find((item) => item.key === key)?.at; + if (at) apply(at); } -function submit() { - const at = chosenDate(); - if (!at || props.saving) return; - emit('submit', at.toISOString()); +function submitCustom() { + if (!customDate.value || props.saving) return; + apply(customDate.value); } function close() { @@ -156,73 +155,57 @@ onBeforeUnmount(() => {