feat: save pdf as file
This commit is contained in:
		@@ -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",
 | 
			
		||||
 
 | 
			
		||||
@@ -284,6 +284,27 @@ export class DealService {
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Get Deal Document
 | 
			
		||||
     * @returns any Successful Response
 | 
			
		||||
     * @throws ApiError
 | 
			
		||||
     */
 | 
			
		||||
    public static getDealDocument({
 | 
			
		||||
        dealId,
 | 
			
		||||
    }: {
 | 
			
		||||
        dealId: number,
 | 
			
		||||
    }): CancelablePromise<any> {
 | 
			
		||||
        return __request(OpenAPI, {
 | 
			
		||||
            method: 'GET',
 | 
			
		||||
            url: '/deal/document/{deal_id}',
 | 
			
		||||
            path: {
 | 
			
		||||
                'deal_id': dealId,
 | 
			
		||||
            },
 | 
			
		||||
            errors: {
 | 
			
		||||
                422: `Validation Error`,
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Services Add
 | 
			
		||||
     * @returns DealAddServicesResponse Successful Response
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Props> = ({deal}) => {
 | 
			
		||||
                                    Ссылка на оплату
 | 
			
		||||
                                </ButtonCopy>
 | 
			
		||||
                                :
 | 
			
		||||
                                <ButtonCopy
 | 
			
		||||
                                    value={`${import.meta.env.VITE_API_URL}/deal/document/${deal.id}`}
 | 
			
		||||
                                <ButtonCopyControlled
 | 
			
		||||
                                    onCopyClick={() => {
 | 
			
		||||
                                        // 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)
 | 
			
		||||
                                </ButtonCopy>
 | 
			
		||||
                                </ButtonCopyControlled>
 | 
			
		||||
                            }
 | 
			
		||||
                            <ButtonCopyControlled
 | 
			
		||||
                                onCopyClick={onCopyGuestUrlClick}
 | 
			
		||||
 
 | 
			
		||||
@@ -57,3 +57,12 @@ export function getDatesBetween(startDate: Date, endDate: Date): dayjs.Dayjs[] {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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("-", "_");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user