From 94ce4a6a0089ffffc8f29657f787654f8a244281 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Wed, 11 Dec 2024 09:23:33 +0100 Subject: [PATCH] fix(core): tasks UpdatedTimeAgo should be a hook --- .../core/tasks/components/activity/TaskActivityEditedAt.tsx | 4 ++-- .../core/tasks/components/activity/TasksActivityCreatedAt.tsx | 4 ++-- .../src/core/tasks/components/activity/helpers/index.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/sanity/src/core/tasks/components/activity/TaskActivityEditedAt.tsx b/packages/sanity/src/core/tasks/components/activity/TaskActivityEditedAt.tsx index f4f05ecf72b..b5c54da8147 100644 --- a/packages/sanity/src/core/tasks/components/activity/TaskActivityEditedAt.tsx +++ b/packages/sanity/src/core/tasks/components/activity/TaskActivityEditedAt.tsx @@ -2,7 +2,7 @@ import {Box, Flex, Text} from '@sanity/ui' import {memo} from 'react' import {Tooltip} from '../../../../ui-components' -import {getChangeDetails, NoWrap, UpdatedTimeAgo, UserName} from './helpers' +import {getChangeDetails, NoWrap, UserName, useUpdatedTimeAgo} from './helpers' import {type FieldChange} from './helpers/parseTransactions' interface EditedAtProps { @@ -12,7 +12,7 @@ interface EditedAtProps { export const EditedAt = memo( function EditedAt(props: EditedAtProps) { const {activity} = props - const {formattedDate, timeAgo} = UpdatedTimeAgo(activity.timestamp) + const {formattedDate, timeAgo} = useUpdatedTimeAgo(activity.timestamp) const {icon, text, changeTo} = getChangeDetails(activity) return ( diff --git a/packages/sanity/src/core/tasks/components/activity/TasksActivityCreatedAt.tsx b/packages/sanity/src/core/tasks/components/activity/TasksActivityCreatedAt.tsx index a806d7977a8..cd2e23de7d3 100644 --- a/packages/sanity/src/core/tasks/components/activity/TasksActivityCreatedAt.tsx +++ b/packages/sanity/src/core/tasks/components/activity/TasksActivityCreatedAt.tsx @@ -6,7 +6,7 @@ import {Tooltip} from '../../../../ui-components' import {useTranslation} from '../../../i18n' import {useUser} from '../../../store' import {tasksLocaleNamespace} from '../../i18n' -import {NoWrap, UpdatedTimeAgo} from './helpers' +import {NoWrap, useUpdatedTimeAgo} from './helpers' import {ActivityItem} from './TasksActivityItem' const UserSkeleton = styled(TextSkeleton)` @@ -23,7 +23,7 @@ export const TasksActivityCreatedAt = memo( function TasksActivityCreatedAt(props: TasksActivityCreatedAtProps) { const {createdAt, authorId} = props const [user, loading] = useUser(authorId) - const {timeAgo, formattedDate} = UpdatedTimeAgo(createdAt) + const {timeAgo, formattedDate} = useUpdatedTimeAgo(createdAt) const {t} = useTranslation(tasksLocaleNamespace) return ( diff --git a/packages/sanity/src/core/tasks/components/activity/helpers/index.tsx b/packages/sanity/src/core/tasks/components/activity/helpers/index.tsx index 01661985da2..e9438216fe6 100644 --- a/packages/sanity/src/core/tasks/components/activity/helpers/index.tsx +++ b/packages/sanity/src/core/tasks/components/activity/helpers/index.tsx @@ -37,7 +37,7 @@ export const NoWrap = styled.span` white-space: nowrap; ` -export function UpdatedTimeAgo(timestamp: string) { +export function useUpdatedTimeAgo(timestamp: string) { const date = new Date(timestamp) const dateFormatter = useDateTimeFormat(DATE_FORMAT_OPTIONS) const formattedDate = dateFormatter.format(date)