feat: Add ability to schedule notifications (#10789)

* feat: Add ability to schedule notifications

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Add docker file

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Rename pod

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Add debug logging

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Reminder fixes

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Fix reminders

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Support reminders for all events

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Support for project todo

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Fix mismatched dependency

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Use base event class

Signed-off-by: Artem Savchenko <armisav@gmail.com>

---------

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artyom Savchenko
2026-07-06 11:30:21 +05:00
committed by GitHub
parent 184b4ec08f
commit dfe7d3d17c
40 changed files with 2157 additions and 57 deletions
+1
View File
@@ -257,6 +257,7 @@ const calendarPlugin = plugin(calendarId, {
PersonsLabel: '' as IntlString,
EventNumber: '' as IntlString,
Reminders: '' as IntlString,
Reminder: '' as IntlString,
Today: '' as IntlString,
Visibility: '' as IntlString,
Public: '' as IntlString,
@@ -15,7 +15,7 @@
<script lang="ts">
import { Analytics } from '@hcengineering/analytics'
import { AccessLevel, Calendar, generateEventId } from '@hcengineering/calendar'
import { VisibilityEditor } from '@hcengineering/calendar-resources'
import { EventReminders, VisibilityEditor } from '@hcengineering/calendar-resources'
import calendar from '@hcengineering/calendar-resources/src/plugin'
import { getCurrentEmployee } from '@hcengineering/contact'
import core, { AttachedData, Doc, Ref, SortingOrder, generateId, getCurrentAccount } from '@hcengineering/core'
@@ -104,7 +104,7 @@
allDay: false,
access: AccessLevel.Owner,
visibility: todo.visibility === 'public' ? 'public' : 'freeBusy',
reminders: [],
reminders,
user: myAccount.primarySocialId
})
Analytics.handleEvent(TimeEvents.ToDoScheduled, { id })
@@ -126,6 +126,7 @@
})
let slots: WorkSlot[] = []
let reminders: number[] = []
function removeSlot (e: CustomEvent<{ _id: Ref<WorkSlot> }>): void {
const index = slots.findIndex((p) => p._id === e.detail._id)
@@ -151,7 +152,7 @@
blockTime: true,
access: AccessLevel.Owner,
visibility: todo.visibility,
reminders: [],
reminders,
calendar: _calendar,
space: calendar.space.Calendar,
_id: generateId(),
@@ -267,6 +268,9 @@
on:change={changeSlot}
on:dueChange={changeDueSlot}
/>
{#if slots.length > 0}
<EventReminders bind:reminders />
{/if}
</div>
<div class="flex-row-reverse btn flex-no-shrink">
<Button
@@ -13,7 +13,8 @@
// limitations under the License.
-->
<script lang="ts">
import calendar, { AccessLevel, Calendar, generateEventId } from '@hcengineering/calendar'
import calendar, { AccessLevel, generateEventId } from '@hcengineering/calendar'
import { EventReminders } from '@hcengineering/calendar-resources'
import contact, { getCurrentEmployee } from '@hcengineering/contact'
import { Ref, getCurrentAccount } from '@hcengineering/core'
import { createQuery, getClient } from '@hcengineering/presentation'
@@ -31,11 +32,39 @@
const query = createQuery()
let slots: WorkSlot[] = []
let reminders: number[] = []
let remindersHydrated = false
let remindersKey = ''
let currentTodoId: Ref<ToDo> | undefined
$: if (todo?._id !== undefined && currentTodoId !== todo._id) {
currentTodoId = todo._id
remindersHydrated = false
reminders = []
remindersKey = ''
}
$: query.query(time.class.WorkSlot, { attachedTo: todo._id }, (res) => {
slots = res
if (!remindersHydrated) {
reminders = [...(slots[0]?.reminders ?? [])]
remindersHydrated = true
remindersKey = JSON.stringify(reminders)
}
})
$: {
if (!remindersHydrated || slots.length === 0) {
// no-op
} else {
const nextKey = JSON.stringify(reminders)
if (nextKey !== remindersKey) {
remindersKey = nextKey
void syncRemindersForSlots()
}
}
}
async function change (e: CustomEvent<{ startDate: number, dueDate: number, slot: Ref<WorkSlot> }>): Promise<void> {
const { startDate, dueDate, slot } = e.detail
const workslot = slots.find((s) => s._id === slot)
@@ -72,14 +101,22 @@
access: AccessLevel.Owner,
user: currentAccount.primarySocialId,
visibility: todo.visibility === 'public' ? 'public' : 'freeBusy',
reminders: []
reminders
})
Analytics.handleEvent(TimeEvents.ToDoScheduled, { id: todo._id })
}
async function syncRemindersForSlots (): Promise<void> {
await Promise.all(
slots.map(async (slot) => {
await client.update(slot, { reminders })
})
)
}
async function remove (e: CustomEvent<{ _id: Ref<WorkSlot> }>): Promise<void> {
const object = slots.find((p) => p._id === e.detail._id)
if (object) {
if (object !== undefined) {
showPopup(
contact.component.DeleteConfirmationPopup,
{
@@ -98,4 +135,11 @@
}
</script>
<Workslots {slots} fixed={'toDo'} on:change={change} on:dueChange={dueChange} on:create={create} on:remove={remove} />
<div class="flex-col">
<Workslots {slots} fixed={'toDo'} on:change={change} on:dueChange={dueChange} on:create={create} on:remove={remove} />
{#if slots.length > 0}
<div class="flex pt-4">
<EventReminders bind:reminders />
</div>
{/if}
</div>