AuthorInfo.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { userPageRoot } from '@commons/util/path-utils';
  4. import UserPicture from '../User/UserPicture';
  5. const AuthorInfo = (props) => {
  6. const {
  7. mode, user, date, locate,
  8. } = props;
  9. const infoLabelForSubNav = mode === 'create'
  10. ? 'Created by'
  11. : 'Updated by';
  12. const infoLabelForFooter = mode === 'create'
  13. ? 'Last revision posted at'
  14. : 'Created at';
  15. const userLabel = user != null
  16. ? <a href={userPageRoot(user)}>{user.name}</a>
  17. : <i>Unknown</i>;
  18. if (locate === 'footer') {
  19. return <p>{infoLabelForFooter} {date} by <UserPicture user={user} size="sm" /> {userLabel}</p>;
  20. }
  21. return (
  22. <div className="d-flex align-items-center">
  23. <div className="mr-2">
  24. <UserPicture user={user} size="sm" />
  25. </div>
  26. <div>
  27. <div>{infoLabelForSubNav} {userLabel}</div>
  28. <div className="text-muted text-date">{date}</div>
  29. </div>
  30. </div>
  31. );
  32. };
  33. AuthorInfo.propTypes = {
  34. date: PropTypes.string.isRequired,
  35. user: PropTypes.object,
  36. mode: PropTypes.oneOf(['create', 'update']),
  37. locate: PropTypes.oneOf(['subnav', 'footer']),
  38. };
  39. AuthorInfo.defaultProps = {
  40. mode: 'create',
  41. locate: 'subnav',
  42. };
  43. export default AuthorInfo;