All files / client/components/Admin TopPage.tsx

0% Statements 0/12
0% Branches 0/2
0% Functions 0/4
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                                                                                             
import React, { useContext, useEffect, useState, FC } from 'react'
 
import { AdminContext } from 'components/Admin/AdminPage'
 
interface Info {
  crowiVersion: string | null
  searchInfo: {
    host?: string
    indexName?: string
    esVersion?: string
  }
}
 
function useInfo(crowi) {
  const [info, setInfo] = useState<Info>({ crowiVersion: null, searchInfo: {} })
 
  const fetchInfo = async () => {
    const { crowiVersion, searchInfo } = await crowi.apiGet('/admin/top')
    setInfo({ crowiVersion, searchInfo })
  }
 
  return [info, fetchInfo] as const
}
 
const TopPage: FC<{}> = () => {
  const { crowi, searchConfigured } = useContext(AdminContext)
  const [{ crowiVersion, searchInfo }, fetchInfo] = useInfo(crowi)
  const { host, indexName, esVersion } = searchInfo
 
  useEffect(() => {
    fetchInfo()
  }, [])
 
  return (
    <>
      <p>
        この画面はWiki管理者のみがアクセスできる画面です。
        <br />
        「ユーザー管理」から「管理者にする」ボタンを使ってユーザーをWiki管理者に任命することができます。
      </p>
      <h2>Information</h2>
      <dl className="row">
        <dt className="col-3">Crowi Version</dt>
        <dd className="col-9">{crowiVersion}</dd>
        <dt className="col-3">Search</dt>
        <dd className="col-9">
          {/* TODO: multiple nodes */}
          {searchConfigured ? (
            <>
              Configured: {host}
              {indexName}, <strong>{esVersion}</strong>
            </>
          ) : (
            'Not available.'
          )}
        </dd>
      </dl>
    </>
  )
}
 
export default TopPage