All files / lib/pages/PlayLog index.tsx

0% Statements 0/19
0% Branches 0/6
0% Functions 0/11
0% Lines 0/19

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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132                                                                                                                                                                                                                                                                       
'use client';
 
import { useGetPlayLogsQuery } from '@lib/api/queries';
import { HeaderContainer } from '@lib/components/styledComponents';
import { playStatusToHexCode, playStatusToString } from '@lib/constants/playLog';
import {
  AdminPlayLogDto,
  AdminPlayLogDtoPlayStatusEnum
} from '@uniquegood/realworld-adventure-interface';
import { Table, Tag, Tooltip } from 'antd';
import { ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import React from 'react';
import useModalState from '@lib/hooks/useModalState';
import Filter from './Filter';
import ScoreModal from './Modal/ScoreModal';
 
export default function PlayLogsPage() {
  const [currentPage, setCurrentPage] = React.useState(0);
  const [currentPlayLogId, setCurrentPlayLogId] = React.useState('');
  const [searchData, setSearchData] = React.useState<
    | {
        userId?: string;
        userName?: string;
        treasureId?: string;
        treasureName?: string;
        startedAt?: string;
        endedAt?: string;
      }
    | undefined
  >({});
 
  const {
    openModal: openScoreModal,
    closeModal: closeScoreModal,
    modal: scoreModal
  } = useModalState();
 
  const { data: playLogs, isLoading } = useGetPlayLogsQuery({
    ...searchData,
    page: currentPage,
    size: 20
  });
 
  const columns: ColumnsType<AdminPlayLogDto> = [
    {
      key: 'id',
      dataIndex: 'id',
      title: '로그 ID'
    },
    {
      key: 'userName',
      dataIndex: 'userName',
      title: '유저 이름',
      render: (value, record) => <Tooltip title={record.userId}>{value}</Tooltip>
    },
    {
      key: 'treasureName',
      dataIndex: 'treasureName',
      title: '보물 이름',
      render: (value, record) => <Tooltip title={record.treasureId}>{value}</Tooltip>
    },
    {
      key: 'playStatus',
      dataIndex: 'playStatus',
      title: '플레이 상태',
      align: 'center',
      render: (value: AdminPlayLogDtoPlayStatusEnum) => (
        <Tag color={playStatusToHexCode[value]}>{playStatusToString[value]}</Tag>
      )
    },
    {
      key: 'createdAt',
      dataIndex: 'createdAt',
      title: '접근일',
      render: (value) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-')
    },
    {
      key: 'questionAccessedAt',
      dataIndex: 'questionAccessedAt',
      title: '문제 열람일',
      render: (value) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-')
    },
    {
      key: 'userScoreLogCreatedAt',
      dataIndex: 'userScoreLogCreatedAt',
      title: '보물 획득일',
      render: (value) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-')
    }
  ];
 
  return (
    <>
      <HeaderContainer>
        <h1>플레이 로그</h1>
      </HeaderContainer>
      <Filter
        onSearch={(values) => {
          setCurrentPage(0);
          setSearchData(values);
        }}
      />
      <Table
        columns={columns}
        dataSource={playLogs?.data?.content}
        loading={isLoading}
        scroll={{ x: 'max-content' }}
        pagination={{
          showSizeChanger: false,
          total: playLogs?.data?.totalElements,
          current: currentPage + 1,
          pageSize: 20,
          onChange: (page) => setCurrentPage(page - 1)
        }}
        onRow={(record) => ({
          onClick: () => {
            setCurrentPlayLogId(record.id);
 
            openScoreModal({});
          }
        })}
        rowKey="id"
      />
      <ScoreModal
        modalData={scoreModal}
        closeModal={closeScoreModal}
        playLogId={currentPlayLogId}
      />
    </>
  );
}