Skip to content

Commit

Permalink
adding new global date view format
Browse files Browse the repository at this point in the history
  • Loading branch information
viiktorstefanov committed Oct 4, 2024
1 parent a3124e8 commit e2639f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/util/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bg, enUS } from 'date-fns/locale'

export const formatDate = 'dd MMM yyyy'
export const formatDatetime = 'dd MMM yyyy HH:mm:ss'
export const dateViewFormat = 'dd.MM.yyyy'

export const formatDateString = (dateString: string | Date) => {
return format(new Date(dateString), 'dd.MM.yyyy')
Expand Down
6 changes: 1 addition & 5 deletions src/components/common/form/FormDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { LocalizationProvider, DatePicker } from '@mui/x-date-pickers'
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'
import { format } from 'date-fns'
import { useField, useFormikContext } from 'formik'
import { useTranslation } from 'next-i18next'

import { DATE_VALUE_FORMAT, getDateFormat } from 'common/util/date'
import { DATE_VALUE_FORMAT, dateViewFormat } from 'common/util/date'

/**
* MUI date picker to be connected with Formik. Propagates updates to the passed Formik field name
Expand All @@ -15,9 +14,6 @@ import { DATE_VALUE_FORMAT, getDateFormat } from 'common/util/date'
export default function FormDatePicker({ name, label }: { name: string; label: string }) {
const [field] = useField(name)
const { setFieldValue } = useFormikContext()
const { i18n } = useTranslation()

const dateViewFormat = getDateFormat(i18n?.language)

const updateValue = (newValue: Date | null) => {
let formattedValue
Expand Down

0 comments on commit e2639f1

Please sign in to comment.