diff --git a/package.json b/package.json index 89fbe6a..1a375ed 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "cyrillic-to-translit-js": "^3.2.1", "dayjs": "^1.11.12", "dot-object": "^2.1.5", + "file-saver": "^2.0.5", "framer-motion": "^11.3.8", "globals": "^15.8.0", "jwt-decode": "^4.0.0", @@ -51,6 +52,7 @@ "@eslint/js": "^9.7.0", "@types/dot-object": "^2.1.6", "@types/eslint__js": "^8.42.3", + "@types/file-saver": "^2.0.7", "@types/lodash": "^4.17.7", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", diff --git a/src/client/services/DealService.ts b/src/client/services/DealService.ts index 455dfc3..e8bf4d4 100644 --- a/src/client/services/DealService.ts +++ b/src/client/services/DealService.ts @@ -284,6 +284,27 @@ export class DealService { }, }); } + /** + * Get Deal Document + * @returns any Successful Response + * @throws ApiError + */ + public static getDealDocument({ + dealId, + }: { + dealId: number, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/deal/document/{deal_id}', + path: { + 'deal_id': dealId, + }, + errors: { + 422: `Validation Error`, + }, + }); + } /** * Services Add * @returns DealAddServicesResponse Successful Response diff --git a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx index 81df584..8d71a7a 100644 --- a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx +++ b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx @@ -12,6 +12,8 @@ import ShippingWarehouseAutocomplete import {ButtonCopyControlled} from "../../../../../components/ButtonCopyControlled/ButtonCopyControlled.tsx"; import {useClipboard} from "@mantine/hooks"; import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx"; +import FileSaver from "file-saver"; +import {getCurrentDateTimeForFilename} from "../../../../../shared/lib/date.ts"; type Props = { deal: DealSchema @@ -166,12 +168,20 @@ const Content: FC = ({deal}) => { Ссылка на оплату : - { + // get current datetime for filename, replaced dots with _ + const date = getCurrentDateTimeForFilename(); + + + FileSaver.saveAs(`${import.meta.env.VITE_API_URL}/deal/document/${deal.id}`, + `bill_${deal.id}_${date}.pdf`); + }} + copied={false} onCopiedLabel={"Ссылка скопирована в буфер обмена"} > Ссылка на оплату (PDF) - + } (day === 6) || (day === 0); \ No newline at end of file +export const isWeekend = (day: number) => (day === 6) || (day === 0); + +export const getCurrentDateTimeForFilename = () => new Date() + .toISOString() + .replace(/:/g, '_') + .replace(/\./g, '_') + .replace("T", "") + .slice(0, -2) + .replace("-", "_"); +