From 871aa8efe393d038e911baa36a3b25d1e98b0e96 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 11 Oct 2024 21:40:36 +0300 Subject: [PATCH] feat: export services --- src/client/models/ServiceSchema.ts | 2 +- src/client/services/ServiceService.ts | 33 +++++++++ src/pages/ServicesPage/ui/ServicesPage.tsx | 81 ++++++++++++++++++---- 3 files changed, 102 insertions(+), 14 deletions(-) diff --git a/src/client/models/ServiceSchema.ts b/src/client/models/ServiceSchema.ts index 1be8c70..a82419c 100644 --- a/src/client/models/ServiceSchema.ts +++ b/src/client/models/ServiceSchema.ts @@ -15,6 +15,6 @@ export type ServiceSchema = { categoryPrices: Array; cost: (number | null); rank: string; - isPlaceholder?: boolean; + isPlaceholder?: (boolean | null); }; diff --git a/src/client/services/ServiceService.ts b/src/client/services/ServiceService.ts index c9479e9..088e3f3 100644 --- a/src/client/services/ServiceService.ts +++ b/src/client/services/ServiceService.ts @@ -138,6 +138,17 @@ export class ServiceService { }, }); } + /** + * Get Price List + * @returns any Successful Response + * @throws ApiError + */ + public static getPriceList(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/service/price-list', + }); + } /** * Get All Categories * @returns ServiceGetAllCategoriesResponse Successful Response @@ -362,4 +373,26 @@ export class ServiceService { }, }); } + /** + * Export List Pdf + * @returns any Successful Response + * @throws ApiError + */ + public static exportListPdf(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/service/export-list/pdf', + }); + } + /** + * Export List Excel + * @returns any Successful Response + * @throws ApiError + */ + public static exportListExcel(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/service/export-list/excel', + }); + } } diff --git a/src/pages/ServicesPage/ui/ServicesPage.tsx b/src/pages/ServicesPage/ui/ServicesPage.tsx index e1e22b9..e8d9a72 100644 --- a/src/pages/ServicesPage/ui/ServicesPage.tsx +++ b/src/pages/ServicesPage/ui/ServicesPage.tsx @@ -2,7 +2,7 @@ import { FC, useState } from "react"; import ServicesTable from "../components/ServicesTable/ServicesTable.tsx"; import PageBlock from "../../../components/PageBlock/PageBlock.tsx"; import styles from "./ServicesPage.module.css"; -import { Button, Flex, rem, Switch } from "@mantine/core"; +import { Button, Flex, Popover, rem, Switch } from "@mantine/core"; import ServiceTypeSegmentedControl, { ServicesTab, } from "../components/ServiceTypeSegmentedControl/ServiceTypeSegmentedControl.tsx"; @@ -12,6 +12,9 @@ import useServicesState from "../hooks/useServicesState.tsx"; import useServicesKitsState from "../hooks/useServicesKitsState.tsx"; import useServicePriceCategoryState from "../hooks/useServicePriceCategoryState.tsx"; import { ObjectStateToTableProps } from "../../../types/utils.ts"; +import { IconDownload, IconFileExcel, IconFileTypePdf } from "@tabler/icons-react"; +import FileSaver from "file-saver"; +import { getCurrentDateTimeForFilename } from "../../../shared/lib/date.ts"; export const ServicesPage: FC = () => { const [serviceType, setServiceType] = useState(ServicesTab.DEAL_SERVICE); @@ -65,7 +68,6 @@ export const ServicesPage: FC = () => { ); } }; - const getControls = () => { switch (serviceType) { case ServicesTab.SERVICES_KITS: @@ -80,22 +82,62 @@ export const ServicesPage: FC = () => { case ServicesTab.PRODUCT_SERVICE: return ( - - +
+ + + + + + + + + + + + + + + + +
+ setIsEditMode(!isEditMode)} - />
); @@ -113,6 +155,19 @@ export const ServicesPage: FC = () => { ); } }; + + const onDownloadPdfClick = () => { + const date = getCurrentDateTimeForFilename(); + FileSaver.saveAs(`${import.meta.env.VITE_API_URL}/service/export-list/pdf`, + `прайс_лист_${date}.pdf`, + ); + }; + const onDownloadExcelClick = () => { + const date = getCurrentDateTimeForFilename(); + FileSaver.saveAs(`${import.meta.env.VITE_API_URL}/service/export-list/excel`, + `прайс_лист_${date}.xlsx`, + ); + }; return (