@pushwoosh/dumb-components 1.1.52 → 1.1.54

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.
@@ -1,4 +1,4 @@
1
- import React, { useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { Color } from '@pushwoosh/kit-constants';
4
4
  import { Horizontal, useClickAway, Vertical } from '@pushwoosh/kit-helpers';
@@ -21,8 +21,14 @@ export const CalendarDropdown = props => {
21
21
  const [isShaking, setIsShaking] = useState(false);
22
22
  const [popoverPosition, setPopoverPosition] = useState(null);
23
23
  const [value, setValue] = useState(props.value ?? (isRangePicker ? [] : undefined));
24
- const initialTimezone = 'timezone' in calendarProps ? calendarProps.timezone : 'UTC';
24
+ const initialTimezone = calendarProps.timezone || 'UTC';
25
25
  const [timezone, setTimezone] = useState(initialTimezone);
26
+ useEffect(() => {
27
+ setValue(props.value ?? (isRangePicker ? [] : undefined));
28
+ }, [props.value, isRangePicker]);
29
+ useEffect(() => {
30
+ setTimezone(calendarProps.timezone || 'UTC');
31
+ }, [calendarProps.timezone]);
26
32
  const closePopover = () => {
27
33
  setPopoverPosition(null);
28
34
  setValue(props.value ?? (isRangePicker ? [] : undefined));
@@ -44,7 +50,7 @@ export const CalendarDropdown = props => {
44
50
  (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, val);
45
51
  };
46
52
  const presets = 'presets' in props ? props.presets : undefined;
47
- const noValue = isRangePicker ? (value === null || value === void 0 ? void 0 : value.length) === 0 : !value;
53
+ const noValue = isRangePicker ? ((value === null || value === void 0 ? void 0 : value.length) ?? 0) === 0 : !value;
48
54
  let buttonText;
49
55
  if (noValue) {
50
56
  buttonText = isRangePicker ? 'Select period' : 'Select date';
@@ -124,8 +124,7 @@ export const getPeriodEnd = (date, period) => {
124
124
  return utcDateToStruct(dateObj);
125
125
  };
126
126
  export const dateToStruct = (date, tzOffsetMinutes) => {
127
- const utcTime = date.getTime() + date.getTimezoneOffset() * 60_000;
128
- const localTime = new Date(utcTime + tzOffsetMinutes * 60_000);
127
+ const localTime = new Date(date.getTime() + tzOffsetMinutes * 60_000);
129
128
  return utcDateToStruct(localTime);
130
129
  };
131
130
  export const structToDate = (ds, tzOffsetMinutes) => {
@@ -159,7 +158,8 @@ export const dateToStructTz = (date, tzName) => {
159
158
  return dateToStruct(date, tzOffsetMinutes);
160
159
  };
161
160
  export const structToDateTz = (ds, tzName) => {
162
- const tentativeDate = new Date(Date.UTC(ds.year, ds.month - 1, ds.day, ds.hour, ds.minute, ds.second, ds.millisecond));
161
+ const utcTime = Date.UTC(ds.year, ds.month - 1, ds.day, ds.hour, ds.minute, ds.second, ds.millisecond);
162
+ const tentativeDate = new Date(utcTime);
163
163
  const tzOffsetMinutes = getTimezoneOffset(tzName, tentativeDate);
164
- return structToDate(ds, tzOffsetMinutes);
164
+ return new Date(utcTime - tzOffsetMinutes * 60_000);
165
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.52",
3
+ "version": "1.1.54",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",