@samitouri / QOSami-HFS / commits / 38e63185

fix: admin/options: GUI crash trying to edit a block rule with expiration

Massimo Melina committed Apr 25, 2024 at 17:50 UTC 38e63185085fe08e294083630a5734123d67e064
2 files changed +6 -3
admin/src/DateTimeField.ts
+2 -3
@@ -3,12 +3,12 @@ import dayjs from 'dayjs'
3 import { FieldProps } from '@hfs/mui-grid-form'
4 import { createElement as h } from 'react'
5 import { Box, FormHelperText } from '@mui/material'
6 -import { objSameKeys } from './misc'
6 +import { isTimestampString, objSameKeys } from './misc'
7
8 export function DateTimeField({ onChange, error, helperText, ...rest }: FieldProps<Date>) {
9 return h(Box, {},
10 h(DateTimePicker, {
11 - ...objSameKeys(rest, x => x && x instanceof Date ? dayjs(x) : (x ?? null)), // null to not be considered uncontrolled
11 + ...objSameKeys(rest, x => isTimestampString(x) || x && x instanceof Date ? dayjs(x) : (x ?? null)), // null to not be considered uncontrolled
12 sx: { width: '100%', color: 'error.main', ...rest.sx },
13 onChange(v: any) {
14 onChange(v && new Date(v), { was: rest.value, event: undefined })
@@ -20,4 +20,3 @@ export function DateTimeField({ onChange, error, helperText, ...rest }: FieldPro
20 helperText && h(FormHelperText, { error }, helperText),
21 )
22 }
23 -
src/cross.ts
+4
@@ -358,6 +358,10 @@ export function isWindowsDrive(s?: string) {
358 return s && /^[a-zA-Z]:$/.test(s)
359 }
360
361 +export function isTimestampString(v: unknown) {
362 + return typeof v === 'string' && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z*$/.test(v)
363 +}
364 +
365 export function isEqualLax(a: any,b: any): boolean {
366 return a == b //eslint-disable-line
367 || (a && b && typeof a === 'object' && typeof b === 'object'