Login:Src:Utils: add functions for timezone

This commit is contained in:
Darya Umrikhina 2024-07-11 12:31:57 +04:00
parent bbac07f94d
commit b485c6a4d9

View File

@ -28,6 +28,10 @@ import { thirdPartyLogin } from "@docspace/shared/utils/loginUtils";
import { Nullable, TTranslation } from "@docspace/shared/types"; import { Nullable, TTranslation } from "@docspace/shared/types";
import { MessageKey } from "./enums"; import { MessageKey } from "./enums";
import { TTimeZone } from "@docspace/shared/api/settings/types";
import { TTimeZoneOption } from "@/types";
import { findWindows } from "windows-iana";
export async function oAuthLogin(profile: string) { export async function oAuthLogin(profile: string) {
let isSuccess = false; let isSuccess = false;
@ -138,3 +142,35 @@ export const getEmailFromInvitation = (encodeString: Nullable<string>) => {
return queryParams.email; return queryParams.email;
}; };
export const mapTimezonesToArray = (
timezones: TTimeZone[],
): TTimeZoneOption[] => {
return timezones.map((timezone) => {
return { key: timezone.id, label: timezone.displayName };
});
};
export const getUserTimezone = (): string => {
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
};
export const getSelectZone = (
zones: TTimeZoneOption[],
userTimezone: string,
) => {
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[0]) ||
zones.filter((zone) => zone.key === defaultTimezone)
);
}
return (
zones.filter((zone) => zone.key === userTimezone) ||
zones.filter((zone) => zone.key === defaultTimezone)
);
};