Client: Wizard: fix timezone select

This commit is contained in:
Viktor Fomin 2023-02-02 13:22:16 +03:00
parent 272c57a1fd
commit 42feb5475a
4 changed files with 35 additions and 8 deletions

View File

@ -50,7 +50,8 @@
"react-hotkeys-hook": "^3.4.4",
"react-markdown": "^7.0.1",
"react-smartbanner": "^5.1.4",
"react-string-format": "^0.1.4"
"react-string-format": "^0.1.4",
"windows-iana": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.15.5",

View File

@ -34,6 +34,8 @@ import {
StyledInfo,
StyledAcceptTerms,
} from "./StyledWizard";
import { getUserTimezone, getSelectZone } from "./timezonesHelper";
import DocspaceLogo from "SRC_DIR/DocspaceLogo";
import RefreshReactSvgUrl from "PUBLIC_DIR/images/refresh.react.svg?url";
@ -92,10 +94,6 @@ const Wizard = (props) => {
});
};
const getUserTimezone = () => {
return Intl.DateTimeFormat().resolvedOptions().timeZone || timezone;
};
const fetchData = async () => {
await axios
.all([
@ -105,9 +103,7 @@ const Wizard = (props) => {
getPortalTimezones(wizardToken).then((data) => {
const userTimezone = getUserTimezone();
const zones = mapTimezonesToArray(data);
const select =
zones.filter((zone) => zone.key === userTimezone) ||
zones.filter((zone) => zone.key === timezone);
const select = getSelectZone(zones, userTimezone);
setTimezones(zones);
setSelectedTimezone({

View File

@ -0,0 +1,22 @@
import { findWindows } from "windows-iana";
export const getUserTimezone = () => {
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
};
export const getSelectZone = (zones, userTimezone) => {
const defaultTimezone = "UTC";
const isWindowsZones = zones[0].key === "Dateline Standard Time"; //TODO: get from server
if (isWindowsZones) {
const windowsZoneKey = findWindows(userTimezone);
return (
zones.filter((zone) => zone.key === windowsZoneKey) ||
zones.filter((zone) => zone.key === defaultTimezone)
);
}
return (
zones.filter((zone) => zone.key === userTimezone) ||
zones.filter((zone) => zone.key === defaultTimezone)
);
};

View File

@ -2815,6 +2815,7 @@ __metadata:
webpack: 5.52.1
webpack-cli: 4.10.0
webpack-dev-server: 4.3.1
windows-iana: ^5.1.0
languageName: unknown
linkType: soft
@ -26168,6 +26169,13 @@ __metadata:
languageName: node
linkType: hard
"windows-iana@npm:^5.1.0":
version: 5.1.0
resolution: "windows-iana@npm:5.1.0"
checksum: 0dc9ababde5f839e83a4bcd448347d8da563efd9e23ce61ac777e9992774ff85de2a9f343f87b80b37b181742fe4d783cff3ba39191cfedb6357ae7d5f58aadc
languageName: node
linkType: hard
"winston-cloudwatch@npm:^6.1.1":
version: 6.1.1
resolution: "winston-cloudwatch@npm:6.1.1"