@bindu-dashing/dam-solution-v2 5.8.161 → 5.8.163

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.
@@ -12,10 +12,10 @@ import { Button, Checkbox, Drawer, Form, Input, Select, Typography } from "antd"
12
12
  import { useEffect, useMemo, useState } from "react";
13
13
  import { ACCESS_TYPES, DAM_LOCATION_TYPES } from "../hocs/appConstants";
14
14
  import { useDamConfig } from "../hocs/DamConfigContext";
15
- import { CREATE_SUB_BRAND, FETCH_BRAND_USING_SUBDOMAIN } from "../utilities/constants/apiUrls";
15
+ import { CREATE_SUB_BRAND, FETCH_BRAND_USING_SUBDOMAIN, USER_LOGIN } from "../utilities/constants/apiUrls";
16
16
  import axios from "axios";
17
17
  import { createApiClient } from "../hocs/configureAxios";
18
- import { fetchBrandDetails } from "../react-query/services/brand-services";
18
+ import { getBaseUrl } from "../hocs/helpers";
19
19
  import { CREATE_SUCCESS, SOMETHING_WENT_WRONG, } from "../utilities/constants/messages";
20
20
  import { NotificationStatus } from "../utilities/constants/interface";
21
21
  import { showNotification } from "../common/notifications";
@@ -39,11 +39,21 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
39
39
  // Fetch client data when editing
40
40
  useEffect(() => {
41
41
  const fetchClientData = () => __awaiter(void 0, void 0, void 0, function* () {
42
+ var _a, _b, _c, _d;
42
43
  if (isEditMode) {
43
44
  setFetchingClientData(true);
44
45
  try {
46
+ // Validate that we have required credentials
47
+ if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) || !(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey) || !(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
48
+ console.error("Missing required credentials for login:", {
49
+ accessKey: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey),
50
+ secretKey: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey),
51
+ subdomain: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)
52
+ });
53
+ setFetchingClientData(false);
54
+ return;
55
+ }
45
56
  let fetchedData;
46
- // TEMPORARY: Using static brandId for testing - remove after testing
47
57
  let brandId = (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) || "68a2f214f7e91fbee730b0b9";
48
58
  console.log("Edit mode - existingClientData:", existingClientData);
49
59
  console.log("Using brandId:", brandId);
@@ -63,22 +73,65 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
63
73
  console.warn("Failed to fetch by subdomain, using static brandId:", subdomainError);
64
74
  }
65
75
  }
66
- // Always use brands/details endpoint with brandId
67
- if (brandId) {
68
- console.log("Fetching brand details using brandId:", brandId);
69
- console.log("API endpoint:", `/brands/details/${brandId}`);
70
- // Use reusable fetchBrandDetails function
71
- fetchedData = yield fetchBrandDetails(api, brandId);
72
- console.log("Fetched client data from brands/details:", fetchedData);
76
+ // Step 1: Call login API first with access and secret keys
77
+ const baseUrl = getBaseUrl(appType);
78
+ const loginPayload = {
79
+ accessKey: existingClientData.accessKey,
80
+ secretKey: existingClientData.secretKey,
81
+ subdomain: existingClientData.subdomain,
82
+ teams: [brandId] // Use brandId as team ID
83
+ };
84
+ console.log("Step 1: Calling login API with payload:", Object.assign(Object.assign({}, loginPayload), { secretKey: loginPayload.secretKey ? `${loginPayload.secretKey.substring(0, 10)}...` : 'missing' }));
85
+ let token;
86
+ let loginBrandId = brandId;
87
+ try {
88
+ const loginResponse = yield axios.post(`${baseUrl}${USER_LOGIN}`, loginPayload, {
89
+ headers: {
90
+ 'Content-Type': 'application/json',
91
+ 'accept': 'application/json, text/plain, */*'
92
+ }
93
+ });
94
+ console.log("Login response:", loginResponse.data);
95
+ token = (_b = (_a = loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.access_token;
96
+ const loginBrandData = (_d = (_c = loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.data) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.brand;
97
+ loginBrandId = (loginBrandData === null || loginBrandData === void 0 ? void 0 : loginBrandData._id) || brandId;
98
+ if (!token) {
99
+ console.error("No token received from login API");
100
+ setFetchingClientData(false);
101
+ return;
102
+ }
103
+ }
104
+ catch (loginError) {
105
+ console.error("Error logging in with DAM credentials:", loginError);
106
+ if (loginError.response) {
107
+ console.error("Login error response:", loginError.response.data);
108
+ console.error("Login error status:", loginError.response.status);
109
+ }
110
+ setFetchingClientData(false);
111
+ return;
73
112
  }
74
- else if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
75
- console.log("No brandId available, using subdomain endpoint:", existingClientData.subdomain);
76
- const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
77
- fetchedData = get(response, "data.data", {});
78
- console.log("Fetched client data from subdomain:", fetchedData);
113
+ // Step 2: Call brands/details API with the token (only after login succeeds)
114
+ console.log("Step 2: Calling brands/details API with token and brandId:", loginBrandId);
115
+ try {
116
+ const brandDetailsResponse = yield axios.get(`${baseUrl}/brands/details/${loginBrandId}`, {
117
+ headers: {
118
+ 'Authorization': `Bearer ${token}`,
119
+ 'accept': 'application/json, text/plain, */*'
120
+ }
121
+ });
122
+ fetchedData = get(brandDetailsResponse, "data.data", {});
123
+ console.log("Fetched client data from brands/details:", fetchedData);
79
124
  }
80
- else {
81
- console.warn("No brandId or subdomain provided");
125
+ catch (brandDetailsError) {
126
+ console.error("Error fetching brand details:", brandDetailsError);
127
+ if (brandDetailsError.response) {
128
+ console.error("Brand details error response:", brandDetailsError.response.data);
129
+ console.error("Brand details error status:", brandDetailsError.response.status);
130
+ }
131
+ // If brand details fetch fails, still set subdomain
132
+ if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
133
+ form.setFieldValue("subdomain", existingClientData.subdomain);
134
+ }
82
135
  setFetchingClientData(false);
83
136
  return;
84
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.161",
3
+ "version": "5.8.163",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",