@paro.io/expert-shared-components 1.6.3 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ interface ClientDocumentTableProps {
14
14
  expertClientFilesLazyQuery: any;
15
15
  isClientPortal: boolean;
16
16
  documentUploadUrl?: string;
17
+ downloadDocumentUrl?: string;
17
18
  }
18
- export declare const ClientDocumentsTable: ({ legacyFreelancerId, expertFiles, setExpertClientFiles, clientAndProjectsList, uploadExpertClientFiles, paroDocuments, freelancerName, freelancerEmail, updateFileLastViewed, deleteExpertClientFile, getFileLazyQuery, expertClientFilesLazyQuery, isClientPortal, documentUploadUrl }: ClientDocumentTableProps) => JSX.Element;
19
+ export declare const ClientDocumentsTable: ({ legacyFreelancerId, expertFiles, setExpertClientFiles, clientAndProjectsList, uploadExpertClientFiles, paroDocuments, freelancerName, freelancerEmail, updateFileLastViewed, deleteExpertClientFile, getFileLazyQuery, expertClientFilesLazyQuery, isClientPortal, documentUploadUrl, downloadDocumentUrl }: ClientDocumentTableProps) => JSX.Element;
19
20
  export {};
@@ -44,6 +44,7 @@ const DocumentUploadRow_1 = require("./DocumentUploadRow");
44
44
  const base_icons_1 = require("@paro.io/base-icons");
45
45
  const DeleteDocumentModal_1 = require("./DeleteDocumentModal");
46
46
  const utils_1 = require("../shared/utils");
47
+ const DownloadClient_1 = __importDefault(require("../shared/DownloadClient"));
47
48
  exports.useStyles = (0, core_1.makeStyles)({
48
49
  tableCell: {
49
50
  whiteSpace: 'normal',
@@ -134,7 +135,7 @@ const getKeyByValue = (object, value) => {
134
135
  }
135
136
  return Object.keys(object).find(key => object[key] === value);
136
137
  };
137
- const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClientFiles, clientAndProjectsList, uploadExpertClientFiles, paroDocuments, freelancerName, freelancerEmail, updateFileLastViewed, deleteExpertClientFile, getFileLazyQuery, expertClientFilesLazyQuery, isClientPortal, documentUploadUrl }) => {
138
+ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClientFiles, clientAndProjectsList, uploadExpertClientFiles, paroDocuments, freelancerName, freelancerEmail, updateFileLastViewed, deleteExpertClientFile, getFileLazyQuery, expertClientFilesLazyQuery, isClientPortal, documentUploadUrl, downloadDocumentUrl }) => {
138
139
  const classes = (0, exports.useStyles)();
139
140
  const [order, setOrder] = react_1.default.useState('desc');
140
141
  const [orderBy, setOrderBy] = react_1.default.useState('lastViewed');
@@ -230,6 +231,7 @@ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClient
230
231
  });
231
232
  const updateLastViewed = () => __awaiter(void 0, void 0, void 0, function* () {
232
233
  yield updateFileLastViewed({
234
+ skip: !fileId,
233
235
  variables: {
234
236
  input: {
235
237
  fileId: fileId,
@@ -252,7 +254,7 @@ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClient
252
254
  const mimeType = (0, utils_1.getFileMimeType)(downloadFilename);
253
255
  if (mimeType === 'application/pdf') {
254
256
  // handle pdf type files
255
- (0, utils_1.handleDownloadPdf)({ fileData, downloadFilename });
257
+ (0, utils_1.handleDownloadPdf)({ fileData, downloadFilename, streamData: false });
256
258
  updateLastViewed();
257
259
  }
258
260
  else {
@@ -302,13 +304,22 @@ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClient
302
304
  setFileId(null);
303
305
  });
304
306
  };
305
- const handleDownloadFile = (fileName, fileId, projectId) => __awaiter(void 0, void 0, void 0, function* () {
307
+ const handleDownloadFile = (fileName, fileId, projectId, docSize) => __awaiter(void 0, void 0, void 0, function* () {
306
308
  (0, utils_1.showToast)('success', 'Starting File Download...');
307
309
  fileId && setFileId(fileId);
308
- if (fileName) {
309
- setDownloadFilename(fileName);
310
- const folderName = `project-${projectId}`;
311
- yield getFileData({ fileName, folderName });
310
+ if (docSize >= 5) {
311
+ const downloadFileName = `project-${projectId}/${fileName}`;
312
+ const downloadClient = new DownloadClient_1.default({ downloadDocumentUrl: downloadDocumentUrl || 'https://veaaink7zzzyaeuxuikl7ackza0iyoym.lambda-url.us-east-1.on.aws/', fileKey: downloadFileName });
313
+ const downloadData = yield downloadClient.downloadDocument();
314
+ (0, utils_1.handleDownloadPdf)({ fileData: downloadData, downloadFilename: fileName, streamData: true });
315
+ updateLastViewed();
316
+ }
317
+ else {
318
+ if (fileName) {
319
+ setDownloadFilename(fileName);
320
+ const folderName = `project-${projectId}`;
321
+ yield getFileData({ fileName, folderName });
322
+ }
312
323
  }
313
324
  });
314
325
  const toggleDeleteModal = (fileName, fileId) => {
@@ -339,7 +350,7 @@ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClient
339
350
  return (react_1.default.createElement(core_1.TableRow, { key: fileId },
340
351
  react_1.default.createElement(core_1.TableCell, { className: classes.tableCell, align: "center" }, index + 1),
341
352
  react_1.default.createElement(core_1.TableCell, { className: classes.tableCell, align: "center" },
342
- react_1.default.createElement("a", { onClick: () => handleDownloadFile(fileName, fileId, projectId), style: {
353
+ react_1.default.createElement("a", { onClick: () => handleDownloadFile(fileName, fileId, projectId, docSize), style: {
343
354
  color: 'blue',
344
355
  textDecoration: 'underline',
345
356
  cursor: 'pointer',
@@ -357,7 +368,7 @@ const ClientDocumentsTable = ({ legacyFreelancerId, expertFiles, setExpertClient
357
368
  react_1.default.createElement(core_1.TableCell, { className: classes.tableCell },
358
369
  react_1.default.createElement(core_1.Grid, { item: true, container: true, direction: "row", justify: "space-evenly", alignItems: "center" },
359
370
  react_1.default.createElement(core_1.Tooltip, { arrow: true, placement: "top", interactive: true, className: "whitespace-nowrap", title: "Download Document" },
360
- react_1.default.createElement(core_1.IconButton, { onClick: () => __awaiter(void 0, void 0, void 0, function* () { return handleDownloadFile(fileName, fileId, projectId); }) },
371
+ react_1.default.createElement(core_1.IconButton, { onClick: () => __awaiter(void 0, void 0, void 0, function* () { return handleDownloadFile(fileName, fileId, projectId, docSize); }) },
361
372
  " ",
362
373
  react_1.default.createElement(base_icons_1.IconDocumentDownload, { size: "sm" }),
363
374
  " ")),
@@ -168,7 +168,7 @@ const ParoDocumentsTable = ({ legacyFreelancerId, expiryDate, setExpiryDate, exp
168
168
  const mimeType = (0, utils_1.getFileMimeType)(downloadFilename);
169
169
  if (mimeType === 'application/pdf') {
170
170
  //handle pdf type files
171
- (0, utils_1.handleDownloadPdf)({ fileData, downloadFilename });
171
+ (0, utils_1.handleDownloadPdf)({ fileData, downloadFilename, streamData: false });
172
172
  }
173
173
  else {
174
174
  // handle other type files
@@ -0,0 +1,6 @@
1
+ export default class DownloadClient {
2
+ fileKey: string;
3
+ downloadDocumentUrl: string;
4
+ constructor(props: any);
5
+ downloadDocument(): Promise<any>;
6
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ class DownloadClient {
13
+ constructor(props) {
14
+ this.downloadDocumentUrl = props.downloadDocumentUrl;
15
+ this.fileKey = props.fileKey;
16
+ }
17
+ downloadDocument() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ try {
20
+ const response = yield fetch(`${this.downloadDocumentUrl}`, {
21
+ method: 'POST',
22
+ body: JSON.stringify({ key: this.fileKey }),
23
+ });
24
+ if (!response.body) {
25
+ throw new Error('ReadableStream not supported in this environment.');
26
+ }
27
+ const reader = response.body.getReader();
28
+ const chunks = [];
29
+ while (true) {
30
+ const { done, value } = yield reader.read();
31
+ if (done)
32
+ break;
33
+ chunks.push(value);
34
+ }
35
+ const blob = new Blob(chunks);
36
+ const contentType = response.headers.get('Content-Type');
37
+ if (contentType && contentType.includes('application/json')) {
38
+ const text = yield blob.text();
39
+ return JSON.parse(text);
40
+ }
41
+ else if (contentType && contentType.includes('text/')) {
42
+ return yield blob.text();
43
+ }
44
+ else {
45
+ return blob;
46
+ }
47
+ }
48
+ catch (error) {
49
+ console.log(`Error Downloading Document ${error}`);
50
+ }
51
+ });
52
+ }
53
+ }
54
+ exports.default = DownloadClient;
@@ -7,9 +7,10 @@ export declare const stateAbbreviationMap: {
7
7
  [key: string]: string;
8
8
  };
9
9
  export declare const getFileMimeType: (filename: string) => "application/pdf" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-powerpoint" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "text/csv" | "application/octet-stream";
10
- export declare const handleDownloadPdf: ({ fileData, downloadFilename, }: {
10
+ export declare const handleDownloadPdf: ({ fileData, downloadFilename, streamData }: {
11
11
  fileData: any;
12
12
  downloadFilename: string;
13
+ streamData: boolean;
13
14
  }) => void;
14
15
  export declare const CustomPaper: React.ComponentType<Pick<import("@material-ui/core").PaperProps, "variant" | "id" | "square" | "color" | "content" | "translate" | "hidden" | "slot" | "style" | "title" | "dir" | "rel" | "accessKey" | "draggable" | "lang" | "prefix" | "role" | "children" | "contentEditable" | "enterKeyHint" | "inputMode" | "nonce" | "tabIndex" | "ref" | "suppressHydrationWarning" | "elevation" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "autoCapitalize" | "autoFocus" | "contextMenu" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "component" | "innerRef"> & import("@material-ui/core").StyledComponentProps<"root"> & {
15
16
  className?: string;
@@ -133,14 +133,17 @@ const getFileMimeType = (filename) => {
133
133
  }
134
134
  };
135
135
  exports.getFileMimeType = getFileMimeType;
136
- const handleDownloadPdf = ({ fileData, downloadFilename, }) => {
136
+ const handleDownloadPdf = ({ fileData, downloadFilename, streamData }) => {
137
137
  var _a, _b;
138
- const byteCharacters = atob((_b = (_a = fileData === null || fileData === void 0 ? void 0 : fileData.data) === null || _a === void 0 ? void 0 : _a.getFile) === null || _b === void 0 ? void 0 : _b.data);
139
- const byteNumbers = new Array(byteCharacters.length);
140
- for (let i = 0; i < byteCharacters.length; i++) {
141
- byteNumbers[i] = byteCharacters.charCodeAt(i);
138
+ let byteArray = streamData ? fileData : new Uint8Array();
139
+ if (!streamData) {
140
+ const byteCharacters = atob(fileData || ((_b = (_a = fileData === null || fileData === void 0 ? void 0 : fileData.data) === null || _a === void 0 ? void 0 : _a.getFile) === null || _b === void 0 ? void 0 : _b.data));
141
+ const byteNumbers = new Array(byteCharacters.length);
142
+ for (let i = 0; i < byteCharacters.length; i++) {
143
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
144
+ }
145
+ byteArray = new Uint8Array(byteNumbers);
142
146
  }
143
- const byteArray = new Uint8Array(byteNumbers);
144
147
  const blob = new Blob([byteArray], { type: 'application/pdf' });
145
148
  const blobUrl = URL.createObjectURL(blob);
146
149
  const newTab = window.open(blobUrl, '_blank');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paro.io/expert-shared-components",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {