Рефакторинг импорта dayjs и добавление утилиты форматирования дат. Все компоненты, использующие dayjs, теперь используют новую функцию formatDate для форматирования дат с учетом локали. Также добавлена поддержка обновления локали dayjs при изменении языка в i18next.

This commit is contained in:
2025-03-23 21:58:18 +03:00
parent 3d383f2e25
commit 2901f51862
15 changed files with 75 additions and 40 deletions
+10 -7
View File
@@ -1,4 +1,5 @@
import React, { useCallback, useEffect, useState, useMemo } from 'react'
import { formatDate } from '../../utils/dayjs-config'
import dayjs from 'dayjs'
import { Link as ConnectedLink, generatePath } from 'react-router-dom'
import { getNavigationValue } from '@brojs/cli'
@@ -231,7 +232,7 @@ export const CourseCard = ({ course }: { course: Course }) => {
<Badge colorScheme="blue">
<HStack spacing={1}>
<CalendarIcon boxSize="3" />
<Text>{dayjs(course.startDt).format('DD.MM.YYYY')}</Text>
<Text>{formatDate(course.startDt, 'DD.MM.YYYY')}</Text>
</HStack>
</Badge>
<Badge colorScheme="purple">
@@ -243,7 +244,7 @@ export const CourseCard = ({ course }: { course: Course }) => {
<Badge colorScheme="blue">
<HStack spacing={1}>
<CalendarIcon boxSize="3" />
<Text>{dayjs(course.startDt).format('DD.MM.YYYY')}</Text>
<Text>{formatDate(course.startDt, 'DD.MM.YYYY')}</Text>
</HStack>
</Badge>
<Badge colorScheme="purple">
@@ -311,10 +312,12 @@ export const CourseCard = ({ course }: { course: Course }) => {
{populatedCourse.data?.lessons
.filter(lesson => dayjs(lesson.date).isAfter(dayjs()))
.sort((a, b) => dayjs(a.date).valueOf() - dayjs(b.date).valueOf())[0]?.date
? dayjs(populatedCourse.data?.lessons
.filter(lesson => dayjs(lesson.date).isAfter(dayjs()))
.sort((a, b) => dayjs(a.date).valueOf() - dayjs(b.date).valueOf())[0]?.date)
.format('DD.MM.YYYY')
? formatDate(
populatedCourse.data?.lessons
.filter(lesson => dayjs(lesson.date).isAfter(dayjs()))
.sort((a, b) => dayjs(a.date).valueOf() - dayjs(b.date).valueOf())[0]?.date,
'DD.MM.YYYY'
)
: t('journal.pl.common.noData')
}
</Text>
@@ -455,7 +458,7 @@ export const CourseCard = ({ course }: { course: Course }) => {
<HStack spacing={2} mt={1} flexWrap="wrap">
<Tag size="sm" colorScheme={isPast ? "green" : "blue"} borderRadius="full">
<TagLeftIcon as={CalendarIcon} boxSize='10px' />
<TagLabel>{dayjs(lesson.date).format('DD.MM.YYYY')}</TagLabel>
<TagLabel>{formatDate(lesson.date, 'DD.MM.YYYY')}</TagLabel>
</Tag>
{isPast && lessonAttendance && (
<Tag