Username.tsx 630 B

1234567891011121314151617181920212223
  1. import React from 'react';
  2. import type { IUserHasId } from '@growi/core';
  3. import { isPopulated, type IUser, type Ref } from '@growi/core';
  4. import { pagePathUtils } from '@growi/core/dist/utils';
  5. import Link from 'next/link';
  6. export const Username: React.FC<{ user?: IUserHasId | Ref<IUser> }> = ({ user }): JSX.Element => {
  7. if (user == null || !isPopulated(user)) {
  8. return <i>(anyone)</i>;
  9. }
  10. const name = user.name || '(no name)';
  11. const username = user.username;
  12. const href = pagePathUtils.userHomepagePath(user);
  13. return (
  14. <Link href={href} prefetch={false}>
  15. {name}(@{username})
  16. </Link>
  17. );
  18. };