KickboardHistoryTable.jsx 1.63 KB
import React from "react";
import {Table} from "react-bootstrap";
import { Card } from "components/Card/Card.jsx";
import { tdArray } from "variables/Variables.jsx";

const UserDataKey = {
  user_id: '유저ID',
  rent_datetime: '대여 시각',
  return_datetime: '반납 시각',
  rental_time: '대여 시간',
  rental_distance: '이동 거리',
  rental_fee: '대여 금액',
};

function timestampToString(stamp) {
  if (!stamp) return '';
  const date = stamp.split('T')[0];
  const time = stamp.split('T')[1].split('.')[0];

  return `${date} ${time}`;
}

const KickboardHistoryTable = (props) => {
  const {kbId, historyData} = props;

  return (
    <Card
      title={`${kbId}번 킥보드 사용자 히스토리`}
      ctTableFullWidth
      ctTableResponsive
      content={
        <Table striped hover>
          <thead>
          <tr>
            {Object.values(UserDataKey).map((prop, key) => {
              return <th key={key}>{prop}</th>;
            })}
          </tr>
          </thead>
          <tbody>
          {historyData.map((data, idx) => {
            const {user_id, rent_datetime, return_datetime, rental_time, rental_distance, rental_fee} = data;

            return (
              <tr key={idx}>
                <td>{user_id}</td>
                <td>{timestampToString(rent_datetime)}</td>
                <td>{timestampToString(return_datetime)}</td>
                <td>{rental_time}</td>
                <td>{rental_distance}km</td>
                <td>{rental_fee}</td>
              </tr>
            );
          })}
          </tbody>
        </Table>
      }
    />
  )
};

export default KickboardHistoryTable;