@7365admin1/layer-common 4.97.1-staging.637 → 4.97.1-staging.638

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.
@@ -7,7 +7,7 @@
7
7
  </template>
8
8
  </v-text-field>
9
9
  <div class="w-100 d-flex align-end ga-3 hidden-input">
10
- <input ref="dateInput" type="date" v-model="date" :min="min" />
10
+ <input ref="dateInput" type="date" v-model="date" :min="min" :max="max" />
11
11
  </div>
12
12
  </div>
13
13
  </template>
@@ -26,6 +26,10 @@ const prop = defineProps({
26
26
  min: {
27
27
  type: String,
28
28
  default: undefined
29
+ },
30
+ max: {
31
+ type: String,
32
+ default: undefined
29
33
  }
30
34
  })
31
35
 
@@ -127,8 +127,14 @@
127
127
  v-model="dateFrom"
128
128
  density="compact"
129
129
  hide-details
130
+ :max="todayOnly ? sgToday : undefined"
131
+ />
132
+ <InputDatePicker
133
+ v-model="dateTo"
134
+ density="compact"
135
+ hide-details
136
+ :max="todayOnly ? sgToday : undefined"
130
137
  />
131
- <InputDatePicker v-model="dateTo" density="compact" hide-details />
132
138
  <!-- iSecure: every tab but Unregistered; the Guests tab offers
133
139
  Guest / Contractor, the Visitors tab the eight types. -->
134
140
  <AppSelect
@@ -1882,6 +1888,7 @@ import { isVisitorPassSmsOn } from "../composables/useVisitor";
1882
1888
  import { barrierCameraOf, barrierMessage, barrierOf, VISITOR_ACTION_SUCCESS } from "../utils/visitor-barrier";
1883
1889
  import useVisitorCameraChoices from "../composables/useVisitorCameraChoices";
1884
1890
  import { VISITOR_CAMERA_LABEL } from "../utils/visitor-camera";
1891
+ import { notAfterToday, sgDateOf, type VisitorDateDefault } from "../utils/visitor-date-default";
1885
1892
  import usePassKey from "../composables/usePassKey";
1886
1893
  import {
1887
1894
  VISITOR_SEARCH_DEBOUNCE_MS,
@@ -1893,6 +1900,11 @@ import {
1893
1900
  const { downloadPDF } = usePDFDownload();
1894
1901
 
1895
1902
  const props = defineProps({
1903
+ // The date filter's opening range: "last30" (iSecure) or "today" (Property).
1904
+ defaultDateRange: {
1905
+ type: String as PropType<VisitorDateDefault>,
1906
+ default: "last30",
1907
+ },
1896
1908
  canAddVisitor: {
1897
1909
  type: Boolean,
1898
1910
  default: false,
@@ -2246,8 +2258,15 @@ function daysAgo(days: number) {
2246
2258
  date.setDate(date.getDate() - days);
2247
2259
  return date;
2248
2260
  }
2249
- const defaultDateTo = () => normalizeDateOnly(new Date().toISOString());
2250
- const defaultDateFrom = () => normalizeDateOnly(daysAgo(30).toISOString());
2261
+ // defaultDateRange "today" (Property, DV-0886): both dates are today in
2262
+ // Singapore, nothing after today can be picked, and a fresh open ignores dates
2263
+ // left in the URL. "last30" keeps the lines below exactly as they were.
2264
+ const todayOnly = computed(() => props.defaultDateRange === "today");
2265
+ const sgToday = ref(sgDateOf());
2266
+ const defaultDateTo = () =>
2267
+ todayOnly.value ? sgToday.value : normalizeDateOnly(new Date().toISOString());
2268
+ const defaultDateFrom = () =>
2269
+ todayOnly.value ? sgToday.value : normalizeDateOnly(daysAgo(30).toISOString());
2251
2270
 
2252
2271
  const dateTo = ref(defaultDateTo());
2253
2272
  const dateFrom = ref(defaultDateFrom());
@@ -4224,11 +4243,37 @@ watch(
4224
4243
  // iSecure: the dates cannot be cleared - a cleared one goes back to its default.
4225
4244
  watch(dateFrom, (value) => {
4226
4245
  if (!value) dateFrom.value = defaultDateFrom();
4246
+ else if (todayOnly.value && value > sgToday.value) dateFrom.value = sgToday.value;
4227
4247
  });
4228
4248
  watch(dateTo, (value) => {
4229
4249
  if (!value) dateTo.value = defaultDateTo();
4250
+ else if (todayOnly.value && value > sgToday.value) dateTo.value = sgToday.value;
4230
4251
  });
4231
4252
 
4253
+ // "today" only: a page left open past midnight moves an untouched today to
4254
+ // the new day. A range the user picked is left alone.
4255
+ let sgDayTimer: ReturnType<typeof setInterval> | null = null;
4256
+ onMounted(() => {
4257
+ if (!todayOnly.value) return;
4258
+ sgDayTimer = setInterval(() => {
4259
+ const next = sgDateOf();
4260
+ if (next === sgToday.value) return;
4261
+ const previous = sgToday.value;
4262
+ sgToday.value = next;
4263
+ if (dateFrom.value === previous && dateTo.value === previous) {
4264
+ dateFrom.value = next;
4265
+ dateTo.value = next;
4266
+ }
4267
+ }, 60_000);
4268
+ });
4269
+ onBeforeUnmount(() => {
4270
+ if (sgDayTimer) clearInterval(sgDayTimer);
4271
+ });
4272
+
4273
+ // "today" only: the first read of the route is a fresh open, so dates left in
4274
+ // the URL (bookmark, back navigation, yesterday's tab) do not replace today.
4275
+ let routeDatesSeen = false;
4276
+
4232
4277
  const syncVisitorFiltersFromRoute = () => {
4233
4278
  const requestedTab = (route.query.tab as string) || "registered";
4234
4279
  const nextTab =
@@ -4254,15 +4299,20 @@ const syncVisitorFiltersFromRoute = () => {
4254
4299
  searchQuery.value = nextSearch;
4255
4300
  }
4256
4301
 
4257
- if (route.query.dateFrom) {
4258
- const nextDateFrom = normalizeDateOnly(route.query.dateFrom as string);
4302
+ const skipRouteDates = todayOnly.value && !routeDatesSeen;
4303
+ routeDatesSeen = true;
4304
+ const fromRoute = (value: string) =>
4305
+ todayOnly.value ? notAfterToday(value, sgToday.value) : value;
4306
+
4307
+ if (route.query.dateFrom && !skipRouteDates) {
4308
+ const nextDateFrom = fromRoute(normalizeDateOnly(route.query.dateFrom as string));
4259
4309
  if (dateFrom.value !== nextDateFrom) {
4260
4310
  dateFrom.value = nextDateFrom;
4261
4311
  }
4262
4312
  }
4263
4313
 
4264
- if (route.query.dateTo) {
4265
- const nextDateTo = normalizeDateOnly(route.query.dateTo as string);
4314
+ if (route.query.dateTo && !skipRouteDates) {
4315
+ const nextDateTo = fromRoute(normalizeDateOnly(route.query.dateTo as string));
4266
4316
  if (dateTo.value !== nextDateTo) {
4267
4317
  dateTo.value = nextDateTo;
4268
4318
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.637",
5
+ "version": "4.97.1-staging.638",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The Visitor Mgmt date filter's default range.
3
+ *
4
+ * - "last30" (the default): the last 30 days through today. iSecure (Security
5
+ * web) keeps this; it is the behaviour before DV-0886.
6
+ * - "today": From and To are both today. The Property app asks for this.
7
+ *
8
+ * "Today" is the Singapore date, not the browser's: a browser in another time
9
+ * zone, or with a wrong clock, would otherwise show yesterday or tomorrow.
10
+ * Dates are YYYY-MM-DD strings, so they compare correctly as text.
11
+ */
12
+ export type VisitorDateDefault = "last30" | "today";
13
+
14
+ export const VISITOR_DATE_TIME_ZONE = "Asia/Singapore";
15
+
16
+ /** The Singapore date of `now`, as YYYY-MM-DD. */
17
+ export function sgDateOf(now: Date = new Date()): string {
18
+ return new Intl.DateTimeFormat("en-CA", {
19
+ timeZone: VISITOR_DATE_TIME_ZONE,
20
+ year: "numeric",
21
+ month: "2-digit",
22
+ day: "2-digit",
23
+ }).format(now);
24
+ }
25
+
26
+ /** YYYY-MM-DD `days` before `day`. */
27
+ export function daysBefore(day: string, days: number): string {
28
+ const date = new Date(`${day}T00:00:00Z`);
29
+ date.setUTCDate(date.getUTCDate() - days);
30
+ return date.toISOString().slice(0, 10);
31
+ }
32
+
33
+ /** The [from, to] a fresh page opens with. */
34
+ export function visitorDefaultRange(
35
+ mode: VisitorDateDefault,
36
+ today: string,
37
+ ): { from: string; to: string } {
38
+ return mode === "today"
39
+ ? { from: today, to: today }
40
+ : { from: daysBefore(today, 30), to: today };
41
+ }
42
+
43
+ /** A date after today becomes today; anything else is kept. */
44
+ export function notAfterToday(day: string, today: string): string {
45
+ return day && day > today ? today : day;
46
+ }