feat(web): add next Saturday and next week to postpone

Saturday is the start of the work week, so the sheet can defer a task to next Saturday morning or the same time one week later.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-01 21:20:15 +03:30
co-authored by Cursor
parent 81edf61065
commit d5dd13863a
@@ -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<PostponeKey | null>(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(() => {
<template>
<Teleport to="body">
<div class="layer" role="presentation">
<div class="backdrop" aria-hidden="true" />
<button class="backdrop" type="button" aria-label="بستن" @click="close" />
<section class="sheet" role="dialog" aria-modal="true" aria-labelledby="postpone-title">
<div class="handle" aria-hidden="true" />
<header class="head">
<button class="icon" type="button" aria-label="تأیید تعویق" :disabled="!canSubmit" @click="submit">
<UiIcon name="check-plain" :size="22" />
</button>
<div class="titles">
<h2 id="postpone-title">به تعویق انداختن فعالیت</h2>
</div>
<h2 id="postpone-title">به تعویق انداختن</h2>
<button class="icon" type="button" aria-label="بستن" @click="close">
<UiIcon name="x" :size="20" />
</button>
</header>
<p class="lead">زمان جدید برای این فعالیت را انتخاب کنید.</p>
<div class="body">
<div class="presets">
<button
v-for="item in options"
:key="item.key"
class="card"
type="button"
:class="{ on: selected === item.key }"
:disabled="saving"
@click="pick(item.key)"
>
<span class="label">{{ item.label }}</span>
<span class="aside">
<span class="ico-box">
<UiIcon :name="item.icon" :size="20" />
</span>
<span class="when">{{ item.time }}</span>
</span>
</button>
</div>
<button
class="card custom"
type="button"
:class="{ on: selected === 'custom' }"
:class="{ on: customOpen }"
:disabled="saving"
@click="pick('custom')"
>
<span class="copy">
<strong>تنظیم زمان دلخواه</strong>
<small>انتخاب تاریخ و ساعت</small>
</span>
<span class="aside">
<span class="ico-box">
<UiIcon name="calendar-edit" :size="20" />
</span>
</span>
<span class="label">زمان دلخواه</span>
<span class="when">{{ customOpen && customPreview ? customPreview : 'تاریخ و ساعت' }}</span>
</button>
<div v-if="selected === 'custom'" class="custom-box">
<div v-if="customOpen" class="custom-box">
<label class="picker">
<span>تاریخ و ساعت جدید</span>
<JalaliDateInput v-model="customLocal" mode="datetime" />
</label>
<p class="preview">{{ customPreview }}</p>
<button
class="confirm"
type="button"
:disabled="saving || !customDate"
@click="submitCustom"
>
{{ saving ? 'در حال ثبت…' : 'ثبت تعویق' }}
</button>
</div>
<p class="notice">
<UiIcon name="lightbulb" :size="18" />
با تعویق انداختن، این فعالیت در زمان جدید به لیست فعالیت‌های شما منتقل می‌شود.
</p>
</div>
</section>
</div>
@@ -236,20 +219,27 @@ onBeforeUnmount(() => {
z-index: 90;
display: flex;
justify-content: center;
align-items: stretch;
align-items: flex-end;
}
.backdrop {
display: none;
position: absolute;
inset: 0;
border: 0;
background: rgba(15, 23, 42, 0.28);
cursor: pointer;
}
.sheet {
position: relative;
width: 100%;
height: 100dvh;
max-height: 92dvh;
background: #fff;
display: flex;
flex-direction: column;
font-family: IRANSans, Tahoma, sans-serif;
border-radius: 16px 16px 0 0;
box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.12);
}
.handle {
@@ -261,75 +251,65 @@ onBeforeUnmount(() => {
}
.head {
display: grid;
grid-template-columns: 40px 1fr 40px;
display: flex;
align-items: center;
padding: 0.1rem 0.7rem 0.15rem;
justify-content: space-between;
gap: 0.5rem;
padding: 0.15rem 0.85rem 0.35rem;
}
.titles h2,
.lead {
.head h2 {
margin: 0;
text-align: center;
}
.titles h2 {
font-size: 16px;
font-weight: 500;
font-weight: 600;
color: #0f172a;
}
.lead {
color: #94a3b8;
font-size: 0.82rem;
padding: 0 1.2rem 0.55rem;
}
.icon {
width: 40px;
height: 40px;
width: 36px;
height: 36px;
border: 0;
background: none;
color: #0f766e;
color: #64748b;
display: grid;
place-items: center;
cursor: pointer;
}
.icon:disabled {
opacity: 0.35;
cursor: not-allowed;
.body {
overflow: auto;
padding: 0.35rem 1rem calc(1rem + env(safe-area-inset-bottom));
display: grid;
gap: 0.55rem;
}
.body {
flex: 1;
overflow: auto;
padding: 0.15rem 1rem calc(1rem + env(safe-area-inset-bottom));
.presets {
display: grid;
align-content: start;
grid-template-columns: 1fr 1fr;
gap: 0.55rem;
}
.card {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.8rem;
min-height: 72px;
padding: 0.7rem 0.9rem;
flex-direction: column;
align-items: flex-start;
justify-content: center;
gap: 0.2rem;
min-height: 64px;
padding: 0.7rem 0.85rem;
border: 1px solid #e8eef3;
border-radius: var(--radius);
border-radius: var(--radius, 10px);
background: #fff;
font: inherit;
text-align: start;
cursor: pointer;
}
.card.on {
.card.on,
.card:hover:not(:disabled) {
border-color: #99f6e4;
background: #f0fdfa;
box-shadow: 0 0 0 1px #99f6e4;
}
.card:disabled {
@@ -337,54 +317,27 @@ onBeforeUnmount(() => {
cursor: not-allowed;
}
.label,
.copy strong {
font-size: 0.95rem;
font-weight: 600;
.label {
font-size: 0.92rem;
font-weight: 700;
color: #0f172a;
}
.copy {
display: grid;
gap: 0.15rem;
}
.copy small {
color: #94a3b8;
font-size: 0.78rem;
}
.aside {
display: grid;
justify-items: center;
gap: 0.28rem;
min-width: 3.6rem;
flex-shrink: 0;
}
.ico-box {
width: 40px;
height: 40px;
border-radius: var(--radius);
background: #e6f7f4;
color: #0d9488;
display: grid;
place-items: center;
}
.when {
color: #0d9488;
font-size: 0.74rem;
color: #0f766e;
font-size: 0.84rem;
font-weight: 600;
white-space: nowrap;
}
.custom {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.custom-box {
border: 1px solid #e8eef3;
border-radius: var(--radius);
padding: 0.85rem 0.9rem;
display: grid;
gap: 0.55rem;
gap: 0.65rem;
}
.picker {
@@ -394,65 +347,31 @@ onBeforeUnmount(() => {
font-size: 0.8rem;
}
.picker input {
width: 100%;
min-height: var(--control-h);
height: var(--control-h);
border: 1px solid #e2e8f0;
border-radius: var(--radius);
padding: 0.45rem 0.7rem;
.confirm {
border: 0;
background: #0f766e;
color: #fff;
border-radius: var(--radius, 10px);
min-height: 42px;
font: inherit;
color: #0f172a;
background: #fff;
}
.preview {
margin: 0;
color: #0f766e;
font-size: 0.82rem;
font-weight: 700;
cursor: pointer;
}
.notice {
margin: 0.35rem 0 0;
display: flex;
align-items: flex-start;
gap: 0.55rem;
padding: 0.85rem 0.9rem;
border-radius: var(--radius);
background: #f8fafc;
color: #475569;
font-size: 0.8rem;
line-height: 1.75;
}
.notice :deep(.ico) {
margin-top: 0.15rem;
color: #0d9488;
flex-shrink: 0;
.confirm:disabled {
opacity: 0.55;
cursor: not-allowed;
}
@media (min-width: 900px) {
.layer {
background: rgba(15, 23, 42, 0.28);
align-items: center;
padding: 1.2rem;
}
.backdrop {
display: block;
position: absolute;
inset: 0;
border: 0;
background: transparent;
cursor: pointer;
}
.sheet {
position: relative;
max-width: 480px;
height: min(92dvh, 860px);
border-radius: var(--radius, 10px);
max-width: 420px;
border-radius: 16px;
box-shadow: 0 28px 70px rgba(15, 23, 42, 0.22);
}
}