mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
chore: format schedule information according to user preferences (#5747)
This pr uses the user's preferred timezone to display the scheduled times. If the user has no preferences, the default will be used. With norwegian locale set as preference: <img width="1529" alt="image" src="https://github.com/Unleash/unleash/assets/17786332/0072432c-e470-4edc-91fb-864a86bc8f30"> With nothing set (falls back to my system setting): <img width="1529" alt="image" src="https://github.com/Unleash/unleash/assets/17786332/adf3d95f-4015-4302-ac09-e3ba511090db">
This commit is contained in:
parent
9c4a044543
commit
b0c5baa9d3
@ -8,6 +8,7 @@ import {
|
|||||||
useTheme,
|
useTheme,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { ReactComponent as ChangesAppliedIcon } from 'assets/icons/merge.svg';
|
import { ReactComponent as ChangesAppliedIcon } from 'assets/icons/merge.svg';
|
||||||
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
import {
|
import {
|
||||||
StyledOuterContainer,
|
StyledOuterContainer,
|
||||||
StyledButtonContainer,
|
StyledButtonContainer,
|
||||||
@ -30,6 +31,7 @@ import {
|
|||||||
} from 'component/changeRequest/changeRequest.types';
|
} from 'component/changeRequest/changeRequest.types';
|
||||||
import { getBrowserTimezone } from './utils';
|
import { getBrowserTimezone } from './utils';
|
||||||
import { ConditionallyRender } from '../../../common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../../common/ConditionallyRender/ConditionallyRender';
|
||||||
|
import { formatDateYMDHMS } from 'utils/formatDate';
|
||||||
|
|
||||||
interface ISuggestChangeReviewsStatusProps {
|
interface ISuggestChangeReviewsStatusProps {
|
||||||
changeRequest: IChangeRequest;
|
changeRequest: IChangeRequest;
|
||||||
@ -232,6 +234,7 @@ interface IScheduledProps {
|
|||||||
const Scheduled = ({ schedule, onEditClick }: IScheduledProps) => {
|
const Scheduled = ({ schedule, onEditClick }: IScheduledProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const timezone = getBrowserTimezone();
|
const timezone = getBrowserTimezone();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
if (!schedule?.scheduledAt) {
|
if (!schedule?.scheduledAt) {
|
||||||
return null;
|
return null;
|
||||||
@ -273,18 +276,24 @@ const ScheduledFailed = ({
|
|||||||
}: { schedule: IChangeRequestSchedule }) => {
|
}: { schedule: IChangeRequestSchedule }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const timezone = getBrowserTimezone();
|
const timezone = getBrowserTimezone();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
if (!schedule?.scheduledAt) {
|
if (!schedule?.scheduledAt) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scheduledTime = formatDateYMDHMS(
|
||||||
|
new Date(schedule?.scheduledAt),
|
||||||
|
locationSettings?.locale,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledFlexAlignCenterBox>
|
<StyledFlexAlignCenterBox>
|
||||||
<StyledInfoIcon />
|
<StyledInfoIcon />
|
||||||
<Box>
|
<Box>
|
||||||
<StyledReviewTitle color={theme.palette.error.main}>
|
<StyledReviewTitle color={theme.palette.error.main}>
|
||||||
Changes failed to be applied on{' '}
|
Changes failed to be applied on {scheduledTime} because of{' '}
|
||||||
{new Date(schedule?.scheduledAt).toLocaleString()} because
|
{schedule?.failureReason}
|
||||||
of {schedule?.failureReason}
|
|
||||||
</StyledReviewTitle>
|
</StyledReviewTitle>
|
||||||
<Typography>Your timezone is {timezone}</Typography>
|
<Typography>Your timezone is {timezone}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
@ -297,13 +306,23 @@ const ScheduledPending = ({
|
|||||||
}: { schedule: IChangeRequestSchedule }) => {
|
}: { schedule: IChangeRequestSchedule }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const timezone = getBrowserTimezone();
|
const timezone = getBrowserTimezone();
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
|
if (!schedule?.scheduledAt) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduledTime = formatDateYMDHMS(
|
||||||
|
new Date(schedule?.scheduledAt),
|
||||||
|
locationSettings?.locale,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledFlexAlignCenterBox>
|
<StyledFlexAlignCenterBox>
|
||||||
<StyledScheduledIcon />
|
<StyledScheduledIcon />
|
||||||
<Box>
|
<Box>
|
||||||
<StyledReviewTitle color={theme.palette.warning.dark}>
|
<StyledReviewTitle color={theme.palette.warning.dark}>
|
||||||
Changes are scheduled to be applied on:{' '}
|
Changes are scheduled to be applied on: {scheduledTime}
|
||||||
{new Date(schedule?.scheduledAt).toLocaleString()}
|
|
||||||
</StyledReviewTitle>
|
</StyledReviewTitle>
|
||||||
<Typography>Your timezone is {timezone}</Typography>
|
<Typography>Your timezone is {timezone}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -10,6 +10,8 @@ import { ChangeRequestState } from '../../changeRequest.types';
|
|||||||
import { ConditionallyRender } from '../../../common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../../common/ConditionallyRender/ConditionallyRender';
|
||||||
import { HtmlTooltip } from '../../../common/HtmlTooltip/HtmlTooltip';
|
import { HtmlTooltip } from '../../../common/HtmlTooltip/HtmlTooltip';
|
||||||
import { Info } from '@mui/icons-material';
|
import { Info } from '@mui/icons-material';
|
||||||
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
|
import { formatDateYMDHMS } from 'utils/formatDate';
|
||||||
|
|
||||||
interface ISuggestChangeTimelineProps {
|
interface ISuggestChangeTimelineProps {
|
||||||
state: ChangeRequestState;
|
state: ChangeRequestState;
|
||||||
@ -103,6 +105,8 @@ export const ChangeRequestTimeline: FC<ISuggestChangeTimelineProps> = ({
|
|||||||
}
|
}
|
||||||
const activeIndex = data.findIndex((item) => item === state);
|
const activeIndex = data.findIndex((item) => item === state);
|
||||||
|
|
||||||
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledPaper elevation={0}>
|
<StyledPaper elevation={0}>
|
||||||
<StyledBox>
|
<StyledBox>
|
||||||
@ -112,7 +116,10 @@ export const ChangeRequestTimeline: FC<ISuggestChangeTimelineProps> = ({
|
|||||||
scheduledAt &&
|
scheduledAt &&
|
||||||
state === 'Scheduled' &&
|
state === 'Scheduled' &&
|
||||||
state === title
|
state === title
|
||||||
? new Date(scheduledAt).toLocaleString()
|
? formatDateYMDHMS(
|
||||||
|
new Date(scheduledAt),
|
||||||
|
locationSettings?.locale,
|
||||||
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
const color = determineColor(
|
const color = determineColor(
|
||||||
state,
|
state,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export const formatDateYMDHMS = (
|
export const formatDateYMDHMS = (
|
||||||
date: number | string | Date,
|
date: number | string | Date,
|
||||||
locale: string,
|
locale?: string,
|
||||||
): string => {
|
): string => {
|
||||||
return new Date(date).toLocaleString(locale, {
|
return new Date(date).toLocaleString(locale, {
|
||||||
day: '2-digit',
|
day: '2-digit',
|
||||||
|
Loading…
Reference in New Issue
Block a user