feat: 기관관리 게시물/자료 탭에 Mattermost 채널 실시간 열람 화면 추가
- ChannelPosts: 문정원/법률검토 채널 선택 칩 + 3초 폴링으로 최근 게시글을 보여주고, 시스템 메시지·첨부파일 다운로드 칩·자동 스크롤을 처리한다 - ChannelFiles: 같은 채널 선택으로 자료실 파일 전체를 표로 보여주고 새로고침을 지원한다 - client.ts에 getPosts/getFiles/fileDownloadUrl 추가, OrgOverview는 게시물/자료 탭에서 자리표시 대신 위 컴포넌트를 렌더링(org.id로 key를 잡아 기관 전환 시 폴링을 재시작)
@b2761465741de3ad76272479928d9fa52c4ea4f8
--- frontend/src/api/client.ts
+++ frontend/src/api/client.ts
... | ... | @@ -36,6 +36,32 @@ |
| 36 | 36 |
total: number |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
+export interface FileRef {
|
|
| 40 |
+ id: string |
|
| 41 |
+ name: string |
|
| 42 |
+ size: number |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 45 |
+export interface PostView {
|
|
| 46 |
+ id: string |
|
| 47 |
+ user: string |
|
| 48 |
+ message: string |
|
| 49 |
+ createAt: number |
|
| 50 |
+ system: boolean |
|
| 51 |
+ files: FileRef[] |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+export interface FileView {
|
|
| 55 |
+ id: string |
|
| 56 |
+ name: string |
|
| 57 |
+ size: number |
|
| 58 |
+ mimeType: string |
|
| 59 |
+ createAt: number |
|
| 60 |
+ uploader: string |
|
| 61 |
+} |
|
| 62 |
+ |
|
| 63 |
+export type ChannelKindKey = 'mj' | 'law' |
|
| 64 |
+ |
|
| 39 | 65 |
/** |
| 40 | 66 |
* 서버가 4xx/5xx로 응답했을 때 던지는 예외. status를 함께 들고 있어야 호출자가 |
| 41 | 67 |
* "인증이 끊긴 것(401)"과 "그 밖의 모든 오류"를 구분해서 다르게 처리할 수 있다 - |
... | ... | @@ -91,6 +117,19 @@ |
| 91 | 117 |
return request<ProvisionResult>(`/api/orgs/${id}/channels`, { method: 'POST' })
|
| 92 | 118 |
} |
| 93 | 119 |
|
| 120 |
+export function getPosts(orgId: number, channel: ChannelKindKey): Promise<PostView[]> {
|
|
| 121 |
+ return request<PostView[]>(`/api/orgs/${orgId}/posts?channel=${channel}`)
|
|
| 122 |
+} |
|
| 123 |
+ |
|
| 124 |
+export function getFiles(orgId: number, channel: ChannelKindKey): Promise<FileView[]> {
|
|
| 125 |
+ return request<FileView[]>(`/api/orgs/${orgId}/files?channel=${channel}`)
|
|
| 126 |
+} |
|
| 127 |
+ |
|
| 128 |
+/** 다운로드는 <a href>가 그대로 열게 두므로 fetch()를 거치지 않는다. */ |
|
| 129 |
+export function fileDownloadUrl(fileId: string): string {
|
|
| 130 |
+ return `/api/files/${fileId}`
|
|
| 131 |
+} |
|
| 132 |
+ |
|
| 94 | 133 |
export function uploadSeed(file: File): Promise<SeedReport> {
|
| 95 | 134 |
const form = new FormData() |
| 96 | 135 |
form.append('file', file)
|
+++ frontend/src/components/ChannelFiles.test.tsx
... | ... | @@ -0,0 +1,97 @@ |
| 1 | +import { fireEvent, render, screen, waitFor } from '@testing-library/react' | |
| 2 | +import { beforeEach, describe, expect, it, vi } from 'vitest' | |
| 3 | +import ChannelFiles from './ChannelFiles' | |
| 4 | +import type { FileView, Org } from '../api/client' | |
| 5 | + | |
| 6 | +const mocks = vi.hoisted(() => ({ | |
| 7 | + getFiles: vi.fn(), | |
| 8 | +})) | |
| 9 | + | |
| 10 | +vi.mock('../api/client', async (importOriginal) => ({ | |
| 11 | + ...(await importOriginal<typeof import('../api/client')>()), | |
| 12 | + getFiles: mocks.getFiles, | |
| 13 | +})) | |
| 14 | + | |
| 15 | +function org(overrides: Partial<Org> = {}): Org { | |
| 16 | + return { | |
| 17 | + id: 1, | |
| 18 | + orgNo: '001', | |
| 19 | + orgName: '국제방송교류재단', | |
| 20 | + status: 'ACTIVE', | |
| 21 | + deptName: null, | |
| 22 | + managerName: null, | |
| 23 | + managerTitle: null, | |
| 24 | + managerPhone: null, | |
| 25 | + managerEmail: null, | |
| 26 | + channelIdMj: 'chan-mj', | |
| 27 | + channelIdLaw: 'chan-law', | |
| 28 | + ...overrides, | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +function file(overrides: Partial<FileView> = {}): FileView { | |
| 33 | + return { | |
| 34 | + id: 'f1', | |
| 35 | + name: '보고서.pdf', | |
| 36 | + size: 1234, | |
| 37 | + mimeType: 'application/pdf', | |
| 38 | + createAt: new Date('2026-07-01T10:30:00').getTime(), | |
| 39 | + uploader: '송민지', | |
| 40 | + ...overrides, | |
| 41 | + } | |
| 42 | +} | |
| 43 | + | |
| 44 | +beforeEach(() => { | |
| 45 | + mocks.getFiles.mockReset() | |
| 46 | +}) | |
| 47 | + | |
| 48 | +describe('ChannelFiles', () => { | |
| 49 | + it('목록을 표로 보여준다', async () => { | |
| 50 | + mocks.getFiles.mockResolvedValue([file()]) | |
| 51 | + | |
| 52 | + render(<ChannelFiles org={org()} />) | |
| 53 | + | |
| 54 | + await waitFor(() => { | |
| 55 | + expect(screen.getByText('보고서.pdf')).toBeTruthy() | |
| 56 | + expect(screen.getByText('송민지')).toBeTruthy() | |
| 57 | + }) | |
| 58 | + expect(screen.getByText('보고서.pdf').closest('a')).toHaveAttribute('href', '/api/files/f1') | |
| 59 | + }) | |
| 60 | + | |
| 61 | + it('새로고침을 누르면 다시 조회한다', async () => { | |
| 62 | + mocks.getFiles.mockResolvedValue([]) | |
| 63 | + | |
| 64 | + render(<ChannelFiles org={org()} />) | |
| 65 | + | |
| 66 | + await waitFor(() => expect(mocks.getFiles).toHaveBeenCalledTimes(1)) | |
| 67 | + | |
| 68 | + fireEvent.click(screen.getByRole('button', { name: '새로고침' })) | |
| 69 | + | |
| 70 | + await waitFor(() => expect(mocks.getFiles).toHaveBeenCalledTimes(2)) | |
| 71 | + }) | |
| 72 | + | |
| 73 | + it('자료가 없으면 안내 문구를 보여준다', async () => { | |
| 74 | + mocks.getFiles.mockResolvedValue([]) | |
| 75 | + | |
| 76 | + render(<ChannelFiles org={org()} />) | |
| 77 | + | |
| 78 | + await waitFor(() => { | |
| 79 | + expect(screen.getByText('등록된 자료가 없습니다.')).toBeTruthy() | |
| 80 | + }) | |
| 81 | + }) | |
| 82 | + | |
| 83 | + it('조회 중에는 불러오는 중 문구를 보여준다', () => { | |
| 84 | + mocks.getFiles.mockReturnValue(new Promise(() => {})) | |
| 85 | + | |
| 86 | + render(<ChannelFiles org={org()} />) | |
| 87 | + | |
| 88 | + expect(screen.getByText('불러오는 중…')).toBeTruthy() | |
| 89 | + }) | |
| 90 | + | |
| 91 | + it('양쪽 채널이 모두 없으면 안내 문구를 보여주고 API를 호출하지 않는다', () => { | |
| 92 | + render(<ChannelFiles org={org({ channelIdMj: null, channelIdLaw: null })} />) | |
| 93 | + | |
| 94 | + expect(screen.getByText('채널이 아직 생성되지 않았습니다.')).toBeTruthy() | |
| 95 | + expect(mocks.getFiles).not.toHaveBeenCalled() | |
| 96 | + }) | |
| 97 | +}) |
+++ frontend/src/components/ChannelFiles.tsx
... | ... | @@ -0,0 +1,153 @@ |
| 1 | +import { useEffect, useState } from 'react' | |
| 2 | +import { getFiles, fileDownloadUrl, type ChannelKindKey, type FileView, type Org } from '../api/client' | |
| 3 | + | |
| 4 | +const dateFormatter = new Intl.DateTimeFormat('ko-KR', { | |
| 5 | + year: 'numeric', | |
| 6 | + month: '2-digit', | |
| 7 | + day: '2-digit', | |
| 8 | + hour: '2-digit', | |
| 9 | + minute: '2-digit', | |
| 10 | +}) | |
| 11 | + | |
| 12 | +function humanizeSize(bytes: number): string { | |
| 13 | + if (bytes < 1024) { | |
| 14 | + return `${bytes} B` | |
| 15 | + } | |
| 16 | + const kb = bytes / 1024 | |
| 17 | + if (kb < 1024) { | |
| 18 | + return `${kb.toFixed(1)} KB` | |
| 19 | + } | |
| 20 | + return `${(kb / 1024).toFixed(1)} MB` | |
| 21 | +} | |
| 22 | + | |
| 23 | +function formatDate(createAt: number): string { | |
| 24 | + // Intl 기본 포맷은 "2026. 07. 22. 14:05" 형태라 화면 요구사항(yyyy-MM-dd HH:mm)에 맞게 다듬는다. | |
| 25 | + const parts = dateFormatter.formatToParts(new Date(createAt)) | |
| 26 | + const get = (type: string) => parts.find((p) => p.type === type)?.value ?? '' | |
| 27 | + return `${get('year')}-${get('month')}-${get('day')} ${get('hour')}:${get('minute')}` | |
| 28 | +} | |
| 29 | + | |
| 30 | +/** 기관관리 상세의 자료 탭. 선택한 채널에 올라온 첨부파일 전체를 목록으로 보여준다(폴링 없음). */ | |
| 31 | +export default function ChannelFiles({ org }: { org: Org }) { | |
| 32 | + const bothMissing = !org.channelIdMj && !org.channelIdLaw | |
| 33 | + const [channel, setChannel] = useState<ChannelKindKey>(org.channelIdMj ? 'mj' : 'law') | |
| 34 | + const [files, setFiles] = useState<FileView[]>([]) | |
| 35 | + const [loading, setLoading] = useState(false) | |
| 36 | + const [error, setError] = useState<string | null>(null) | |
| 37 | + const [reloadKey, setReloadKey] = useState(0) | |
| 38 | + | |
| 39 | + useEffect(() => { | |
| 40 | + if (bothMissing) { | |
| 41 | + return | |
| 42 | + } | |
| 43 | + | |
| 44 | + let cancelled = false | |
| 45 | + setLoading(true) | |
| 46 | + setError(null) | |
| 47 | + | |
| 48 | + getFiles(org.id, channel) | |
| 49 | + .then((data) => { | |
| 50 | + if (!cancelled) { | |
| 51 | + setFiles(data) | |
| 52 | + } | |
| 53 | + }) | |
| 54 | + .catch((e: Error) => { | |
| 55 | + if (!cancelled) { | |
| 56 | + setError(e.message) | |
| 57 | + } | |
| 58 | + }) | |
| 59 | + .finally(() => { | |
| 60 | + if (!cancelled) { | |
| 61 | + setLoading(false) | |
| 62 | + } | |
| 63 | + }) | |
| 64 | + | |
| 65 | + return () => { | |
| 66 | + cancelled = true | |
| 67 | + } | |
| 68 | + // eslint-disable-next-line react-hooks/exhaustive-deps | |
| 69 | + }, [channel, org.id, reloadKey]) | |
| 70 | + | |
| 71 | + return ( | |
| 72 | + <div className="p-4"> | |
| 73 | + <div className="flex items-center justify-between gap-2"> | |
| 74 | + <div className="flex gap-2"> | |
| 75 | + <button | |
| 76 | + type="button" | |
| 77 | + disabled={!org.channelIdMj} | |
| 78 | + title={org.channelIdMj ? undefined : '채널 미생성'} | |
| 79 | + onClick={() => setChannel('mj')} | |
| 80 | + className={`rounded-full border px-3 py-1 text-xs ${ | |
| 81 | + channel === 'mj' | |
| 82 | + ? 'border-blue-600 bg-blue-50 font-semibold text-blue-700' | |
| 83 | + : 'border-gray-200 text-gray-500' | |
| 84 | + } disabled:cursor-not-allowed disabled:opacity-40`} | |
| 85 | + > | |
| 86 | + 문정원 | |
| 87 | + </button> | |
| 88 | + <button | |
| 89 | + type="button" | |
| 90 | + disabled={!org.channelIdLaw} | |
| 91 | + title={org.channelIdLaw ? undefined : '채널 미생성'} | |
| 92 | + onClick={() => setChannel('law')} | |
| 93 | + className={`rounded-full border px-3 py-1 text-xs ${ | |
| 94 | + channel === 'law' | |
| 95 | + ? 'border-blue-600 bg-blue-50 font-semibold text-blue-700' | |
| 96 | + : 'border-gray-200 text-gray-500' | |
| 97 | + } disabled:cursor-not-allowed disabled:opacity-40`} | |
| 98 | + > | |
| 99 | + 법률검토 | |
| 100 | + </button> | |
| 101 | + </div> | |
| 102 | + | |
| 103 | + {!bothMissing && ( | |
| 104 | + <button | |
| 105 | + type="button" | |
| 106 | + onClick={() => setReloadKey((k) => k + 1)} | |
| 107 | + className="rounded-md border border-gray-300 px-3 py-1 text-xs text-gray-600 hover:bg-gray-50" | |
| 108 | + > | |
| 109 | + 새로고침 | |
| 110 | + </button> | |
| 111 | + )} | |
| 112 | + </div> | |
| 113 | + | |
| 114 | + {bothMissing ? ( | |
| 115 | + <p className="mt-6 text-center text-sm text-gray-400">채널이 아직 생성되지 않았습니다.</p> | |
| 116 | + ) : ( | |
| 117 | + <div className="mt-3"> | |
| 118 | + {loading && <p className="py-6 text-center text-sm text-gray-400">불러오는 중…</p>} | |
| 119 | + {!loading && error && <p className="py-4 text-sm text-red-600">{error}</p>} | |
| 120 | + {!loading && !error && files.length === 0 && ( | |
| 121 | + <p className="py-6 text-center text-sm text-gray-300">등록된 자료가 없습니다.</p> | |
| 122 | + )} | |
| 123 | + {!loading && !error && files.length > 0 && ( | |
| 124 | + <table className="w-full text-left text-sm"> | |
| 125 | + <thead> | |
| 126 | + <tr className="border-b border-gray-200 text-xs text-gray-400"> | |
| 127 | + <th className="py-2 font-medium">파일명</th> | |
| 128 | + <th className="py-2 font-medium">크기</th> | |
| 129 | + <th className="py-2 font-medium">올린 사람</th> | |
| 130 | + <th className="py-2 font-medium">올린 시각</th> | |
| 131 | + </tr> | |
| 132 | + </thead> | |
| 133 | + <tbody> | |
| 134 | + {files.map((file) => ( | |
| 135 | + <tr key={file.id} className="border-b border-gray-100"> | |
| 136 | + <td className="py-2"> | |
| 137 | + <a href={fileDownloadUrl(file.id)} className="text-blue-600 hover:underline"> | |
| 138 | + {file.name} | |
| 139 | + </a> | |
| 140 | + </td> | |
| 141 | + <td className="py-2 text-gray-600">{humanizeSize(file.size)}</td> | |
| 142 | + <td className="py-2 text-gray-600">{file.uploader}</td> | |
| 143 | + <td className="py-2 text-gray-600">{formatDate(file.createAt)}</td> | |
| 144 | + </tr> | |
| 145 | + ))} | |
| 146 | + </tbody> | |
| 147 | + </table> | |
| 148 | + )} | |
| 149 | + </div> | |
| 150 | + )} | |
| 151 | + </div> | |
| 152 | + ) | |
| 153 | +} |
+++ frontend/src/components/ChannelPosts.test.tsx
... | ... | @@ -0,0 +1,119 @@ |
| 1 | +import { act, render, screen, waitFor } from '@testing-library/react' | |
| 2 | +import { beforeEach, describe, expect, it, vi } from 'vitest' | |
| 3 | +import ChannelPosts from './ChannelPosts' | |
| 4 | +import type { Org, PostView } from '../api/client' | |
| 5 | + | |
| 6 | +const mocks = vi.hoisted(() => ({ | |
| 7 | + getPosts: vi.fn(), | |
| 8 | +})) | |
| 9 | + | |
| 10 | +vi.mock('../api/client', async (importOriginal) => ({ | |
| 11 | + ...(await importOriginal<typeof import('../api/client')>()), | |
| 12 | + getPosts: mocks.getPosts, | |
| 13 | +})) | |
| 14 | + | |
| 15 | +function org(overrides: Partial<Org> = {}): Org { | |
| 16 | + return { | |
| 17 | + id: 1, | |
| 18 | + orgNo: '001', | |
| 19 | + orgName: '국제방송교류재단', | |
| 20 | + status: 'ACTIVE', | |
| 21 | + deptName: null, | |
| 22 | + managerName: null, | |
| 23 | + managerTitle: null, | |
| 24 | + managerPhone: null, | |
| 25 | + managerEmail: null, | |
| 26 | + channelIdMj: 'chan-mj', | |
| 27 | + channelIdLaw: 'chan-law', | |
| 28 | + ...overrides, | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +function post(overrides: Partial<PostView> = {}): PostView { | |
| 33 | + return { | |
| 34 | + id: 'p1', | |
| 35 | + user: '송민지', | |
| 36 | + message: '안녕하세요', | |
| 37 | + createAt: Date.now(), | |
| 38 | + system: false, | |
| 39 | + files: [], | |
| 40 | + ...overrides, | |
| 41 | + } | |
| 42 | +} | |
| 43 | + | |
| 44 | +beforeEach(() => { | |
| 45 | + mocks.getPosts.mockReset() | |
| 46 | + vi.useRealTimers() | |
| 47 | +}) | |
| 48 | + | |
| 49 | +describe('ChannelPosts', () => { | |
| 50 | + it('메시지를 작성자와 본문과 함께 보여준다', async () => { | |
| 51 | + mocks.getPosts.mockResolvedValue([post()]) | |
| 52 | + | |
| 53 | + render(<ChannelPosts org={org()} />) | |
| 54 | + | |
| 55 | + await waitFor(() => { | |
| 56 | + expect(screen.getByText('송민지')).toBeTruthy() | |
| 57 | + expect(screen.getByText('안녕하세요')).toBeTruthy() | |
| 58 | + }) | |
| 59 | + }) | |
| 60 | + | |
| 61 | + it('시스템 메시지는 회색 중앙 정렬 한 줄로 보여준다', async () => { | |
| 62 | + mocks.getPosts.mockResolvedValue([post({ system: true, message: '님이 입장했습니다.' })]) | |
| 63 | + | |
| 64 | + render(<ChannelPosts org={org()} />) | |
| 65 | + | |
| 66 | + await waitFor(() => { | |
| 67 | + const line = screen.getByText('님이 입장했습니다.') | |
| 68 | + expect(line.className).toContain('text-gray-400') | |
| 69 | + expect(line.className).toContain('text-center') | |
| 70 | + }) | |
| 71 | + }) | |
| 72 | + | |
| 73 | + it('3초마다 폴링해서 게시글을 다시 조회한다', async () => { | |
| 74 | + vi.useFakeTimers() | |
| 75 | + mocks.getPosts.mockResolvedValue([]) | |
| 76 | + | |
| 77 | + render(<ChannelPosts org={org()} />) | |
| 78 | + | |
| 79 | + await act(async () => { | |
| 80 | + await vi.advanceTimersByTimeAsync(0) | |
| 81 | + }) | |
| 82 | + expect(mocks.getPosts).toHaveBeenCalledTimes(1) | |
| 83 | + | |
| 84 | + await act(async () => { | |
| 85 | + await vi.advanceTimersByTimeAsync(3000) | |
| 86 | + }) | |
| 87 | + expect(mocks.getPosts).toHaveBeenCalledTimes(2) | |
| 88 | + | |
| 89 | + vi.useRealTimers() | |
| 90 | + }) | |
| 91 | + | |
| 92 | + it('양쪽 채널이 모두 없으면 안내 문구를 보여주고 API를 호출하지 않는다', () => { | |
| 93 | + render(<ChannelPosts org={org({ channelIdMj: null, channelIdLaw: null })} />) | |
| 94 | + | |
| 95 | + expect(screen.getByText('채널이 아직 생성되지 않았습니다.')).toBeTruthy() | |
| 96 | + expect(mocks.getPosts).not.toHaveBeenCalled() | |
| 97 | + }) | |
| 98 | + | |
| 99 | + it('법률검토 채널이 없으면 법률검토 칩이 비활성화된다', async () => { | |
| 100 | + mocks.getPosts.mockResolvedValue([]) | |
| 101 | + render(<ChannelPosts org={org({ channelIdLaw: null })} />) | |
| 102 | + | |
| 103 | + expect(screen.getByRole('button', { name: '법률검토' })).toBeDisabled() | |
| 104 | + await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) | |
| 105 | + }) | |
| 106 | + | |
| 107 | + it('첨부파일 칩의 링크는 다운로드 엔드포인트를 가리킨다', async () => { | |
| 108 | + mocks.getPosts.mockResolvedValue([ | |
| 109 | + post({ files: [{ id: 'f1', name: '보고서.pdf', size: 1200 }] }), | |
| 110 | + ]) | |
| 111 | + | |
| 112 | + render(<ChannelPosts org={org()} />) | |
| 113 | + | |
| 114 | + await waitFor(() => { | |
| 115 | + const link = screen.getByText('보고서.pdf').closest('a') | |
| 116 | + expect(link).toHaveAttribute('href', '/api/files/f1') | |
| 117 | + }) | |
| 118 | + }) | |
| 119 | +}) |
+++ frontend/src/components/ChannelPosts.tsx
... | ... | @@ -0,0 +1,153 @@ |
| 1 | +import { useEffect, useRef, useState } from 'react' | |
| 2 | +import { getPosts, fileDownloadUrl, type ChannelKindKey, type FileRef, type Org, type PostView } from '../api/client' | |
| 3 | + | |
| 4 | +const POLL_INTERVAL_MS = 3000 | |
| 5 | + | |
| 6 | +const timeFormatter = new Intl.DateTimeFormat('ko-KR', { hour: '2-digit', minute: '2-digit' }) | |
| 7 | + | |
| 8 | +function humanizeSize(bytes: number): string { | |
| 9 | + if (bytes < 1024) { | |
| 10 | + return `${bytes} B` | |
| 11 | + } | |
| 12 | + const kb = bytes / 1024 | |
| 13 | + if (kb < 1024) { | |
| 14 | + return `${kb.toFixed(1)} KB` | |
| 15 | + } | |
| 16 | + return `${(kb / 1024).toFixed(1)} MB` | |
| 17 | +} | |
| 18 | + | |
| 19 | +function AttachmentChip({ file }: { file: FileRef }) { | |
| 20 | + return ( | |
| 21 | + <a | |
| 22 | + href={fileDownloadUrl(file.id)} | |
| 23 | + className="inline-flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-2 py-1 text-xs text-gray-600 hover:bg-gray-100" | |
| 24 | + > | |
| 25 | + <span className="font-medium text-gray-700">{file.name}</span> | |
| 26 | + <span className="text-gray-400">({humanizeSize(file.size)})</span> | |
| 27 | + </a> | |
| 28 | + ) | |
| 29 | +} | |
| 30 | + | |
| 31 | +function PostRow({ post }: { post: PostView }) { | |
| 32 | + if (post.system) { | |
| 33 | + return <p className="py-1 text-center text-xs text-gray-400">{post.message}</p> | |
| 34 | + } | |
| 35 | + | |
| 36 | + return ( | |
| 37 | + <div className="py-2"> | |
| 38 | + <div className="flex items-baseline gap-2"> | |
| 39 | + <span className="text-sm font-semibold text-gray-800">{post.user}</span> | |
| 40 | + <span className="text-xs text-gray-400">{timeFormatter.format(new Date(post.createAt))}</span> | |
| 41 | + </div> | |
| 42 | + <p className="mt-0.5 whitespace-pre-wrap text-sm text-gray-700">{post.message}</p> | |
| 43 | + {post.files.length > 0 && ( | |
| 44 | + <div className="mt-1.5 flex flex-wrap gap-1.5"> | |
| 45 | + {post.files.map((f) => ( | |
| 46 | + <AttachmentChip key={f.id} file={f} /> | |
| 47 | + ))} | |
| 48 | + </div> | |
| 49 | + )} | |
| 50 | + </div> | |
| 51 | + ) | |
| 52 | +} | |
| 53 | + | |
| 54 | +/** 기관관리 상세의 게시물 탭. 선택한 채널의 최근 게시글을 3초 간격으로 폴링해서 보여준다. */ | |
| 55 | +export default function ChannelPosts({ org }: { org: Org }) { | |
| 56 | + const bothMissing = !org.channelIdMj && !org.channelIdLaw | |
| 57 | + const [channel, setChannel] = useState<ChannelKindKey>(org.channelIdMj ? 'mj' : 'law') | |
| 58 | + const [posts, setPosts] = useState<PostView[]>([]) | |
| 59 | + const [error, setError] = useState<string | null>(null) | |
| 60 | + | |
| 61 | + const containerRef = useRef<HTMLDivElement>(null) | |
| 62 | + const prevCountRef = useRef(0) | |
| 63 | + | |
| 64 | + useEffect(() => { | |
| 65 | + if (bothMissing) { | |
| 66 | + return | |
| 67 | + } | |
| 68 | + | |
| 69 | + let cancelled = false | |
| 70 | + | |
| 71 | + async function load() { | |
| 72 | + try { | |
| 73 | + const data = await getPosts(org.id, channel) | |
| 74 | + if (!cancelled) { | |
| 75 | + setPosts(data) | |
| 76 | + setError(null) | |
| 77 | + } | |
| 78 | + } catch { | |
| 79 | + if (!cancelled) { | |
| 80 | + setError('연결이 원활하지 않습니다. 재시도 중…') | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + void load() | |
| 86 | + const timer = setInterval(() => void load(), POLL_INTERVAL_MS) | |
| 87 | + return () => { | |
| 88 | + cancelled = true | |
| 89 | + clearInterval(timer) | |
| 90 | + } | |
| 91 | + // eslint-disable-next-line react-hooks/exhaustive-deps | |
| 92 | + }, [channel, org.id]) | |
| 93 | + | |
| 94 | + useEffect(() => { | |
| 95 | + if (posts.length > prevCountRef.current && containerRef.current) { | |
| 96 | + containerRef.current.scrollTop = containerRef.current.scrollHeight | |
| 97 | + } | |
| 98 | + prevCountRef.current = posts.length | |
| 99 | + }, [posts.length]) | |
| 100 | + | |
| 101 | + return ( | |
| 102 | + <div className="p-4"> | |
| 103 | + <div className="flex gap-2"> | |
| 104 | + <button | |
| 105 | + type="button" | |
| 106 | + disabled={!org.channelIdMj} | |
| 107 | + title={org.channelIdMj ? undefined : '채널 미생성'} | |
| 108 | + onClick={() => setChannel('mj')} | |
| 109 | + className={`rounded-full border px-3 py-1 text-xs ${ | |
| 110 | + channel === 'mj' | |
| 111 | + ? 'border-blue-600 bg-blue-50 font-semibold text-blue-700' | |
| 112 | + : 'border-gray-200 text-gray-500' | |
| 113 | + } disabled:cursor-not-allowed disabled:opacity-40`} | |
| 114 | + > | |
| 115 | + 문정원 | |
| 116 | + </button> | |
| 117 | + <button | |
| 118 | + type="button" | |
| 119 | + disabled={!org.channelIdLaw} | |
| 120 | + title={org.channelIdLaw ? undefined : '채널 미생성'} | |
| 121 | + onClick={() => setChannel('law')} | |
| 122 | + className={`rounded-full border px-3 py-1 text-xs ${ | |
| 123 | + channel === 'law' | |
| 124 | + ? 'border-blue-600 bg-blue-50 font-semibold text-blue-700' | |
| 125 | + : 'border-gray-200 text-gray-500' | |
| 126 | + } disabled:cursor-not-allowed disabled:opacity-40`} | |
| 127 | + > | |
| 128 | + 법률검토 | |
| 129 | + </button> | |
| 130 | + </div> | |
| 131 | + | |
| 132 | + {bothMissing ? ( | |
| 133 | + <p className="mt-6 text-center text-sm text-gray-400">채널이 아직 생성되지 않았습니다.</p> | |
| 134 | + ) : ( | |
| 135 | + <> | |
| 136 | + {error && ( | |
| 137 | + <p className="mt-3 rounded-md bg-amber-50 px-3 py-1.5 text-xs text-amber-700">{error}</p> | |
| 138 | + )} | |
| 139 | + <div | |
| 140 | + ref={containerRef} | |
| 141 | + className="mt-3 h-96 overflow-y-auto rounded-lg border border-gray-200 px-3" | |
| 142 | + > | |
| 143 | + {posts.length === 0 ? ( | |
| 144 | + <p className="py-6 text-center text-sm text-gray-300">게시글이 없습니다.</p> | |
| 145 | + ) : ( | |
| 146 | + posts.map((post) => <PostRow key={post.id} post={post} />) | |
| 147 | + )} | |
| 148 | + </div> | |
| 149 | + </> | |
| 150 | + )} | |
| 151 | + </div> | |
| 152 | + ) | |
| 153 | +} |
--- frontend/src/components/OrgOverview.test.tsx
+++ frontend/src/components/OrgOverview.test.tsx
... | ... | @@ -1,7 +1,18 @@ |
| 1 |
-import { fireEvent, render, screen } from '@testing-library/react'
|
|
| 2 |
-import { describe, expect, it } from 'vitest'
|
|
| 1 |
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
| 2 |
+import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
| 3 | 3 |
import OrgOverview from './OrgOverview' |
| 4 | 4 |
import type { Org } from '../api/client'
|
| 5 |
+ |
|
| 6 |
+const mocks = vi.hoisted(() => ({
|
|
| 7 |
+ getPosts: vi.fn(), |
|
| 8 |
+ getFiles: vi.fn(), |
|
| 9 |
+})) |
|
| 10 |
+ |
|
| 11 |
+vi.mock('../api/client', async (importOriginal) => ({
|
|
| 12 |
+ ...(await importOriginal<typeof import('../api/client')>()),
|
|
| 13 |
+ getPosts: mocks.getPosts, |
|
| 14 |
+ getFiles: mocks.getFiles, |
|
| 15 |
+})) |
|
| 5 | 16 |
|
| 6 | 17 |
function org(overrides: Partial<Org> = {}): Org {
|
| 7 | 18 |
return {
|
... | ... | @@ -20,8 +31,13 @@ |
| 20 | 31 |
} |
| 21 | 32 |
} |
| 22 | 33 |
|
| 34 |
+beforeEach(() => {
|
|
| 35 |
+ mocks.getPosts.mockReset().mockResolvedValue([]) |
|
| 36 |
+ mocks.getFiles.mockReset().mockResolvedValue([]) |
|
| 37 |
+}) |
|
| 38 |
+ |
|
| 23 | 39 |
describe('OrgOverview', () => {
|
| 24 |
- it('연번_기관명 헤더와 신청기관 담당자 정보를 보여준다', () => {
|
|
| 40 |
+ it('연번_기관명 헤더와 신청기관 담당자 정보를 보여준다', async () => {
|
|
| 25 | 41 |
render(<OrgOverview org={org()} />)
|
| 26 | 42 |
|
| 27 | 43 |
expect(screen.getByText('001_국제방송교류재단')).toBeTruthy()
|
... | ... | @@ -29,36 +45,55 @@ |
| 29 | 45 |
expect(screen.getByText('송민지 과장')).toBeTruthy()
|
| 30 | 46 |
expect(screen.getByText('02-3475-5434')).toBeTruthy()
|
| 31 | 47 |
expect(screen.getByText('ming@arirang.com')).toBeTruthy()
|
| 48 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 32 | 49 |
}) |
| 33 | 50 |
|
| 34 |
- it('아직 연동 전인 문정원 담당자와 담당 변호사 카드는 자리만 보여준다', () => {
|
|
| 51 |
+ it('아직 연동 전인 문정원 담당자와 담당 변호사 카드는 자리만 보여준다', async () => {
|
|
| 35 | 52 |
render(<OrgOverview org={org()} />)
|
| 36 | 53 |
|
| 37 | 54 |
expect(screen.getByText('문정원 담당자')).toBeTruthy()
|
| 38 | 55 |
expect(screen.getByText('담당 변호사')).toBeTruthy()
|
| 39 | 56 |
expect(screen.getAllByText('추후 연동')).toHaveLength(2)
|
| 57 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 40 | 58 |
}) |
| 41 | 59 |
|
| 42 |
- it('업무단계 12개가 순서대로 보인다', () => {
|
|
| 60 |
+ it('업무단계 12개가 순서대로 보인다', async () => {
|
|
| 43 | 61 |
render(<OrgOverview org={org()} />)
|
| 44 | 62 |
|
| 45 | 63 |
expect(screen.getByText('신청')).toBeTruthy()
|
| 46 | 64 |
expect(screen.getByText('변호사 배당')).toBeTruthy()
|
| 47 | 65 |
expect(screen.getByText('보고서 작성')).toBeTruthy()
|
| 66 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 48 | 67 |
}) |
| 49 | 68 |
|
| 50 |
- it('탭을 누르면 해당 탭의 자리표시 내용으로 바뀐다', () => {
|
|
| 69 |
+ it('기본 탭인 게시물은 자리표시 대신 채널 선택 화면을 보여준다', async () => {
|
|
| 51 | 70 |
render(<OrgOverview org={org()} />)
|
| 52 | 71 |
|
| 53 |
- expect(screen.getByText('게시물 상세 화면은 추후 확정')).toBeTruthy()
|
|
| 72 |
+ expect(screen.getByRole('button', { name: '문정원' })).toBeTruthy()
|
|
| 73 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalledWith(1, 'mj')) |
|
| 74 |
+ }) |
|
| 75 |
+ |
|
| 76 |
+ it('탭을 누르면 해당 탭의 자리표시 내용으로 바뀐다', async () => {
|
|
| 77 |
+ render(<OrgOverview org={org()} />)
|
|
| 78 |
+ |
|
| 79 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 54 | 80 |
|
| 55 | 81 |
fireEvent.click(screen.getByRole('button', { name: '타임라인' }))
|
| 56 | 82 |
|
| 57 | 83 |
expect(screen.getByText('타임라인 상세 화면은 추후 확정')).toBeTruthy()
|
| 58 |
- expect(screen.queryByText('게시물 상세 화면은 추후 확정')).toBeNull()
|
|
| 84 |
+ expect(screen.queryByRole('button', { name: '문정원' })).toBeNull()
|
|
| 59 | 85 |
}) |
| 60 | 86 |
|
| 61 |
- it('채널이 있으면 Mattermost 열기가 채널 링크로 활성화된다', () => {
|
|
| 87 |
+ it('자료 탭을 누르면 자료 목록 화면으로 바뀐다', async () => {
|
|
| 88 |
+ render(<OrgOverview org={org()} />)
|
|
| 89 |
+ |
|
| 90 |
+ fireEvent.click(screen.getByRole('button', { name: '자료' }))
|
|
| 91 |
+ |
|
| 92 |
+ await waitFor(() => expect(mocks.getFiles).toHaveBeenCalledWith(1, 'mj')) |
|
| 93 |
+ expect(screen.getByRole('button', { name: '새로고침' })).toBeTruthy()
|
|
| 94 |
+ }) |
|
| 95 |
+ |
|
| 96 |
+ it('채널이 있으면 Mattermost 열기가 채널 링크로 활성화된다', async () => {
|
|
| 62 | 97 |
render(<OrgOverview org={org()} />)
|
| 63 | 98 |
|
| 64 | 99 |
const link = screen.getByRole('link', { name: 'Mattermost 열기' })
|
... | ... | @@ -66,6 +101,7 @@ |
| 66 | 101 |
'href', |
| 67 | 102 |
'https://hub.iten.co.kr/itn-hub/channels/org-001-mj', |
| 68 | 103 |
) |
| 104 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 69 | 105 |
}) |
| 70 | 106 |
|
| 71 | 107 |
it('채널이 없으면 Mattermost 열기가 비활성이다', () => {
|
... | ... | @@ -75,7 +111,7 @@ |
| 75 | 111 |
expect(screen.getByRole('button', { name: 'Mattermost 열기' })).toBeDisabled()
|
| 76 | 112 |
}) |
| 77 | 113 |
|
| 78 |
- it('치안정책연구소는 policy 채널 링크를 쓴다', () => {
|
|
| 114 |
+ it('치안정책연구소는 policy 채널 링크를 쓴다', async () => {
|
|
| 79 | 115 |
render( |
| 80 | 116 |
<OrgOverview |
| 81 | 117 |
org={org({ orgNo: '008', orgName: '경찰청_치안정책연구소', channelIdMj: 'x' })}
|
... | ... | @@ -86,12 +122,14 @@ |
| 86 | 122 |
'href', |
| 87 | 123 |
'https://hub.iten.co.kr/itn-hub/channels/org-008-policy-mj', |
| 88 | 124 |
) |
| 125 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 89 | 126 |
}) |
| 90 | 127 |
|
| 91 |
- it('미구현 동작 버튼들은 비활성이다', () => {
|
|
| 128 |
+ it('미구현 동작 버튼들은 비활성이다', async () => {
|
|
| 92 | 129 |
render(<OrgOverview org={org()} />)
|
| 93 | 130 |
|
| 94 | 131 |
expect(screen.getByRole('button', { name: '진행단계 변경' })).toBeDisabled()
|
| 95 | 132 |
expect(screen.getByRole('button', { name: '보고서 관리' })).toBeDisabled()
|
| 133 |
+ await waitFor(() => expect(mocks.getPosts).toHaveBeenCalled()) |
|
| 96 | 134 |
}) |
| 97 | 135 |
}) |
--- frontend/src/components/OrgOverview.tsx
+++ frontend/src/components/OrgOverview.tsx
... | ... | @@ -1,5 +1,7 @@ |
| 1 | 1 |
import { useState } from 'react'
|
| 2 | 2 |
import type { Org } from '../api/client'
|
| 3 |
+import ChannelFiles from './ChannelFiles' |
|
| 4 |
+import ChannelPosts from './ChannelPosts' |
|
| 3 | 5 |
import StatusBadge from './StatusBadge' |
| 4 | 6 |
|
| 5 | 7 |
// 기관관리 상세 화면. 3단계 대시보드 시안의 "기관관리" 레이아웃을 따른다. |
... | ... | @@ -189,9 +191,19 @@ |
| 189 | 191 |
</nav> |
| 190 | 192 |
</div> |
| 191 | 193 |
|
| 192 |
- <div className="mt-4 rounded-lg border border-dashed border-gray-200 p-10 text-center text-sm text-gray-400"> |
|
| 193 |
- {activeTab} 상세 화면은 추후 확정
|
|
| 194 |
- </div> |
|
| 194 |
+ {activeTab === '게시물' ? (
|
|
| 195 |
+ <div className="mt-4 rounded-lg border border-gray-200"> |
|
| 196 |
+ <ChannelPosts key={org.id} org={org} />
|
|
| 197 |
+ </div> |
|
| 198 |
+ ) : activeTab === '자료' ? ( |
|
| 199 |
+ <div className="mt-4 rounded-lg border border-gray-200"> |
|
| 200 |
+ <ChannelFiles key={org.id} org={org} />
|
|
| 201 |
+ </div> |
|
| 202 |
+ ) : ( |
|
| 203 |
+ <div className="mt-4 rounded-lg border border-dashed border-gray-200 p-10 text-center text-sm text-gray-400"> |
|
| 204 |
+ {activeTab} 상세 화면은 추후 확정
|
|
| 205 |
+ </div> |
|
| 206 |
+ )} |
|
| 195 | 207 |
</div> |
| 196 | 208 |
</div> |
| 197 | 209 |
) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?