All files / pages/admin/ManageAsset/components AssignmentHistory.tsx

100% Statements 14/14
100% Branches 2/2
100% Functions 7/7
100% Lines 14/14

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  3x                 3x 3x 3x 3x     3x   4x         2x             2x                           2x                         2x     4x           12x         3x  
import { AssignmentHistoryDto } from "@/types/Assignment";
import { Table, Typography } from "antd";
 
interface Props {
  data: AssignmentHistoryDto[];
  isLoading?: boolean;
}
function AssignmentHistory({ data, isLoading }: Props) {
  function formatDate(dateInput: Date) {
    // Extract day, month, and year from the date object
    const date = new Date(dateInput);
    const day = String(date.getDate()).padStart(2, "0");
    const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero based
    const year = date.getFullYear();
 
    // Return the formatted date string in DD/MM/YYYY format
    return `${day}/${month}/${year}`;
  }
  const columns = [
    {
      key: "assignedDate",
      title: "Date",
      dataIndex: "assignedDate",
      render: (date: Date) => formatDate(date),
    },
    {
      key: "assignTo",
      title: "Assigned to",
      dataIndex: "assignTo",
      render: (username: string) => (
        <Typography.Paragraph
          ellipsis={{
            expandable: "collapsible",
          }}
        >
          {username}
        </Typography.Paragraph>
      ),
    },
    {
      key: "assignBy",
      title: "Assigned by",
      dataIndex: "assignBy",
      render: (username: string) => (
        <Typography.Paragraph
          ellipsis={{
            expandable: "collapsible",
          }}
        >
          {username}
        </Typography.Paragraph>
      ),
    },
    {
      key: "returnDate",
      title: "Returned Date",
      dataIndex: "returnDate",
      render: (date: Date) => (date ? formatDate(date) : null),
    },
  ];
  return (
    <Table
      columns={columns}
      dataSource={data}
      pagination={false}
      loading={isLoading}
      rowKey={(record) => record.id}
    />
  );
}
 
export default AssignmentHistory;