@bindu-dashing/dam-solution-v2 5.8.73 → 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
- // console.log(fileForConfirmation);
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, coreApiUrl, coreApiToken, shopifySearchMode } = damConfig;
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]);
@@ -244,26 +246,27 @@ function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pi
244
246
  }, [brandId]);
245
247
  // Fetch Shopify products when in shopify search mode
246
248
  useEffect(() => {
247
- console.log("Shopify search effect - shopifySearchMode:", shopifySearchMode, "coreApiToken:", !!coreApiToken, "folderSearch:", folderSearch);
248
- // Only require coreApiToken (not coreApiUrl since we have a fallback)
249
- if (shopifySearchMode && coreApiToken && folderSearch && folderSearch.length >= 2) {
249
+ console.log("Shopify search effect - shopifySearchMode:", shopifySearchMode, "folderSearch:", folderSearch);
250
+ // Using static token, so no need to check for coreApiToken
251
+ if (shopifySearchMode && folderSearch && folderSearch.length >= 2) {
250
252
  fetchShopifyProducts(folderSearch);
251
253
  }
252
254
  else if (shopifySearchMode && (!folderSearch || folderSearch.length < 2)) {
253
255
  setState((prevState) => (Object.assign(Object.assign({}, prevState), { shopifyProducts: [] })));
254
256
  }
255
- }, [shopifySearchMode, coreApiToken, folderSearch]);
257
+ }, [shopifySearchMode, folderSearch]);
256
258
  const fetchShopifyProducts = (searchTerm) => __awaiter(this, void 0, void 0, function* () {
257
259
  setState((prevState) => (Object.assign(Object.assign({}, prevState), { shopifyLoading: true })));
258
260
  try {
259
- // Use coreApiUrl if provided, otherwise use staging URL as fallback
261
+ // Hardcoded Shopify API URL and token for now
260
262
  const shopifyApiBaseUrl = "https://staging-api.dashingone.com.au";
263
+ // Static token for Shopify API access - TODO: Replace with proper auth mechanism later
264
+ const shopifyStaticToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTAyOSwicGVybWlzc2lvbnMiOiJbe1wicmVzb3VyY2VfaWRcIjoyLFwiYWNjZXNzXCI6W1wicmVhZFwiXX0se1wicmVzb3VyY2VfaWRcIjoxLFwiYWNjZXNzXCI6W1wicmVhZFwiXX0se1wicmVzb3VyY2VfaWRcIjo1LFwiYWNjZXNzXCI6W1wiY3JlYXRlXCJdfSx7XCJyZXNvdXJjZV9pZFwiOjUsXCJhY2Nlc3NcIjpbXCJyZWFkXCJdfSx7XCJyZXNvdXJjZV9pZFwiOjUsXCJhY2Nlc3NcIjpbXCJ1cGRhdGVcIl19XSIsInRlYW1zIjoiWzE1OCwxNjUsMTA0XSIsInRlYW1JRCI6MTU4LCJicmFuZFRlYW1JRCI6MTA0LCJ0aGVtZUlEIjoxLCJlbWFpbCI6Im1haGVuZHJha29uZGFkYXN1QGdtYWlsLmNvbSIsImZpcnN0TmFtZSI6Ik1haGVuZHJhIiwibGFzdE5hbWUiOiJLb25kYWRhc3UiLCJpYXQiOjE3NjUyNjE1MzIsImV4cCI6MTc2NTMyMTUzMn0.1KcLUytTQQ2cqqOfNwuMt8vIdm1mJMv5mZZtCC9M1KA";
261
265
  console.log("Shopify API Base URL:", shopifyApiBaseUrl);
262
- console.log("Core API Token available:", !!coreApiToken);
263
266
  const response = yield axios.get(`${shopifyApiBaseUrl}${FETCH_SHOPIFY_PRODUCTS_URL}`, {
264
267
  params: { title: searchTerm },
265
268
  headers: {
266
- Authorization: `Bearer ${coreApiToken}`,
269
+ Authorization: `Bearer ${shopifyStaticToken}`,
267
270
  },
268
271
  });
269
272
  // Transform Shopify products to file entity format
@@ -271,19 +274,26 @@ function DriveContainer({ parentFolderId, setSelectedFile, setParentFolderId, pi
271
274
  const products = get(response, "data.data.products", get(response, "data.products", []));
272
275
  console.log("Shopify products response:", response.data);
273
276
  console.log("Extracted products:", products);
274
- const transformedProducts = (Array.isArray(products) ? products : []).map((product) => ({
275
- _id: product.id || product._id || `shopify-${Date.now()}-${Math.random()}`,
276
- name: product.title || product.name || "Unknown Product",
277
- thumbnailUrl: product.image || product.thumbnailUrl || "",
278
- s3Url: product.image || product.s3Url || "",
279
- type: EntityType.FILE,
280
- fileType: "jpeg",
281
- createdAt: product.created_at || product.createdAt || new Date().toISOString(),
282
- updatedAt: product.updated_at || product.updatedAt || new Date().toISOString(),
283
- size: 0,
284
- // Keep original product data for reference
285
- shopifyProduct: product,
286
- }));
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
+ });
287
297
  setState((prevState) => (Object.assign(Object.assign({}, prevState), { shopifyProducts: transformedProducts, shopifyLoading: false })));
288
298
  }
289
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.73",
3
+ "version": "5.8.78",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",