import React from 'react';
import dateFnsFormat from 'date-fns/format';
import { useTranslation } from 'next-i18next';
import CopyDropdown from '../Page/CopyDropdown';
type ShareLinkTrProps = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
shareLink: any,
isAdmin?: boolean,
onDelete?: () => void,
}
const ShareLinkTr = (props: ShareLinkTrProps): JSX.Element => {
const { t } = useTranslation();
const { isAdmin, shareLink, onDelete } = props;
const { _id: shareLinkId, relatedPage } = shareLink;
const isRelatedPageExists = relatedPage != null;
return (
|
{shareLinkId}
{ isRelatedPageExists && (
Copy Link
) }
|
{ isAdmin && (
{ isRelatedPageExists
? {relatedPage.path}
: '(Page is not found)'
}
|
) }
{shareLink.expiredAt && {dateFnsFormat(new Date(shareLink.expiredAt), 'yyyy-MM-dd HH:mm')}} |
{shareLink.description} |
|
);
};
type Props = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
shareLinks: any[],
onClickDeleteButton?: (shareLinkId: string) => void,
isAdmin?: boolean,
}
const ShareLinkList = (props: Props): JSX.Element => {
const { t } = useTranslation('commons');
function renderShareLinks() {
return (
<>
{props.shareLinks.map(shareLink => (
{
if (props.onClickDeleteButton == null) {
return;
}
props.onClickDeleteButton(shareLink._id);
}}
/>
))}
>
);
}
return (
| {t('share_links.Share Link', { ns: 'commons' })} |
{props.isAdmin && {t('share_links.Page Path', { ns: 'commons' })} | }
{t('share_links.expire', { ns: 'commons' })} |
{t('share_links.description', { ns: 'commons' })} |
|
{renderShareLinks()}
);
};
export default ShareLinkList;