import React, { type JSX } from 'react'; import Link from 'next/link'; import type { IUserHasId } from '@growi/core'; import { type IUser, isPopulated, type Ref } from '@growi/core'; import { pagePathUtils } from '@growi/core/dist/utils'; import { UserPicture } from '@growi/ui/dist/components'; import { format } from 'date-fns/format'; import { useTranslation } from 'next-i18next'; import styles from './AuthorInfo.module.scss'; const UserLabel = ({ user, }: { user: IUserHasId | Ref; }): JSX.Element => { if (isPopulated(user)) { return ( {user.name} ); } return (anyone); }; type AuthorInfoProps = { date: Date; user?: IUserHasId | Ref; mode: 'create' | 'update'; locate: 'pageSide' | 'footer'; }; export const AuthorInfo = (props: AuthorInfoProps): JSX.Element => { const { t } = useTranslation(); const { date, user, mode = 'create', locate = 'pageSide' } = props; const formatType = 'yyyy/MM/dd HH:mm'; const infoLabelForPageSide = mode === 'create' ? t('author_info.created_by') : t('author_info.updated_by'); const nullinfoLabelForFooter = mode === 'create' ? 'Created by' : 'Updated by'; const infoLabelForFooter = mode === 'create' ? t('author_info.created_at') : t('author_info.last_revision_posted_at'); const userLabel = user != null ? : Unknown; if (locate === 'footer') { try { return (

{infoLabelForFooter} {format(new Date(date), formatType)} by{' '} {userLabel}

); } catch (err) { if (err instanceof RangeError) { return (

{nullinfoLabelForFooter} {' '} {userLabel}

); } return <>; } } const renderParsedDate = () => { try { return format(new Date(date), formatType); } catch (err) { return ''; } }; return (
{infoLabelForPageSide}
{userLabel}
{renderParsedDate()}
); };