@jsb188/mday 1.1.8 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +105 -35
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +48 -0
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +44 -0
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +7 -366
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -11
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +168 -0
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +61 -0
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1017 -738
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +57 -316
- package/src/schemas/organization.ts +53 -213
- package/src/types/account.d.ts +81 -0
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +366 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +142 -0
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +57 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +169 -190
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +175 -76
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +1130 -0
- package/src/types/storage.d.ts +242 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +305 -0
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +849 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +172 -0
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +173 -778
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +683 -81
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4973 -0
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/workflow.ts +380 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -209
- package/src/constants/product.ts +0 -66
- package/src/constants/report.ts +0 -25
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -145
- package/src/schemas/reportsQuery.ts +0 -107
- package/src/types/action.d.ts +0 -42
- package/src/types/product.d.ts +0 -173
- package/src/types/report.d.ts +0 -203
- package/src/utils/product-calEvent.ts +0 -508
- package/src/utils/route-helpers.ts +0 -583
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import type { AddressObj, ScheduleObj } from '@jsb188/app/types/other.d';
|
|
3
|
-
import { getFullDate } from '@jsb188/app/utils/datetime';
|
|
4
|
-
import { convertToMilitaryTime } from '@jsb188/app/utils/number';
|
|
5
|
-
import { DEFAULT_TIMEZONE, formatCalDateInTimeZone, getDayOfWeekInTimeZone, hhmmFromDateOrTime, parseBoundaryDateInTimezone } from '@jsb188/app/utils/timeZone';
|
|
6
|
-
import { DateTime } from 'luxon';
|
|
7
|
-
import type { ProductAttendanceData, ProductCalEventData, ProductCalEventGQL } from '../types/product.d';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get the address in a single line text format
|
|
11
|
-
* @param address - Address data object
|
|
12
|
-
* @param multiline - Whether to format in multiple lines
|
|
13
|
-
* @returns Address in a single line text format
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export function getAddressText(
|
|
17
|
-
address: AddressObj | null,
|
|
18
|
-
multiline = false,
|
|
19
|
-
): string {
|
|
20
|
-
if (!address) {
|
|
21
|
-
return i18n.t('form.not_specified');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const { line1, line2, city, state, postalCode, country } = address;
|
|
25
|
-
if (multiline) {
|
|
26
|
-
return [
|
|
27
|
-
[line1, line2].filter(Boolean).join(', '),
|
|
28
|
-
[city, state, postalCode, country].filter(Boolean).join(', '),
|
|
29
|
-
].filter(Boolean).join('\n');
|
|
30
|
-
}
|
|
31
|
-
return [line1, line2, city, state, postalCode, country].filter(Boolean).join(', ');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Check if organization event is upcoming
|
|
36
|
-
* Upcoming is defined by: "recurring and not ended" or "date is in the future"
|
|
37
|
-
* @param eventProduct - Calendar Event product GQL data
|
|
38
|
-
* @returns boolean value to indicate if event is upcoming
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
export function checkIfEventIsUpcoming(eventDetails: ProductCalEventGQL): boolean {
|
|
42
|
-
const now = new Date();
|
|
43
|
-
|
|
44
|
-
const once = !eventDetails.schedule?.frequency || eventDetails.schedule.frequency === 'ONCE';
|
|
45
|
-
if (once) {
|
|
46
|
-
const startAt = new Date(eventDetails.startAt);
|
|
47
|
-
return startAt > now;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// End date only applies to recurring events
|
|
51
|
-
const endAt = eventDetails.endAt ? new Date(eventDetails.endAt) : null;
|
|
52
|
-
const finished = endAt && (endAt < now);
|
|
53
|
-
if (finished) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// If it's not "once" event, then it's recurring until end date, so it will default to true
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get icon for event based on time (finished, upcoming, today, etc)
|
|
63
|
-
* @param startAt - Event start date/time in ISO format
|
|
64
|
-
* @param endAt - Event end date/time in ISO format
|
|
65
|
-
* @param schedule - Event schedule object
|
|
66
|
-
* @param showRecurringSchedule - Whether recurring schedule should be shown
|
|
67
|
-
* @returns Icon name as string
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
export function getEventIconName(
|
|
71
|
-
startAt_: string | Date,
|
|
72
|
-
endAt_: string | Date | null,
|
|
73
|
-
schedule: ScheduleObj | null,
|
|
74
|
-
): string {
|
|
75
|
-
const startAt = new Date(startAt_);
|
|
76
|
-
const endAt = endAt_ ? new Date(endAt_) : null;
|
|
77
|
-
const once = !schedule?.frequency || schedule?.frequency === 'ONCE';
|
|
78
|
-
const isUpcoming = checkIfEventIsUpcoming({ startAt, endAt, schedule } as ProductCalEventGQL);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (isUpcoming && !once) {
|
|
83
|
-
return 'calendar-3'; // Upcoming & not-finished recurring event
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const now = new Date();
|
|
87
|
-
if (startAt < now) {
|
|
88
|
-
return 'calendar-check'; // Finished event
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const startDate = new Date(startAt.getFullYear(), startAt.getMonth(), startAt.getDate());
|
|
92
|
-
const nowDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
93
|
-
|
|
94
|
-
if (startDate.getTime() === nowDate.getTime()) {
|
|
95
|
-
return 'clock-3'; // Today's event
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return 'calendar-3'; // Upcoming one-time event
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get the icon labels for Organization event data
|
|
103
|
-
* @param eventProduct - Calendar Event product GQL data
|
|
104
|
-
* @returns Array of icon label objects with icon name and tooltip text
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
export function getEventLabelIcons(eventDetails: ProductCalEventGQL) {
|
|
108
|
-
const { schedule, address } = eventDetails;
|
|
109
|
-
const addressText = address && getAddressText(address);
|
|
110
|
-
const labelIcons = [];
|
|
111
|
-
|
|
112
|
-
if (addressText) {
|
|
113
|
-
labelIcons.push({
|
|
114
|
-
iconName: 'style-two-pin-marker',
|
|
115
|
-
color: 'darker_2', // should really be "lt" but because the icon is "filled", it looks more like texts written in "lt"
|
|
116
|
-
tooltipText: addressText,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// if (status === 'CANCELED') {
|
|
121
|
-
// labelIcons.push({
|
|
122
|
-
// text: 'Canceled',
|
|
123
|
-
// color: 'red_light',
|
|
124
|
-
// // tooltipText: i18n.t('org.event_canceled'),
|
|
125
|
-
// });
|
|
126
|
-
// }
|
|
127
|
-
|
|
128
|
-
// if (recurring) {
|
|
129
|
-
// labelIcons.push({
|
|
130
|
-
// iconName: 'library-filled',
|
|
131
|
-
// color: 'darker_2', // should really be "lt" but because the icon is "filled", it looks more like texts written in "lt"
|
|
132
|
-
// tooltipText: recurringSchedule || i18n.t('org.no_recurring_schedule'),
|
|
133
|
-
// });
|
|
134
|
-
// } else {
|
|
135
|
-
// labelIcons.push({
|
|
136
|
-
// iconName: 'circle-number-1-filled',
|
|
137
|
-
// color: 'emerald',
|
|
138
|
-
// tooltipText: i18n.t('org.single_event_msg'),
|
|
139
|
-
// });
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
return labelIcons;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get schedule info and icons
|
|
147
|
-
* @param eventDetails - Calendar Event details object
|
|
148
|
-
* @param alwaysFillIcon - Whether to always use filled icons
|
|
149
|
-
* @returns Array of icon label objects with icon name and tooltip text
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
export function getScheduleIcons(eventDetails: ProductCalEventGQL, alwaysFillIcon = false) {
|
|
153
|
-
const { schedule } = eventDetails;
|
|
154
|
-
const once = !schedule?.frequency || schedule.frequency === 'ONCE';
|
|
155
|
-
|
|
156
|
-
if (once) {
|
|
157
|
-
return [{
|
|
158
|
-
iconName: 'circle-number-1-filled',
|
|
159
|
-
color: 'amber',
|
|
160
|
-
tooltipText: i18n.t('org.single_event_msg'),
|
|
161
|
-
}];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const { daysOfWeek } = schedule;
|
|
165
|
-
const [startTime, endTime] = schedule.time || [];
|
|
166
|
-
|
|
167
|
-
const labelIcons = [[0,'S'], [1, 'M'], [2, 'T'], [3, 'W'], [4, 'T'], [5, 'F'], [6, 'S']].map((d) => {
|
|
168
|
-
const [dayInt, dayLetter] = d as [0 | 1 | 2 | 3 | 4 | 5 | 6, string];
|
|
169
|
-
const isScheduled = daysOfWeek?.includes(dayInt);
|
|
170
|
-
|
|
171
|
-
let timeText = '';
|
|
172
|
-
if (startTime) {
|
|
173
|
-
timeText = ` ${convertToMilitaryTime(startTime)}${endTime ? ' - ' + convertToMilitaryTime(endTime) : ''}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
iconName: `circle-letter-${dayLetter.toLowerCase()}${isScheduled || alwaysFillIcon ? '-filled' : ''}`,
|
|
178
|
-
color: !isScheduled ? 'darker_2' : dayLetter === 's' ? 'sky' : 'lime',
|
|
179
|
-
tooltipText: isScheduled ? (i18n.t(`datetime.daysOfWeek.${dayInt}`) + timeText) : undefined,
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return labelIcons;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get next date from schedule
|
|
188
|
-
* @param schedule - Event schedule object
|
|
189
|
-
* @param startAt - Start date/time of when this schedule goes in effect
|
|
190
|
-
* @param timeZone - Time zone string
|
|
191
|
-
* @returns Next date in string format
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
export function getNextDateFromSchedule(
|
|
195
|
-
schedule: ScheduleObj | null,
|
|
196
|
-
startAt: string | Date | null,
|
|
197
|
-
timeZone_: string | null,
|
|
198
|
-
) {
|
|
199
|
-
const timeZone = timeZone_ || DEFAULT_TIMEZONE;
|
|
200
|
-
const once = !schedule?.frequency || schedule.frequency === 'ONCE';
|
|
201
|
-
if (once) {
|
|
202
|
-
let onceDate, onceCalDate;
|
|
203
|
-
if (startAt) {
|
|
204
|
-
const dt = DateTime.fromISO(startAt.toString()).setZone(timeZone);
|
|
205
|
-
onceDate = dt.toJSDate();
|
|
206
|
-
onceCalDate = dt.toFormat('yyyy-MM-dd');
|
|
207
|
-
} else {
|
|
208
|
-
onceDate = null;
|
|
209
|
-
onceCalDate = null;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
date: onceDate,
|
|
214
|
-
calDate: onceCalDate,
|
|
215
|
-
text: getFullDate(startAt, 'DATE_ONLY_SHORT', timeZone),
|
|
216
|
-
numericText: getFullDate(startAt, 'TOMORROW_OR_NUMERIC', timeZone),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Get date in time zone using Luxon package
|
|
221
|
-
let now = DateTime.now().setZone(timeZone).toJSDate();
|
|
222
|
-
if (startAt) {
|
|
223
|
-
const scheduleStartDate = DateTime.fromISO(startAt.toString()).setZone(timeZone).toJSDate();
|
|
224
|
-
// If scheduleStartDate is after "now", use that as the base date
|
|
225
|
-
if (scheduleStartDate > now) {
|
|
226
|
-
now = scheduleStartDate;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const daySchedTime = (schedule.time || []).map(Number);
|
|
231
|
-
// const startTime = (daySchedTime[0] || daySchedTime[0] === 0) && convertToMilitaryTime(daySchedTime[0]);
|
|
232
|
-
const hours = Math.floor((daySchedTime[0] || 0) / 100);
|
|
233
|
-
const minutes = (daySchedTime[0] || 0) % 100;
|
|
234
|
-
const { daysOfWeek } = schedule;
|
|
235
|
-
|
|
236
|
-
let nextDate;
|
|
237
|
-
if (daysOfWeek && daysOfWeek.length > 0) {
|
|
238
|
-
const today = now.getDay();
|
|
239
|
-
|
|
240
|
-
let minDiff = Infinity;
|
|
241
|
-
for (const num of daysOfWeek) {
|
|
242
|
-
if (num < 0 || num > 6) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let diff = (num - today + 7) % 7;
|
|
247
|
-
// if it's today, check the time
|
|
248
|
-
if (diff === 0) {
|
|
249
|
-
const candidate = DateTime.fromJSDate(now).setZone(timeZone)
|
|
250
|
-
.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 })
|
|
251
|
-
.toJSDate();
|
|
252
|
-
|
|
253
|
-
// if the time hasn't passed yet → pick today
|
|
254
|
-
if (candidate > now) {
|
|
255
|
-
minDiff = 0;
|
|
256
|
-
break; // earliest possible, no need to check others
|
|
257
|
-
} else {
|
|
258
|
-
diff = 7; // skip to next week
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (diff < minDiff) {
|
|
263
|
-
minDiff = diff;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (minDiff !== Infinity) {
|
|
268
|
-
nextDate = DateTime.fromJSDate(now).setZone(timeZone)
|
|
269
|
-
.plus({ days: minDiff })
|
|
270
|
-
.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 })
|
|
271
|
-
.toJSDate();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (nextDate) {
|
|
276
|
-
const calDate = DateTime.fromJSDate(nextDate, { zone: timeZone }).toFormat('yyyy-MM-dd');
|
|
277
|
-
return {
|
|
278
|
-
date: nextDate,
|
|
279
|
-
calDate,
|
|
280
|
-
text: getFullDate(nextDate, 'DATE_ONLY_SHORT', timeZone),
|
|
281
|
-
numericText: getFullDate(nextDate, 'TOMORROW_OR_NUMERIC', timeZone),
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
date: null,
|
|
287
|
-
calDate: null,
|
|
288
|
-
numericText: '',
|
|
289
|
-
text: '',
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Check if date is a scheduled date
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
export function isScheduledDate(
|
|
298
|
-
eventDetails: ProductCalEventData['metadata'] | ProductCalEventGQL | null,
|
|
299
|
-
calDateInt_: number | string,
|
|
300
|
-
startAt: string | Date | null,
|
|
301
|
-
endAt: string | Date | null,
|
|
302
|
-
) {
|
|
303
|
-
// @ts-ignore - For server + client usage
|
|
304
|
-
const schedule = (eventDetails?.schedule || eventDetails?.metadata?.schedule || {}) as ScheduleObj;
|
|
305
|
-
const { frequency, daysOfWeek } = schedule;
|
|
306
|
-
const startCalDateInt = startAt ? Number(DateTime.fromJSDate(new Date(startAt)).toFormat('yyyyMMdd')) : 0;
|
|
307
|
-
const endCalDateInt = endAt ? Number(DateTime.fromJSDate(new Date(endAt)).toFormat('yyyyMMdd')) : 0;
|
|
308
|
-
const calDateInt = typeof calDateInt_ === 'string' ? Number(calDateInt_.replace(/-/g, '')) : calDateInt_;
|
|
309
|
-
|
|
310
|
-
if (calDateInt < startCalDateInt || (endCalDateInt && calDateInt > endCalDateInt)) {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
switch (frequency) {
|
|
315
|
-
case 'ONCE':
|
|
316
|
-
return calDateInt == startCalDateInt;
|
|
317
|
-
case 'WEEKLY': {
|
|
318
|
-
const hasWeeklyNth = schedule.weeksOfMonth && schedule.weeksOfMonth.length > 0;
|
|
319
|
-
if (hasWeeklyNth) {
|
|
320
|
-
const dt = DateTime.fromFormat(String(calDateInt), 'yyyyMMdd');
|
|
321
|
-
const weekOfMonth = Math.ceil(dt.day / 7);
|
|
322
|
-
if (!schedule.weeksOfMonth?.includes(weekOfMonth)) {
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Convert yyyyMMdd to day of week (0-6)
|
|
328
|
-
const dateDay = DateTime.fromFormat(String(calDateInt), 'yyyyMMdd').weekday % 7;
|
|
329
|
-
return !!daysOfWeek?.includes(dateDay as any);
|
|
330
|
-
}
|
|
331
|
-
default:
|
|
332
|
-
if (frequency) {
|
|
333
|
-
console.warn(`isScheduledDate(): ${frequency} frequency is not implemented yet`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Get time from schedule
|
|
342
|
-
* @param schedule - Event schedule object
|
|
343
|
-
* @returns Next date in string format
|
|
344
|
-
*/
|
|
345
|
-
|
|
346
|
-
export function getTimeFromSchedule(
|
|
347
|
-
schedule: ScheduleObj | null,
|
|
348
|
-
date: Date | null,
|
|
349
|
-
endAt: Date | null,
|
|
350
|
-
timeZone: string | null
|
|
351
|
-
) {
|
|
352
|
-
if ((!schedule?.frequency || schedule.frequency === 'ONCE') && date) {
|
|
353
|
-
|
|
354
|
-
const endAtDate = endAt ? new Date(endAt) : null;
|
|
355
|
-
if (endAtDate) {
|
|
356
|
-
|
|
357
|
-
const dayDiff = Math.floor((endAtDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
|
|
358
|
-
if (dayDiff > 0) {
|
|
359
|
-
return [
|
|
360
|
-
hhmmFromDateOrTime(null, date, true, timeZone),
|
|
361
|
-
getFullDate(endAtDate, 'DATE_ONLY_SHORT', timeZone)
|
|
362
|
-
];
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return [
|
|
366
|
-
hhmmFromDateOrTime(null, date, true, timeZone),
|
|
367
|
-
endAtDate > date ? hhmmFromDateOrTime(null, endAtDate, true, timeZone) : null
|
|
368
|
-
];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return [hhmmFromDateOrTime(null, date, true, timeZone)];
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const timeSched = schedule?.time;
|
|
375
|
-
if (
|
|
376
|
-
!Array.isArray(timeSched) ||
|
|
377
|
-
!timeSched[0]
|
|
378
|
-
) {
|
|
379
|
-
return [i18n.t('form.not_specified')];
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const [startTime, endTime] = timeSched;
|
|
383
|
-
return [
|
|
384
|
-
hhmmFromDateOrTime(startTime, null, true, timeZone),
|
|
385
|
-
endTime && hhmmFromDateOrTime(endTime, null, true, timeZone)
|
|
386
|
-
];
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Filter org event attendance based on manual check & edit history
|
|
391
|
-
* @param attendance - Array of organization event attendance data objects
|
|
392
|
-
* @param calDate - Calendar date in string format (YYYY-MM-DD)
|
|
393
|
-
* @returns Filtered array of organization event attendance data objects
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
export function filterEventAttendance(
|
|
397
|
-
attendance_: ProductAttendanceData[],
|
|
398
|
-
calDate: string,
|
|
399
|
-
): ProductAttendanceData[] {
|
|
400
|
-
const targetJSDate = new Date(calDate);
|
|
401
|
-
const targetTimestamp = targetJSDate.getTime();
|
|
402
|
-
const attendance = attendance_.filter((item) => !item.calDate || new Date(item.calDate).getTime() === targetTimestamp);
|
|
403
|
-
|
|
404
|
-
const checkedAttendance = new Set<number | bigint>();
|
|
405
|
-
for (const item of attendance) {
|
|
406
|
-
if (item.attended !== null) {
|
|
407
|
-
checkedAttendance.add(item.organizationId);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const isActiveOnDate = (item: ProductAttendanceData): boolean => {
|
|
412
|
-
if (
|
|
413
|
-
item.calDate || // If "calDate" is set, this was a manual override by a human, so history is ignored
|
|
414
|
-
!item.history || item.history.length === 0
|
|
415
|
-
) {
|
|
416
|
-
return true;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Sort history by date to be safe
|
|
420
|
-
// NOTE: item.history.sort() will mutate the original array, but that's acceptable for our application
|
|
421
|
-
const sorted = item.history.sort((a: any, b: any) => new Date(a[0]).getTime() - new Date(b[0]).getTime());
|
|
422
|
-
|
|
423
|
-
let active = false;
|
|
424
|
-
for (const [hDate, status] of sorted) {
|
|
425
|
-
if (new Date(hDate) > targetJSDate) {
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
active = status === '1';
|
|
429
|
-
}
|
|
430
|
-
return active;
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
const filteredList = attendance.filter((item) =>
|
|
434
|
-
!(item.attended === null && checkedAttendance.has(item.organizationId)) &&
|
|
435
|
-
isActiveOnDate(item)
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
// Sort by organization.name
|
|
439
|
-
return filteredList.sort((a, b) => a.organization.name.localeCompare(b.organization.name));
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Get all date this event happens between 2 calendar dates
|
|
444
|
-
* @param calEvent
|
|
445
|
-
* @param fromDate
|
|
446
|
-
* @param toDate
|
|
447
|
-
* @returns
|
|
448
|
-
*/
|
|
449
|
-
|
|
450
|
-
export function getAllEventDates(
|
|
451
|
-
calEvent: ProductCalEventData,
|
|
452
|
-
fromDate: string, // "YYYY-MM-DD"
|
|
453
|
-
toDate: string, // "YYYY-MM-DD"
|
|
454
|
-
timeZone: string | null = null,
|
|
455
|
-
): string[] {
|
|
456
|
-
const results: string[] = [];
|
|
457
|
-
|
|
458
|
-
const from = parseBoundaryDateInTimezone(fromDate, timeZone);
|
|
459
|
-
const to = parseBoundaryDateInTimezone(toDate, timeZone, true);
|
|
460
|
-
|
|
461
|
-
const eventStart = new Date(calEvent.startAt);
|
|
462
|
-
const eventEnd = calEvent.endAt ? new Date(calEvent.endAt) : null;
|
|
463
|
-
|
|
464
|
-
const rangeStart = new Date(Math.max(from.getTime(), eventStart.getTime()));
|
|
465
|
-
const rangeEnd = eventEnd
|
|
466
|
-
? new Date(Math.min(to.getTime(), eventEnd.getTime()))
|
|
467
|
-
: to;
|
|
468
|
-
|
|
469
|
-
// @ts-ignore – product events only
|
|
470
|
-
const { frequency, daysOfWeek } = calEvent.metadata?.schedule || {};
|
|
471
|
-
|
|
472
|
-
switch (frequency) {
|
|
473
|
-
case 'ONCE': {
|
|
474
|
-
if (eventStart >= from && eventStart <= to) {
|
|
475
|
-
results.push(formatCalDateInTimeZone(eventStart, timeZone));
|
|
476
|
-
}
|
|
477
|
-
return results;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
case 'WEEKLY': {
|
|
481
|
-
if (!Array.isArray(daysOfWeek) || !daysOfWeek.length) {
|
|
482
|
-
return results;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const allowedDays = new Set<number>(daysOfWeek);
|
|
486
|
-
const cursor = new Date(rangeStart);
|
|
487
|
-
|
|
488
|
-
while (cursor <= rangeEnd) {
|
|
489
|
-
const dow = getDayOfWeekInTimeZone(cursor, timeZone);
|
|
490
|
-
|
|
491
|
-
if (allowedDays.has(dow)) {
|
|
492
|
-
const dateStr = formatCalDateInTimeZone(cursor, timeZone);
|
|
493
|
-
|
|
494
|
-
// Final safety clamp (prevents Jan 1 bleed)
|
|
495
|
-
if (dateStr >= fromDate && dateStr <= toDate) {
|
|
496
|
-
results.push(dateStr);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Move forward ONE LOCAL DAY safely
|
|
501
|
-
cursor.setDate(cursor.getDate() + 1);
|
|
502
|
-
}
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return results;
|
|
508
|
-
}
|