0fe1201435
**What** - Renames /admin-next -> /admin - Renames @medusajs/admin-sdk -> @medusajs/admin-bundler - Creates a new package called @medusajs/admin-sdk that will hold all tooling relevant to creating admin extensions. This is currently `defineRouteConfig` and `defineWidgetConfig`, but will eventually also export methods for adding custom fields, register translation, etc. - cc: @shahednasser we should update the examples in the docs so these functions are imported from `@medusajs/admin-sdk`. People will also need to install the package in their project, as it's no longer a transient dependency. - cc: @olivermrbl we might want to publish a changelog when this is merged, as it is a breaking change, and will require people to import the `defineXConfig` from the new package instead of `@medusajs/admin-shared`. - Updates CODEOWNERS so /admin packages does not require a review from the UI team.
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { format, formatDistance, sub } from "date-fns"
|
|
import { enUS } from "date-fns/locale"
|
|
import { useTranslation } from "react-i18next"
|
|
|
|
import { languages } from "../i18n/languages"
|
|
|
|
// TODO: We rely on the current language to determine the date locale. This is not ideal, as we use en-US for the english translation.
|
|
// We either need to also have an en-GB translation or we need to separate the date locale from the translation language.
|
|
export const useDate = () => {
|
|
const { i18n } = useTranslation()
|
|
|
|
const locale =
|
|
languages.find((l) => l.code === i18n.language)?.date_locale || enUS
|
|
|
|
const getFullDate = ({
|
|
date,
|
|
includeTime = false,
|
|
}: {
|
|
date: string | Date
|
|
includeTime?: boolean
|
|
}) => {
|
|
const ensuredDate = new Date(date)
|
|
|
|
if (isNaN(ensuredDate.getTime())) {
|
|
return ""
|
|
}
|
|
|
|
const timeFormat = includeTime ? "p" : ""
|
|
|
|
return format(ensuredDate, `PP ${timeFormat}`, {
|
|
locale,
|
|
})
|
|
}
|
|
|
|
function getRelativeDate(date: string | Date): string {
|
|
const now = new Date()
|
|
|
|
return formatDistance(sub(new Date(date), { minutes: 0 }), now, {
|
|
addSuffix: true,
|
|
locale,
|
|
})
|
|
}
|
|
|
|
return {
|
|
getFullDate,
|
|
getRelativeDate,
|
|
}
|
|
}
|