File size: 2,214 Bytes
79278ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Button from "@/components/generics/button/Button";
import { downloadExcel } from "@/shared/utils/downloadExcel";
import { useState } from "react";
import "./Logs.scss";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import { LogRequestType } from "@/api/predictions/types";
import { useGetLogs } from "@/api/predictions/hooks";

const Logs = () => {
  const [startDate, setStartDate] = useState<Date | undefined>(undefined);
  const [endDate, setEndDate] = useState<Date | undefined>(undefined);

  const { mutate, isPending } = useGetLogs();

  const handleDownload = () => {
    const localStartDate = startDate;
    localStartDate?.setHours(0, 0, 0, 0);

    const localEndDate = endDate;
    localEndDate?.setHours(23, 59, 0, 0);

    const data: LogRequestType = {
      date_start: localStartDate?.toISOString(),
      date_end: localEndDate?.toISOString(),
    };

    mutate(data, {
      onSuccess: (data) => {
        downloadExcel(data);
      },
    });
  };

  return (
    <div className="logs_page">
      <h1 className="header">Пользовательские логи</h1>
      <div className="filters">
        <div className="dates_container">
          <div className="date_filter">
            <label htmlFor="startDate">Дата начала</label>
            <DatePicker
              id="startDate"
              dateFormat="dd/MM/yyyy"
              selected={startDate}
              onChange={(date) => setStartDate(date ?? undefined)}
              selectsStart
              isClearable={true}
              showIcon
            />
          </div>
          <div className="date_filter">
            <label htmlFor="endDate">Дата окончания</label>
            <DatePicker
              id="endDate"
              dateFormat="dd/MM/yyyy"
              selected={endDate}
              onChange={(date) => setEndDate(date ?? undefined)}
              selectsEnd
              isClearable={true}
              showIcon
            />
          </div>
        </div>
        <Button name={"Скачать excel"} onClick={handleDownload} loading={isPending} />
      </div>
    </div>
  );
};

export default Logs;