QnAListLayout.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. 'use client';
  2. import './style.scss';
  3. import Link from 'next/link';
  4. import { useSearchParams } from 'next/navigation';
  5. import { useMemo } from 'react';
  6. import Post from '@/types/forum/post';
  7. import { BoardListMeta } from '@/types/forum/boardMeta';
  8. import { formatDate, isNewPost } from '@/lib/utils/client';
  9. import NoticeListLayout from './NoticeListLayout';
  10. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  11. import { faComment } from '@fortawesome/free-regular-svg-icons';
  12. interface Props {
  13. boardListMeta: BoardListMeta;
  14. notice?: Post[];
  15. list: Post[];
  16. startIndex?: number;
  17. onChange?: (_: number|undefined) => void;
  18. }
  19. export default function QnAListLayout({boardListMeta, notice = [], list, startIndex, onChange}: Props)
  20. {
  21. const searchParams = useSearchParams();
  22. const query = useMemo(() => Object.fromEntries(searchParams.entries()), [searchParams]);
  23. return (
  24. <>
  25. <section className='qna-list-layout' aria-label='1:1문의 게시판'>
  26. <article>
  27. <ul>
  28. <li>번호</li>
  29. <li>제목</li>
  30. <li>작성자</li>
  31. <li>답변 여부</li>
  32. <li>작성일</li>
  33. </ul>
  34. </article>
  35. <article>
  36. {/* 일반 공지 */}
  37. <NoticeListLayout isEnabled={!boardListMeta.exceptNotice} list={notice} layout={boardListMeta.layout} />
  38. {/* 일반 글 */}
  39. {list.length > 0 && (
  40. list.map((row, i) => {
  41. const isNew = isNewPost(boardListMeta.isNewIcon, row);
  42. const createdAt = formatDate(row.createdAt);
  43. const postViewUrl = {pathname: '/post/' + row.id, query};
  44. return (
  45. <section key={row.id}>
  46. {/* PC */}
  47. <ol>
  48. <li>
  49. <small>{startIndex !== undefined ? startIndex - i : i + 1}</small>
  50. </li>
  51. <li>
  52. {row.boardPrefix && row.boardPrefixID && onChange && (
  53. <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
  54. [{row.boardPrefix.name}]
  55. </button>
  56. )}
  57. <Link href={postViewUrl}>
  58. <em>{row.subject} {row.comments > 0 && (<span>[{row.comments}]</span>)}</em>
  59. {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
  60. </Link>
  61. </li>
  62. <li>{row.name || row.sid}</li>
  63. <li>
  64. {!row.isReply ? (
  65. <span className='inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-yellow-600/20 ring-inset'>
  66. 대기
  67. </span>
  68. ) : (
  69. <span className='inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-green-600/20 ring-inset'>
  70. 완료
  71. </span>
  72. )}
  73. </li>
  74. <li>{createdAt}</li>
  75. </ol>
  76. {/* Mobile */}
  77. <dl hidden>
  78. <dt>
  79. {row.boardPrefix && row.boardPrefixID && onChange && (
  80. <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
  81. [{row.boardPrefix.name}]
  82. </button>
  83. )}
  84. <Link href={postViewUrl}>
  85. <em>{row.subject} {row.comments > 0 && (<span>[{row.comments}]</span>)}</em>
  86. {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
  87. </Link>
  88. </dt>
  89. <dd>
  90. <ul>
  91. <li>{row.name || row.sid}</li>
  92. <li><FontAwesomeIcon icon={faComment} /> {row.comments}</li>
  93. <li>
  94. {!row.isReply ? (
  95. <span className='inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-yellow-600/20 ring-inset'>
  96. 대기
  97. </span>
  98. ) : (
  99. <span className='inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-green-600/20 ring-inset'>
  100. 완료
  101. </span>
  102. )}
  103. </li>
  104. <li>{createdAt}</li>
  105. </ul>
  106. </dd>
  107. </dl>
  108. </section>
  109. );
  110. })
  111. )}
  112. {list.length <= 0 && (
  113. <section>
  114. <p className="text-center p-10">
  115. 1:1문의 글이 없습니다.
  116. </p>
  117. </section>
  118. )}
  119. </article>
  120. </section>
  121. </>
  122. );
  123. }