|
|
@@ -1,21 +1,23 @@
|
|
|
import { formatDistanceToNow } from 'date-fns';
|
|
|
+import { useTranslation } from 'next-i18next';
|
|
|
|
|
|
import type { ActivityHasUserId, SupportedActivityActionType } from '~/interfaces/activity';
|
|
|
import { ActivityLogActions } from '~/interfaces/activity';
|
|
|
|
|
|
+
|
|
|
export const ActivityActionTranslationMap: Record<
|
|
|
SupportedActivityActionType,
|
|
|
string
|
|
|
> = {
|
|
|
- [ActivityLogActions.ACTION_PAGE_CREATE]: 'created a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_UPDATE]: 'updated a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_DELETE]: 'deleted a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_DELETE_COMPLETELY]: 'deleted a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_RENAME]: 'renamed a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_REVERT]: 'reverted a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_DUPLICATE]: 'duplicated a page',
|
|
|
- [ActivityLogActions.ACTION_PAGE_LIKE]: 'liked a page',
|
|
|
- [ActivityLogActions.ACTION_COMMENT_CREATE]: 'posted a comment',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_CREATE]: 'page_create',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_UPDATE]: 'page_update',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_DELETE]: 'page_delete',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_DELETE_COMPLETELY]: 'page_delete_completely',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_RENAME]: 'page_rename',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_REVERT]: 'page_revert',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_DUPLICATE]: 'page_duplicate',
|
|
|
+ [ActivityLogActions.ACTION_PAGE_LIKE]: 'page_like',
|
|
|
+ [ActivityLogActions.ACTION_COMMENT_CREATE]: 'comment_create',
|
|
|
};
|
|
|
|
|
|
export const IconActivityTranslationMap: Record<
|
|
|
@@ -34,11 +36,11 @@ export const IconActivityTranslationMap: Record<
|
|
|
};
|
|
|
|
|
|
const translateAction = (action: SupportedActivityActionType): string => {
|
|
|
- return ActivityActionTranslationMap[action] || 'performed an unknown action';
|
|
|
+ return ActivityActionTranslationMap[action] || 'KEY_MISSING_ERROR';
|
|
|
};
|
|
|
|
|
|
const setIcon = (action: SupportedActivityActionType): string => {
|
|
|
- return IconActivityTranslationMap[action] || 'performed an unknown action';
|
|
|
+ return IconActivityTranslationMap[action] || '';
|
|
|
};
|
|
|
|
|
|
const calculateTimePassed = (date: Date): string => {
|
|
|
@@ -49,23 +51,22 @@ const calculateTimePassed = (date: Date): string => {
|
|
|
|
|
|
|
|
|
export const ActivityListItem = ({ activity }: { activity: ActivityHasUserId }): JSX.Element => {
|
|
|
- const username = activity.user?.username;
|
|
|
+ const { t } = useTranslation();
|
|
|
+
|
|
|
const action = activity.action as SupportedActivityActionType;
|
|
|
+ const keyToTranslate = translateAction(action);
|
|
|
+ const fullKeyPath = `user_home_page.${keyToTranslate}`;
|
|
|
|
|
|
return (
|
|
|
<div className="activity-row">
|
|
|
- <p className="text-muted small mb-1">
|
|
|
+ <p className="small mb-1">
|
|
|
{setIcon(action)}
|
|
|
|
|
|
- <span className="text-gray-900 dark:text-white">
|
|
|
- {username}
|
|
|
- </span>
|
|
|
-
|
|
|
<strong className="text-gray-900 dark:text-white">
|
|
|
- {' '}{translateAction(action)}
|
|
|
+ {' '}{t(fullKeyPath)}
|
|
|
</strong>
|
|
|
|
|
|
- <span className="text-muted text-xs">
|
|
|
+ <span className="text-secondary">
|
|
|
{' '}・{' '}
|
|
|
{calculateTimePassed(activity.createdAt)}
|
|
|
</span>
|