@bindu-dashing/dam-solution-v2 5.8.74 → 5.8.78
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.
|
@@ -17,8 +17,9 @@ import TestImageFromMetalData from "./TestImgFromMetaData";
|
|
|
17
17
|
import { getFormattedValue } from "../hocs/helpers";
|
|
18
18
|
import { createApiClient } from "../hocs/configureAxios";
|
|
19
19
|
import { useDamConfig } from "../hocs/DamConfigContext";
|
|
20
|
-
import { FETCH_ASSET_URL, FETCH_SHARED_FILE_URL, } from "../utilities/constants/apiUrls";
|
|
20
|
+
import { FETCH_ASSET_URL, FETCH_SHARED_FILE_URL, FETCH_SHOPIFY_PRODUCT_DETAIL_URL, } from "../utilities/constants/apiUrls";
|
|
21
21
|
import { FoldersProvider } from "../utilities/FoldersContext";
|
|
22
|
+
import axios from "axios";
|
|
22
23
|
function TestImagePickerModal({ imagePicker, open, toggleModal, setSelectedFile, searchOnly, }) {
|
|
23
24
|
const [state, setState] = useState({
|
|
24
25
|
parentFolderId: get(imagePicker, "folderId"),
|
|
@@ -29,22 +30,57 @@ function TestImagePickerModal({ imagePicker, open, toggleModal, setSelectedFile,
|
|
|
29
30
|
const damConfig = useDamConfig();
|
|
30
31
|
const api = useMemo(() => createApiClient(damConfig), [damConfig]);
|
|
31
32
|
const { parentFolderId, fileForConfirmation } = state;
|
|
33
|
+
// Check if this is a Shopify product (has shopifyProduct data)
|
|
34
|
+
const isShopifyProduct = !!get(fileForConfirmation, "shopifyProduct");
|
|
35
|
+
// Extract numeric product ID from Shopify ID format: "gid://shopify/Product/8145266835769" -> "8145266835769"
|
|
36
|
+
const extractShopifyProductId = (shopifyId) => {
|
|
37
|
+
if (!shopifyId)
|
|
38
|
+
return "";
|
|
39
|
+
const parts = shopifyId.split("/");
|
|
40
|
+
return parts[parts.length - 1] || shopifyId;
|
|
41
|
+
};
|
|
42
|
+
const onSelectShopifyProduct = () => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
try {
|
|
44
|
+
const shopifyProduct = get(fileForConfirmation, "shopifyProduct", {});
|
|
45
|
+
const productId = extractShopifyProductId((shopifyProduct === null || shopifyProduct === void 0 ? void 0 : shopifyProduct.id) || get(fileForConfirmation, "_id", ""));
|
|
46
|
+
console.log("Fetching Shopify product details for:", productId);
|
|
47
|
+
// Static token for Shopify API access
|
|
48
|
+
const shopifyStaticToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTAyOSwicGVybWlzc2lvbnMiOiJbe1wicmVzb3VyY2VfaWRcIjoyLFwiYWNjZXNzXCI6W1wicmVhZFwiXX0se1wicmVzb3VyY2VfaWRcIjoxLFwiYWNjZXNzXCI6W1wicmVhZFwiXX0se1wicmVzb3VyY2VfaWRcIjo1LFwiYWNjZXNzXCI6W1wiY3JlYXRlXCJdfSx7XCJyZXNvdXJjZV9pZFwiOjUsXCJhY2Nlc3NcIjpbXCJyZWFkXCJdfSx7XCJyZXNvdXJjZV9pZFwiOjUsXCJhY2Nlc3NcIjpbXCJ1cGRhdGVcIl19XSIsInRlYW1zIjoiWzE1OCwxNjUsMTA0XSIsInRlYW1JRCI6MTU4LCJicmFuZFRlYW1JRCI6MTA0LCJ0aGVtZUlEIjoxLCJlbWFpbCI6Im1haGVuZHJha29uZGFkYXN1QGdtYWlsLmNvbSIsImZpcnN0TmFtZSI6Ik1haGVuZHJhIiwibGFzdE5hbWUiOiJLb25kYWRhc3UiLCJpYXQiOjE3NjUyNjE1MzIsImV4cCI6MTc2NTMyMTUzMn0.1KcLUytTQQ2cqqOfNwuMt8vIdm1mJMv5mZZtCC9M1KA";
|
|
49
|
+
const response = yield axios.get(`https://staging-api.dashingone.com.au${FETCH_SHOPIFY_PRODUCT_DETAIL_URL.replace(":productId", productId)}`, {
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${shopifyStaticToken}`,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
console.log("Shopify product detail response:", response.data);
|
|
55
|
+
// Get product data from response
|
|
56
|
+
const productData = get(response, "data.data", get(response, "data", {}));
|
|
57
|
+
// Get image URL from image.src
|
|
58
|
+
const thumbnailUrl = get(productData, "image.src", get(productData, "images[0].src", fileForConfirmation === null || fileForConfirmation === void 0 ? void 0 : fileForConfirmation.thumbnailUrl));
|
|
59
|
+
// Pass the thumbnail URL and product title as value
|
|
60
|
+
setSelectedFile(thumbnailUrl, get(productData, "title", ""));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error("Error fetching Shopify product details:", error);
|
|
64
|
+
// Fallback to using existing data
|
|
65
|
+
setSelectedFile((fileForConfirmation === null || fileForConfirmation === void 0 ? void 0 : fileForConfirmation.thumbnailUrl) || "", get(fileForConfirmation, "shopifyProduct.title", ""));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
32
68
|
const onSelectFile = () => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
//
|
|
69
|
+
// If it's a Shopify product, use the Shopify API
|
|
70
|
+
if (isShopifyProduct) {
|
|
71
|
+
return onSelectShopifyProduct();
|
|
72
|
+
}
|
|
73
|
+
// Original DAM file selection logic
|
|
34
74
|
const response = yield api.get(FETCH_SHARED_FILE_URL.replace(":fileId", get(fileForConfirmation, "_id")));
|
|
35
|
-
// console.log(response);
|
|
36
75
|
const fileData = get(response, "data");
|
|
37
76
|
const assetId = get(fileData, "assetId");
|
|
38
77
|
const assetTypeResponse = yield api.get(FETCH_ASSET_URL.replace(":assetId", assetId));
|
|
39
78
|
const imagePickerOutputFormat = get(assetTypeResponse, "data.imagePickerOutputFormat", []);
|
|
40
79
|
const metadataFields = get(assetTypeResponse, "data.metadataFields", []);
|
|
41
|
-
// console.log(imagePickerOutputFormat);
|
|
42
80
|
const formattedOutputFormat = imagePickerOutputFormat.map((field) => {
|
|
43
|
-
// console.log("field", field);
|
|
44
81
|
const metaField = metadataFields.find((item) => (item === null || item === void 0 ? void 0 : item.name) == (field === null || field === void 0 ? void 0 : field.name));
|
|
45
82
|
return Object.assign(Object.assign({}, field), { fieldId: get(metaField, "_id") });
|
|
46
83
|
});
|
|
47
|
-
// console.log(formattedOutputFormat);
|
|
48
84
|
const value = getFormattedValue(formattedOutputFormat, fileForConfirmation === null || fileForConfirmation === void 0 ? void 0 : fileForConfirmation.s3Url, get(fileData, "metadata", {}));
|
|
49
85
|
console.log(value);
|
|
50
86
|
setSelectedFile(fileForConfirmation === null || fileForConfirmation === void 0 ? void 0 : fileForConfirmation.thumbnailUrl, value);
|
|
@@ -59,6 +95,6 @@ function TestImagePickerModal({ imagePicker, open, toggleModal, setSelectedFile,
|
|
|
59
95
|
if (localFile) {
|
|
60
96
|
setSelectedFile(get(file, "s3Url", ""), get(file, "thumbnailUrl", ""));
|
|
61
97
|
}
|
|
62
|
-
}, parentFolderId: parentFolderId, setParentFolderId: (id) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { parentFolderId: id, fileForConfirmation: {} }))), pickerFolderId: get(imagePicker, "folderId"), selectedPickerFile: fileForConfirmation, imagePicker: imagePicker, globalSearch: globalSearch, setGlobalSearch: setGlobalSearch, searchOnly: searchOnly }) })) }));
|
|
98
|
+
}, parentFolderId: parentFolderId, setParentFolderId: (id) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { parentFolderId: id, fileForConfirmation: {} }))), pickerFolderId: get(imagePicker, "folderId"), selectedPickerFile: fileForConfirmation, imagePicker: imagePicker, globalSearch: globalSearch, setGlobalSearch: setGlobalSearch, searchOnly: searchOnly, shopifyMode: searchOnly }) })) }));
|
|
63
99
|
}
|
|
64
100
|
export default TestImagePickerModal;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SetStateAction } from "react";
|
|
2
2
|
import { FileEntity, ImagePickerEntity } from "../utilities/constants/interface";
|
|
3
|
-
declare function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pickerFolderId, selectedPickerFile, imagePicker, globalSearch, setGlobalSearch, setSelectedKeys, searchOnly, }: {
|
|
3
|
+
declare function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pickerFolderId, selectedPickerFile, imagePicker, globalSearch, setGlobalSearch, setSelectedKeys, searchOnly, shopifyMode, }: {
|
|
4
4
|
parentFolderId?: string;
|
|
5
5
|
setSelectedFile?: (file: FileEntity, localFile?: boolean) => void;
|
|
6
6
|
setParentFolderId?: (id: string) => void;
|
|
@@ -11,5 +11,6 @@ declare function DriveContainer({ parentFolderId, setSelectedFile, setParentFold
|
|
|
11
11
|
setGlobalSearch?: React.Dispatch<SetStateAction<string>>;
|
|
12
12
|
setSelectedKeys?: (keys: string | string[]) => void;
|
|
13
13
|
searchOnly?: boolean;
|
|
14
|
+
shopifyMode?: boolean;
|
|
14
15
|
}): JSX.Element;
|
|
15
16
|
export default DriveContainer;
|
|
@@ -37,9 +37,11 @@ import useAppParams from "../utilities/useAppParams";
|
|
|
37
37
|
import { IoIosSearch } from "react-icons/io";
|
|
38
38
|
const BsUploadIcon = BsUpload;
|
|
39
39
|
const IoIosSearchIcon = IoIosSearch;
|
|
40
|
-
function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pickerFolderId, selectedPickerFile, imagePicker, globalSearch, setGlobalSearch, setSelectedKeys, searchOnly, }) {
|
|
40
|
+
function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pickerFolderId, selectedPickerFile, imagePicker, globalSearch, setGlobalSearch, setSelectedKeys, searchOnly, shopifyMode, }) {
|
|
41
41
|
const damConfig = useDamConfig();
|
|
42
|
-
const { rootFolderId, brand, isAdmin
|
|
42
|
+
const { rootFolderId, brand, isAdmin } = damConfig;
|
|
43
|
+
// Use shopifyMode prop directly (passed from parent), fallback to context value
|
|
44
|
+
const shopifySearchMode = shopifyMode || damConfig.shopifySearchMode;
|
|
43
45
|
const brandId = get(brand, "_id");
|
|
44
46
|
const { folderId, type, id } = useAppParams();
|
|
45
47
|
const api = useMemo(() => createApiClient(damConfig), [damConfig]);
|
|
@@ -272,19 +274,26 @@ function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pi
|
|
|
272
274
|
const products = get(response, "data.data.products", get(response, "data.products", []));
|
|
273
275
|
console.log("Shopify products response:", response.data);
|
|
274
276
|
console.log("Extracted products:", products);
|
|
275
|
-
const transformedProducts = (Array.isArray(products) ? products : []).map((product) =>
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
277
|
+
const transformedProducts = (Array.isArray(products) ? products : []).map((product) => {
|
|
278
|
+
// Get price from first variant
|
|
279
|
+
const price = get(product, "variants[0].price", "");
|
|
280
|
+
const formattedPrice = price ? `$${price}` : "";
|
|
281
|
+
return {
|
|
282
|
+
_id: product.id || product._id || `shopify-${Date.now()}-${Math.random()}`,
|
|
283
|
+
name: product.title || product.name || "Unknown Product",
|
|
284
|
+
thumbnailUrl: product.image || product.thumbnailUrl || "",
|
|
285
|
+
s3Url: product.image || product.s3Url || "",
|
|
286
|
+
type: EntityType.FILE,
|
|
287
|
+
fileType: "jpeg",
|
|
288
|
+
createdAt: product.created_at || product.createdAt || new Date().toISOString(),
|
|
289
|
+
updatedAt: product.updated_at || product.updatedAt || new Date().toISOString(),
|
|
290
|
+
size: 0,
|
|
291
|
+
// Add price as assetName to display it in the grid
|
|
292
|
+
assetName: formattedPrice,
|
|
293
|
+
// Keep original product data for reference
|
|
294
|
+
shopifyProduct: product,
|
|
295
|
+
};
|
|
296
|
+
});
|
|
288
297
|
setState((prevState) => (Object.assign(Object.assign({}, prevState), { shopifyProducts: transformedProducts, shopifyLoading: false })));
|
|
289
298
|
}
|
|
290
299
|
catch (error) {
|
|
@@ -94,3 +94,4 @@ export declare const GET_BASE64_USING_PATH_URL = "/files/blob";
|
|
|
94
94
|
export declare const FETCH_FILE_DOWNLOAD_LOGS_URL = "/dashboard/download-summary";
|
|
95
95
|
export declare const FETCH_USER_DOWNLOAD_LOGS_URL = "/dashboard/download-summary/user";
|
|
96
96
|
export declare const FETCH_SHOPIFY_PRODUCTS_URL = "/api/products/shopify";
|
|
97
|
+
export declare const FETCH_SHOPIFY_PRODUCT_DETAIL_URL = "/api/products/shopify/:productId";
|
|
@@ -115,3 +115,4 @@ export const FETCH_FILE_DOWNLOAD_LOGS_URL = "/dashboard/download-summary";
|
|
|
115
115
|
export const FETCH_USER_DOWNLOAD_LOGS_URL = "/dashboard/download-summary/user";
|
|
116
116
|
// Shopify products (external API - uses core API URL)
|
|
117
117
|
export const FETCH_SHOPIFY_PRODUCTS_URL = "/api/products/shopify";
|
|
118
|
+
export const FETCH_SHOPIFY_PRODUCT_DETAIL_URL = "/api/products/shopify/:productId";
|