@bindu-dashing/dam-solution-v2 5.8.160 → 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 {
|
|
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,34 +39,99 @@ 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
|
-
let brandId = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId;
|
|
57
|
+
let brandId = (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) || "68a2f214f7e91fbee730b0b9";
|
|
58
|
+
console.log("Edit mode - existingClientData:", existingClientData);
|
|
59
|
+
console.log("Using brandId:", brandId);
|
|
47
60
|
// If brandId is not provided, try to get it from subdomain first
|
|
48
|
-
if (!brandId && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
|
|
61
|
+
if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
|
|
49
62
|
console.log("brandId not found, fetching by subdomain first:", existingClientData.subdomain);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
try {
|
|
64
|
+
const subdomainResponse = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
|
|
65
|
+
const subdomainData = get(subdomainResponse, "data.data", {});
|
|
66
|
+
const extractedBrandId = get(subdomainData, "_id");
|
|
67
|
+
if (extractedBrandId) {
|
|
68
|
+
brandId = extractedBrandId;
|
|
69
|
+
console.log("Extracted brandId from subdomain response:", brandId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (subdomainError) {
|
|
73
|
+
console.warn("Failed to fetch by subdomain, using static brandId:", subdomainError);
|
|
74
|
+
}
|
|
54
75
|
}
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
}
|
|
61
103
|
}
|
|
62
|
-
|
|
63
|
-
console.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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;
|
|
67
112
|
}
|
|
68
|
-
|
|
69
|
-
|
|
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);
|
|
124
|
+
}
|
|
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
|
+
}
|
|
70
135
|
setFetchingClientData(false);
|
|
71
136
|
return;
|
|
72
137
|
}
|