sales-frontend-components 0.0.143 → 0.0.145
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.
- package/dist/camera/camera.module.scss +2 -0
- package/dist/index.cjs.js +83 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +34 -2
- package/dist/index.esm.js +83 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +12 -12
package/dist/index.cjs.js
CHANGED
|
@@ -4422,6 +4422,88 @@ function DudDownload() {
|
|
|
4422
4422
|
] });
|
|
4423
4423
|
}
|
|
4424
4424
|
|
|
4425
|
+
const useDownloader = () => {
|
|
4426
|
+
const [isError, setIsError] = React.useState(false);
|
|
4427
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
4428
|
+
const downloadFile = async (url, fileName) => {
|
|
4429
|
+
try {
|
|
4430
|
+
const response = await fetch(url);
|
|
4431
|
+
if (!response.ok) {
|
|
4432
|
+
throw new Error(`Failed to download ${url}`);
|
|
4433
|
+
}
|
|
4434
|
+
const blob = await response.blob();
|
|
4435
|
+
const downloadUrl = window.URL.createObjectURL(blob);
|
|
4436
|
+
const a = document.createElement("a");
|
|
4437
|
+
a.href = downloadUrl;
|
|
4438
|
+
a.download = fileName || url.split("/").pop() || "download";
|
|
4439
|
+
document.body.appendChild(a);
|
|
4440
|
+
a.click();
|
|
4441
|
+
a.remove();
|
|
4442
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
4443
|
+
} catch (e) {
|
|
4444
|
+
console.error(e);
|
|
4445
|
+
throw e;
|
|
4446
|
+
}
|
|
4447
|
+
};
|
|
4448
|
+
const onClick = async (downloaderProps) => {
|
|
4449
|
+
const { downloadTargetInfo, onAllSuccess, onAnyError, startIndex = 0 } = downloaderProps;
|
|
4450
|
+
setIsLoading(true);
|
|
4451
|
+
setIsError(false);
|
|
4452
|
+
const failedIndex = [];
|
|
4453
|
+
const targetIndices = [];
|
|
4454
|
+
if (typeof startIndex === "number") {
|
|
4455
|
+
for (let i = startIndex; i < downloadTargetInfo.length; i++) {
|
|
4456
|
+
targetIndices.push(i);
|
|
4457
|
+
}
|
|
4458
|
+
} else if (Array.isArray(startIndex)) {
|
|
4459
|
+
for (let i = 0; i < downloadTargetInfo.length; i++) {
|
|
4460
|
+
if (startIndex.includes(i)) {
|
|
4461
|
+
targetIndices.push(i);
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4465
|
+
for (const i of targetIndices) {
|
|
4466
|
+
const info = downloadTargetInfo[i];
|
|
4467
|
+
if (!info) {
|
|
4468
|
+
continue;
|
|
4469
|
+
}
|
|
4470
|
+
try {
|
|
4471
|
+
let url;
|
|
4472
|
+
if (typeof info.downloadTarget === "function") {
|
|
4473
|
+
url = await info.downloadTarget();
|
|
4474
|
+
} else {
|
|
4475
|
+
url = info.downloadTarget;
|
|
4476
|
+
}
|
|
4477
|
+
if (!url) {
|
|
4478
|
+
throw new Error("Download URL is empty");
|
|
4479
|
+
}
|
|
4480
|
+
await downloadFile(url, info.fileName);
|
|
4481
|
+
info.onSuccess?.();
|
|
4482
|
+
} catch (error) {
|
|
4483
|
+
console.error(`Download failed at index ${i}`, error);
|
|
4484
|
+
info.onError?.();
|
|
4485
|
+
onAnyError?.();
|
|
4486
|
+
setIsError(true);
|
|
4487
|
+
failedIndex.push(i);
|
|
4488
|
+
if (downloaderProps.keepGoingOnError) {
|
|
4489
|
+
continue;
|
|
4490
|
+
}
|
|
4491
|
+
break;
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
if (failedIndex.length === 0) {
|
|
4495
|
+
onAllSuccess?.();
|
|
4496
|
+
}
|
|
4497
|
+
setIsLoading(false);
|
|
4498
|
+
return failedIndex.length === 1 ? failedIndex[0] : failedIndex;
|
|
4499
|
+
};
|
|
4500
|
+
return {
|
|
4501
|
+
onClick,
|
|
4502
|
+
isLoading,
|
|
4503
|
+
isError
|
|
4504
|
+
};
|
|
4505
|
+
};
|
|
4506
|
+
|
|
4425
4507
|
exports.Attachment = Attachment;
|
|
4426
4508
|
exports.BankStockSearchModal = BankStockSearchModal;
|
|
4427
4509
|
exports.CODES = CODES;
|
|
@@ -4449,6 +4531,7 @@ exports.useAddressComponent = useAddressComponent;
|
|
|
4449
4531
|
exports.useBankStockSearch = useBankStockSearch;
|
|
4450
4532
|
exports.useCamera = useCamera;
|
|
4451
4533
|
exports.useCanvasPaint = useCanvasPaint;
|
|
4534
|
+
exports.useDownloader = useDownloader;
|
|
4452
4535
|
exports.useJobSearchModal = useJobSearchModal;
|
|
4453
4536
|
exports.useJobVehicleSearchModal = useJobVehicleSearchModal;
|
|
4454
4537
|
exports.useNationalityComponent = useNationalityComponent;
|