feat(reminders): add allowAbsolute prop to ReminderDetail
Adds an allowAbsolute prop to ReminderDetail that hides the 'Date and time' option when set to false, and a lockRelativeTo prop on ReminderPeriod that hides the relativeTo select and forces the chosen value. ReminderDetail threads them together so that when absolute reminders are disallowed, the Custom form can only produce reminders that anchor to defaultRelativeTo.
This commit is contained in:
parent
e85f3fd84c
commit
b61ad9d46a
|
|
@ -36,6 +36,7 @@
|
|||
{{ $t('task.reminder.custom') }}
|
||||
</SimpleButton>
|
||||
<SimpleButton
|
||||
v-if="allowAbsolute"
|
||||
class="option-button"
|
||||
:class="{'currently-active': modelValue?.relativeTo === null}"
|
||||
@click="showFormSwitch = 'absolute'"
|
||||
|
|
@ -47,6 +48,7 @@
|
|||
<ReminderPeriod
|
||||
v-if="activeForm === 'relative'"
|
||||
v-model="reminder"
|
||||
:lock-relative-to="lockedRelativeTo"
|
||||
/>
|
||||
|
||||
<DatepickerInline
|
||||
|
|
@ -91,10 +93,12 @@ const props = withDefaults(defineProps<{
|
|||
modelValue?: ITaskReminder,
|
||||
clearAfterUpdate?: boolean,
|
||||
defaultRelativeTo?: IReminderPeriodRelativeTo | null,
|
||||
allowAbsolute?: boolean,
|
||||
}>(), {
|
||||
modelValue: () => new TaskReminderModel() as ITaskReminder,
|
||||
clearAfterUpdate: false,
|
||||
defaultRelativeTo: REMINDER_PERIOD_RELATIVE_TO_TYPES.DUEDATE,
|
||||
allowAbsolute: true,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
|
@ -118,13 +122,20 @@ const reminderDate = ref<Date | null>(null)
|
|||
const showFormSwitch = ref<null | 'relative' | 'absolute'>(null)
|
||||
|
||||
const activeForm = computed(() => {
|
||||
if (props.defaultRelativeTo === null) {
|
||||
if (props.defaultRelativeTo === null && props.allowAbsolute) {
|
||||
return 'absolute'
|
||||
}
|
||||
|
||||
return showFormSwitch.value
|
||||
})
|
||||
|
||||
const lockedRelativeTo = computed(() => {
|
||||
if (props.allowAbsolute) {
|
||||
return null
|
||||
}
|
||||
return props.defaultRelativeTo
|
||||
})
|
||||
|
||||
const reminderText = computed(() => {
|
||||
if (reminder.value.relativeTo !== null) {
|
||||
return formatReminder(reminder.value)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<div class="select">
|
||||
<div
|
||||
v-if="lockRelativeTo === null"
|
||||
class="select"
|
||||
>
|
||||
<select
|
||||
v-model="period.relativeTo"
|
||||
@change="updateData"
|
||||
|
|
@ -73,9 +76,12 @@ import TaskReminderModel from '@/models/taskReminder'
|
|||
import type {ITaskReminder} from '@/modelTypes/ITaskReminder'
|
||||
import {type IReminderPeriodRelativeTo, REMINDER_PERIOD_RELATIVE_TO_TYPES} from '@/types/IReminderPeriodRelativeTo'
|
||||
|
||||
const props = defineProps<{
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue: ITaskReminder,
|
||||
}>()
|
||||
lockRelativeTo?: IReminderPeriodRelativeTo | null,
|
||||
}>(), {
|
||||
lockRelativeTo: null,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [ITaskReminder]
|
||||
|
|
@ -103,7 +109,7 @@ watch(
|
|||
const p = secondsToPeriod(value?.relativePeriod)
|
||||
period.value.durationUnit = p.unit
|
||||
period.value.duration = Math.abs(p.amount)
|
||||
period.value.relativeTo = value?.relativeTo || REMINDER_PERIOD_RELATIVE_TO_TYPES.DUEDATE
|
||||
period.value.relativeTo = props.lockRelativeTo ?? value?.relativeTo ?? REMINDER_PERIOD_RELATIVE_TO_TYPES.DUEDATE
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue