@bindu-dashing/dam-solution-v2 5.8.167 → 5.8.169
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.
|
@@ -22,7 +22,7 @@ import { showNotification } from "../common/notifications";
|
|
|
22
22
|
import { get } from "lodash";
|
|
23
23
|
const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess, clientSubdomain, existingClientData, }) => {
|
|
24
24
|
const damConfig = useDamConfig();
|
|
25
|
-
const { appType
|
|
25
|
+
const { appType } = damConfig;
|
|
26
26
|
const [loading, setLoading] = useState(false);
|
|
27
27
|
const [fetchingClientData, setFetchingClientData] = useState(false);
|
|
28
28
|
const [damLocationType, setDamLocationType] = useState("external");
|
|
@@ -47,32 +47,23 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
47
47
|
try {
|
|
48
48
|
// Validate that we have required credentials
|
|
49
49
|
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)) {
|
|
50
|
-
console.error("Missing required credentials for login:", {
|
|
51
|
-
accessKey: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey),
|
|
52
|
-
secretKey: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey),
|
|
53
|
-
subdomain: !!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)
|
|
54
|
-
});
|
|
55
50
|
setFetchingClientData(false);
|
|
56
51
|
return;
|
|
57
52
|
}
|
|
58
53
|
let fetchedData;
|
|
59
|
-
let brandId = (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) || "
|
|
60
|
-
console.log("Edit mode - existingClientData:", existingClientData);
|
|
61
|
-
console.log("Using brandId:", brandId);
|
|
54
|
+
let brandId = (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) || "";
|
|
62
55
|
// If brandId is not provided, try to get it from subdomain first
|
|
63
56
|
if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
|
|
64
|
-
console.log("brandId not found, fetching by subdomain first:", existingClientData.subdomain);
|
|
65
57
|
try {
|
|
66
58
|
const subdomainResponse = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
|
|
67
59
|
const subdomainData = get(subdomainResponse, "data.data", {});
|
|
68
60
|
const extractedBrandId = get(subdomainData, "_id");
|
|
69
61
|
if (extractedBrandId) {
|
|
70
62
|
brandId = extractedBrandId;
|
|
71
|
-
console.log("Extracted brandId from subdomain response:", brandId);
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
65
|
catch (subdomainError) {
|
|
75
|
-
|
|
66
|
+
// Failed to fetch by subdomain, continue with empty brandId
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
// Step 1: Call login API first with access and secret keys
|
|
@@ -83,7 +74,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
83
74
|
subdomain: existingClientData.subdomain,
|
|
84
75
|
teams: [brandId] // Use brandId as team ID
|
|
85
76
|
};
|
|
86
|
-
console.log("Step 1: Calling login API with payload:", Object.assign(Object.assign({}, loginPayload), { secretKey: loginPayload.secretKey ? `${loginPayload.secretKey.substring(0, 10)}...` : 'missing' }));
|
|
87
77
|
let token;
|
|
88
78
|
let loginBrandId = brandId;
|
|
89
79
|
try {
|
|
@@ -93,12 +83,10 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
93
83
|
'accept': 'application/json, text/plain, */*'
|
|
94
84
|
}
|
|
95
85
|
});
|
|
96
|
-
console.log("Login response:", loginResponse.data);
|
|
97
86
|
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;
|
|
98
87
|
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;
|
|
99
88
|
loginBrandId = (loginBrandData === null || loginBrandData === void 0 ? void 0 : loginBrandData._id) || brandId;
|
|
100
89
|
if (!token) {
|
|
101
|
-
console.error("No token received from login API");
|
|
102
90
|
setFetchingClientData(false);
|
|
103
91
|
return;
|
|
104
92
|
}
|
|
@@ -107,16 +95,10 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
107
95
|
setBrandIdForUpdate(loginBrandId);
|
|
108
96
|
}
|
|
109
97
|
catch (loginError) {
|
|
110
|
-
console.error("Error logging in with DAM credentials:", loginError);
|
|
111
|
-
if (loginError.response) {
|
|
112
|
-
console.error("Login error response:", loginError.response.data);
|
|
113
|
-
console.error("Login error status:", loginError.response.status);
|
|
114
|
-
}
|
|
115
98
|
setFetchingClientData(false);
|
|
116
99
|
return;
|
|
117
100
|
}
|
|
118
101
|
// Step 2: Call brands/details API with the token (only after login succeeds)
|
|
119
|
-
console.log("Step 2: Calling brands/details API with token and brandId:", loginBrandId);
|
|
120
102
|
try {
|
|
121
103
|
const brandDetailsResponse = yield axios.get(`${baseUrl}/brands/details/${loginBrandId}`, {
|
|
122
104
|
headers: {
|
|
@@ -125,14 +107,8 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
125
107
|
}
|
|
126
108
|
});
|
|
127
109
|
fetchedData = get(brandDetailsResponse, "data.data", {});
|
|
128
|
-
console.log("Fetched client data from brands/details:", fetchedData);
|
|
129
110
|
}
|
|
130
111
|
catch (brandDetailsError) {
|
|
131
|
-
console.error("Error fetching brand details:", brandDetailsError);
|
|
132
|
-
if (brandDetailsError.response) {
|
|
133
|
-
console.error("Brand details error response:", brandDetailsError.response.data);
|
|
134
|
-
console.error("Brand details error status:", brandDetailsError.response.status);
|
|
135
|
-
}
|
|
136
112
|
// If brand details fetch fails, still set subdomain
|
|
137
113
|
if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
|
|
138
114
|
form.setFieldValue("subdomain", existingClientData.subdomain);
|
|
@@ -160,7 +136,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
160
136
|
}
|
|
161
137
|
}
|
|
162
138
|
catch (error) {
|
|
163
|
-
console.error("Error fetching client data:", error);
|
|
164
139
|
// If fetch fails, still set subdomain
|
|
165
140
|
if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
|
|
166
141
|
form.setFieldValue("subdomain", existingClientData.subdomain);
|
|
@@ -217,8 +192,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
217
192
|
const baseUrl = getBaseUrl(appType);
|
|
218
193
|
if (isEditMode && brandIdForUpdate && authToken) {
|
|
219
194
|
// Update existing client: PUT to /brands/{brandId}
|
|
220
|
-
console.log("Updating client with brandId:", brandIdForUpdate);
|
|
221
|
-
console.log("Update payload:", values);
|
|
222
195
|
const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, values, {
|
|
223
196
|
headers: {
|
|
224
197
|
'Authorization': `Bearer ${authToken}`,
|
|
@@ -241,7 +214,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
241
214
|
}
|
|
242
215
|
}
|
|
243
216
|
catch (error) {
|
|
244
|
-
// console.error("Error creating client:", error);
|
|
245
217
|
setLoading(false);
|
|
246
218
|
showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
|
|
247
219
|
}
|
|
@@ -310,12 +282,9 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
310
282
|
setFilteredTeams(options);
|
|
311
283
|
}
|
|
312
284
|
catch (err) {
|
|
313
|
-
console.log("Error while fetching external teams", err);
|
|
314
285
|
}
|
|
315
286
|
});
|
|
316
|
-
// Debug: Log edit mode and location type
|
|
317
287
|
const shouldShowExternalFields = damLocationType === "external" || isEditMode;
|
|
318
|
-
console.log("CreateClientForm - isEditMode:", isEditMode, "damLocationType:", damLocationType, "shouldShowExternalFields:", shouldShowExternalFields, "existingClientData:", existingClientData);
|
|
319
288
|
return (_jsx(Drawer, { open: true, title: isEditMode ? "Edit Client" : "Create Client", onClose: toggleShow, width: 500, maskClosable: false, children: fetchingClientData ? (_jsx("div", { style: { textAlign: "center", padding: "20px" }, children: _jsx(Typography.Text, { children: "Loading client data..." }) })) : (_jsxs(Form, { layout: "vertical", form: form, onFinish: onFinish, children: [_jsx(Form.Item, { label: "Name", name: "name", rules: [
|
|
320
289
|
{
|
|
321
290
|
required: true,
|