@bindu-dashing/dam-solution-v2 5.8.200 → 5.8.203

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.
@@ -9,12 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { Button, Space } from "antd";
12
- import { useState } from "react";
13
- import axios from "axios";
12
+ import { useState, useMemo } from "react";
14
13
  import CreateClientForm from "./CreateClientForm";
15
14
  import { useDamConfig } from "../hocs/DamConfigContext";
16
- import { getBaseUrl } from "../hocs/helpers";
17
- import { REFRESH_KEY_URL, USER_LOGIN } from "../utilities/constants/apiUrls";
15
+ import { createApiClient } from "../hocs/configureAxios";
16
+ import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
18
17
  import { showNotification } from "../common/notifications";
19
18
  import { NotificationStatus } from "../utilities/constants/interface";
20
19
  import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
@@ -24,7 +23,7 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
24
23
  const [refreshingKey, setRefreshingKey] = useState(false);
25
24
  const isEditMode = !!existingClientData;
26
25
  const damConfig = useDamConfig();
27
- const { appType, teamIds } = damConfig;
26
+ const api = useMemo(() => createApiClient(damConfig), [damConfig]);
28
27
  const toggleShow = () => {
29
28
  setShowForm(!showForm);
30
29
  };
@@ -33,38 +32,20 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
33
32
  showNotification("Access key and secret key are required to refresh", NotificationStatus.ERROR);
34
33
  return;
35
34
  }
36
- const accessKey = existingClientData.accessKey;
37
- const secretKey = existingClientData.secretKey;
38
- const subdomain = existingClientData.subdomain || clientSubdomain || (damConfig === null || damConfig === void 0 ? void 0 : damConfig.subdomain) || "";
39
- if (!subdomain) {
40
- showNotification("Subdomain is required to refresh key", NotificationStatus.ERROR);
41
- return;
42
- }
43
35
  setRefreshingKey(true);
44
36
  try {
45
- // Step 1: Login with keys to get DAM token (same as Edit Client flow)
46
- const loginResponse = yield axios.post(getBaseUrl(appType) + USER_LOGIN, {
47
- accessKey,
48
- secretKey,
49
- subdomain,
50
- teams: teamIds && teamIds.length > 0 ? teamIds : [""],
51
- });
52
- const token = get(loginResponse, "data.data.access_token");
53
- if (!token) {
54
- throw new Error("Failed to get token from login");
55
- }
56
- // Step 2: Call refresh API with the DAM token (include subdomain header)
57
- const response = yield axios.put(getBaseUrl(appType) + REFRESH_KEY_URL, { accessKey, secretKey }, {
58
- headers: {
59
- Authorization: `Bearer ${token}`,
60
- subdomain: subdomain,
61
- },
37
+ const response = yield api.put(REFRESH_KEY_URL, {
38
+ accessKey: existingClientData.accessKey,
39
+ secretKey: existingClientData.secretKey,
62
40
  });
63
41
  setRefreshingKey(false);
64
- showNotification(get(response, "data.data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
42
+ showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
43
+ if (onSuccess) {
44
+ onSuccess(response === null || response === void 0 ? void 0 : response.data);
45
+ }
65
46
  }
66
47
  catch (error) {
67
- showNotification(get(error, "response.data.message", get(error, "message", SOMETHING_WENT_WRONG)), NotificationStatus.ERROR);
48
+ showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
68
49
  setRefreshingKey(false);
69
50
  }
70
51
  });
@@ -19,7 +19,7 @@ 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";
22
- import { get, isEqual } from "lodash";
22
+ import { get } from "lodash";
23
23
  const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess, clientSubdomain, existingClientData, }) => {
24
24
  const damConfig = useDamConfig();
25
25
  const { appType } = damConfig;
@@ -34,51 +34,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
34
34
  const api = useMemo(() => createApiClient(damConfig), [damConfig]);
35
35
  const [form] = Form.useForm();
36
36
  const isEditMode = !!existingClientData;
37
- // Watch form values to enable/disable Submit button
38
- const formValues = Form.useWatch([], form);
39
- const isFormValid = useMemo(() => {
40
- var _a;
41
- if (!formValues)
42
- return false;
43
- // In edit mode, disabled fields (subdomain, damLocationDetails) may be excluded from form values - use clientData as fallback
44
- const damLocationDetails = formValues.damLocationDetails || get(clientData, "damLocationDetails", {}) || {};
45
- const name = formValues.name;
46
- const accessTypes = formValues.accessTypes;
47
- const adminTeams = formValues.adminTeams;
48
- const subdomain = (_a = formValues.subdomain) !== null && _a !== void 0 ? _a : (isEditMode ? (get(clientData, "subdomain") || (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) : undefined);
49
- const type = damLocationDetails.type;
50
- const rootPath = damLocationDetails.rootPath;
51
- if (!(name === null || name === void 0 ? void 0 : name.trim()))
52
- return false;
53
- if (!(accessTypes === null || accessTypes === void 0 ? void 0 : accessTypes.length))
54
- return false;
55
- if (!(adminTeams === null || adminTeams === void 0 ? void 0 : adminTeams.length))
56
- return false;
57
- if (!(subdomain === null || subdomain === void 0 ? void 0 : subdomain.trim()))
58
- return false;
59
- if (!type)
60
- return false;
61
- if (!(rootPath === null || rootPath === void 0 ? void 0 : rootPath.trim()))
62
- return false;
63
- if (damLocationType === "external") {
64
- const bucket = damLocationDetails.bucket;
65
- const accessKeyId = damLocationDetails.accessKeyId;
66
- const secretAccessKey = damLocationDetails.secretAccessKey;
67
- const url = damLocationDetails.url;
68
- const region = damLocationDetails.region;
69
- if (!(bucket === null || bucket === void 0 ? void 0 : bucket.trim()))
70
- return false;
71
- if (!(accessKeyId === null || accessKeyId === void 0 ? void 0 : accessKeyId.trim()))
72
- return false;
73
- if (!(secretAccessKey === null || secretAccessKey === void 0 ? void 0 : secretAccessKey.trim()))
74
- return false;
75
- if (!(url === null || url === void 0 ? void 0 : url.trim()))
76
- return false;
77
- if (!(region === null || region === void 0 ? void 0 : region.trim()))
78
- return false;
79
- }
80
- return true;
81
- }, [formValues, damLocationType, isEditMode, clientData, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain]);
82
37
  const onChangeDamLocationType = (e) => {
83
38
  setDamLocationType(e);
84
39
  form.setFieldValue("dam_location_details", { type: e });
@@ -197,40 +152,33 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
197
152
  fetchClientData();
198
153
  }, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api, form]);
199
154
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
200
- var _a, _b, _c, _d;
155
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
201
156
  try {
202
- // Use teamsApiDetails from clientData if available (from API response), otherwise use props
203
- const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
204
- const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
205
- const finalUsername = teamsApiDetailsFromData.username || username;
206
- const finalPassword = teamsApiDetailsFromData.password || password;
207
- // Convert adminTeams to strings for API (API expects strings like ["547"] not numbers like [547])
208
- const adminTeamsAsStrings = Array.isArray(data.adminTeams)
209
- ? data.adminTeams.map((team) => String(team))
210
- : [];
211
157
  setLoading(true);
212
158
  let response;
213
159
  const baseUrl = getBaseUrl(appType);
214
160
  if (isEditMode && brandIdForUpdate && authToken) {
215
- // Edit mode: send only changed fields (partial update)
216
- const originalAdminTeams = get(clientData, "adminTeams", []);
217
- const originalAdminTeamsStr = Array.isArray(originalAdminTeams)
218
- ? originalAdminTeams.map((t) => String(t)).sort()
161
+ // Edit mode: send only changed fields via PUT
162
+ const adminTeamsAsStrings = Array.isArray(data.adminTeams)
163
+ ? data.adminTeams.map((team) => String(team))
219
164
  : [];
220
- const newAdminTeamsStr = [...adminTeamsAsStrings].sort();
165
+ const existingAdminTeams = (get(clientData, "adminTeams", []) || []).map((t) => String(t));
166
+ const arraysEqual = (a, b) => {
167
+ const sa = [...a].sort();
168
+ const sb = [...b].sort();
169
+ return sa.length === sb.length && sa.every((v, i) => v === sb[i]);
170
+ };
171
+ const accessTypesChanged = JSON.stringify([...(data.accessTypes || [])].sort()) !==
172
+ JSON.stringify([...(get(clientData, "accessTypes", []) || [])].sort());
221
173
  const payload = {};
222
- if (data.name !== undefined && data.name !== get(clientData, "name")) {
174
+ if (data.name !== get(clientData, "name"))
223
175
  payload.name = data.name;
224
- }
225
- if (!isEqual(newAdminTeamsStr, originalAdminTeamsStr)) {
176
+ if (accessTypesChanged)
177
+ payload.accessTypes = data.accessTypes || [];
178
+ if (!arraysEqual(adminTeamsAsStrings, existingAdminTeams))
226
179
  payload.adminTeams = adminTeamsAsStrings;
227
- }
228
- if (!isEqual(data.accessTypes || [], get(clientData, "accessTypes", []))) {
229
- payload.accessTypes = data.accessTypes;
230
- }
231
- if (((_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false) !== get(clientData, "showFilePreview", false)) {
180
+ if (((_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false) !== get(clientData, "showFilePreview", false))
232
181
  payload.showFilePreview = (_b = data.showFilePreview) !== null && _b !== void 0 ? _b : false;
233
- }
234
182
  if (Object.keys(payload).length === 0) {
235
183
  setLoading(false);
236
184
  showNotification("No changes to save", NotificationStatus.INFO);
@@ -238,18 +186,39 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
238
186
  }
239
187
  const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, payload, {
240
188
  headers: {
241
- 'Authorization': `Bearer ${authToken}`,
242
- 'Content-Type': 'application/json',
243
- 'accept': 'application/json, text/plain, */*'
244
- }
189
+ Authorization: `Bearer ${authToken}`,
190
+ "Content-Type": "application/json",
191
+ accept: "application/json, text/plain, */*",
192
+ },
245
193
  });
194
+ // Extract data from axios response (API returns { data: {...} } or { data: { data: {...} } })
246
195
  response = get(putResponse, "data.data", get(putResponse, "data", putResponse));
247
196
  }
248
197
  else {
249
- // Create mode: send full payload
250
- const damLocationDetailsFromForm = data === null || data === void 0 ? void 0 : data.damLocationDetails;
251
- const subdomainValue = data.subdomain;
252
- const values = Object.assign(Object.assign({}, data), { subdomain: subdomainValue, adminTeams: adminTeamsAsStrings, showFilePreview: (_c = data.showFilePreview) !== null && _c !== void 0 ? _c : false, accessKey: appType == "reactJs"
198
+ // Create new client: POST to /brands/sub-brand (full payload required)
199
+ const teamsApiDetailsFromData = clientData ? get(clientData, "teamsApiDetails", {}) : {};
200
+ const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
201
+ const finalUsername = teamsApiDetailsFromData.username || username;
202
+ const finalPassword = teamsApiDetailsFromData.password || password;
203
+ const adminTeamsAsStrings = Array.isArray(data.adminTeams)
204
+ ? data.adminTeams.map((team) => String(team))
205
+ : [];
206
+ const formDamLocation = data === null || data === void 0 ? void 0 : data.damLocationDetails;
207
+ const damLocationDetails = damLocationType === "external"
208
+ ? {
209
+ bucket: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.bucket,
210
+ locationType: "EXTERNAL",
211
+ rootPath: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.rootPath,
212
+ accessKeyId: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.accessKeyId,
213
+ secretAccessKey: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.secretAccessKey,
214
+ url: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.url,
215
+ region: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.region,
216
+ }
217
+ : {
218
+ locationType: "INTERNAL",
219
+ rootPath: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.rootPath,
220
+ };
221
+ const values = Object.assign(Object.assign({}, data), { adminTeams: adminTeamsAsStrings, showFilePreview: (_c = data.showFilePreview) !== null && _c !== void 0 ? _c : false, accessKey: appType == "reactJs"
253
222
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
254
223
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
255
224
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SECRET_KEY
@@ -259,35 +228,29 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
259
228
  teamsApi: finalTeamsApi,
260
229
  username: finalUsername,
261
230
  password: finalPassword,
262
- }, damLocationDetails: damLocationType === "external"
263
- ? {
264
- bucket: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.bucket,
265
- locationType: "EXTERNAL",
266
- rootPath: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.rootPath,
267
- accessKeyId: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.accessKeyId,
268
- secretAccessKey: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.secretAccessKey,
269
- url: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.url,
270
- region: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.region,
271
- }
272
- : {
273
- locationType: "INTERNAL",
274
- rootPath: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.rootPath,
275
- } });
276
- // Create new client: POST to /brands/sub-brand
231
+ }, damLocationDetails });
277
232
  response = yield api.post(CREATE_SUB_BRAND, values);
278
233
  }
279
234
  setLoading(false);
280
235
  showNotification((_d = response === null || response === void 0 ? void 0 : response.message) !== null && _d !== void 0 ? _d : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
281
- toggleShow();
236
+ // Call onSuccess before closing drawer so parent can show its toast (e.g. d1-admin, ThemePage)
237
+ // Parent expects accessKey, secretKey, subdomain - always provide when in edit mode
282
238
  if (onSuccess) {
283
- // Pass full brand object: API may return { data: {...} } or {...} directly
284
- // For PATCH (edit), response may be partial - merge with clientData and existingClientData
285
- // so parent gets accessKey, secretKey, subdomain (credentials may not be in API response)
286
- const apiBrand = get(response, "data", response);
287
- const brandData = isEditMode
288
- ? Object.assign(Object.assign(Object.assign({}, (clientData || {})), (existingClientData || {})), apiBrand) : apiBrand;
289
- onSuccess(brandData);
239
+ const successData = isEditMode
240
+ ? Object.assign(Object.assign(Object.assign({}, response === null || response === void 0 ? void 0 : response.data), response), { accessKey: (_f = (_e = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) !== null && _e !== void 0 ? _e : get(response, "accessKey")) !== null && _f !== void 0 ? _f : get(clientData, "accessKey"), secretKey: (_h = (_g = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey) !== null && _g !== void 0 ? _g : get(response, "secretKey")) !== null && _h !== void 0 ? _h : get(clientData, "secretKey"), subdomain: (_l = (_k = (_j = data === null || data === void 0 ? void 0 : data.subdomain) !== null && _j !== void 0 ? _j : existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) !== null && _k !== void 0 ? _k : get(response, "subdomain")) !== null && _l !== void 0 ? _l : get(clientData, "subdomain") }) : (_m = response === null || response === void 0 ? void 0 : response.data) !== null && _m !== void 0 ? _m : response;
241
+ // Guard: parent (e.g. ThemePage.onCreateDamClient) accesses data.accessKey - never pass undefined
242
+ const safeData = successData && typeof successData === "object"
243
+ ? successData
244
+ : isEditMode && existingClientData
245
+ ? {
246
+ accessKey: existingClientData.accessKey,
247
+ secretKey: existingClientData.secretKey,
248
+ subdomain: existingClientData.subdomain,
249
+ }
250
+ : {};
251
+ onSuccess(safeData);
290
252
  }
253
+ toggleShow();
291
254
  }
292
255
  catch (error) {
293
256
  setLoading(false);
@@ -376,48 +339,70 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
376
339
  required: true,
377
340
  message: "Team Ids is required",
378
341
  },
379
- ], children: _jsx(Select, { showSearch: true, mode: "multiple", placeholder: "Team Ids", options: filteredTeams, optionFilterProp: "key" }) }), _jsxs(Form.Item, { label: "DAM Location Details", name: "damLocationDetails", children: [_jsx(Form.Item, { label: "Type", name: ["damLocationDetails", "type"], rules: [
342
+ ], children: _jsx(Select, { showSearch: true, mode: "multiple", placeholder: "Team Ids", options: filteredTeams, optionFilterProp: "key" }) }), !isEditMode && (_jsxs(Form.Item, { label: "DAM Location Details", name: "damLocationDetails", children: [_jsx(Form.Item, { label: "Type", name: ["damLocationDetails", "type"], rules: [
380
343
  {
381
344
  required: true,
382
345
  message: "Type is required",
383
346
  },
384
347
  ], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
385
348
  onChangeDamLocationType(e);
386
- }, placeholder: "Type", disabled: isEditMode }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
349
+ }, placeholder: "Type" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
387
350
  {
388
351
  required: true,
389
352
  message: "Root path is required",
390
353
  },
391
- ], children: _jsx(Input, { placeholder: "Root path", disabled: isEditMode }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
354
+ ], children: _jsx(Input, { placeholder: "Root path" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
392
355
  {
393
356
  required: damLocationType === "external",
394
357
  message: "Bucket is required",
395
358
  },
396
- ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" || isEditMode }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
359
+ ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
397
360
  {
398
361
  required: damLocationType === "external",
399
362
  message: "Access key is required",
400
363
  },
401
- ], children: _jsx(Input, { placeholder: "Access Key", disabled: damLocationType === "internal" || isEditMode }) }), _jsx(Form.Item, { label: "Secret Access Key", name: ["damLocationDetails", "secretAccessKey"], rules: [
364
+ ], children: _jsx(Input, { placeholder: "Access Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Secret Access Key", name: ["damLocationDetails", "secretAccessKey"], rules: [
402
365
  {
403
366
  required: damLocationType === "external",
404
367
  message: "Secret Access Key is required",
405
368
  },
406
- ], children: _jsx(Input, { placeholder: "Secret Key", disabled: damLocationType === "internal" || isEditMode }) }), _jsx(Form.Item, { label: "Url", name: ["damLocationDetails", "url"], rules: [
369
+ ], children: _jsx(Input, { placeholder: "Secret Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Url", name: ["damLocationDetails", "url"], rules: [
407
370
  {
408
371
  required: damLocationType === "external",
409
372
  message: "Url is required",
410
373
  },
411
- ], children: _jsx(Input, { placeholder: "Url", disabled: damLocationType === "internal" || isEditMode }) }), _jsx(Form.Item, { label: "Region", name: ["damLocationDetails", "region"], rules: [
374
+ ], children: _jsx(Input, { placeholder: "Url", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Region", name: ["damLocationDetails", "region"], rules: [
412
375
  {
413
376
  required: damLocationType === "external",
414
377
  message: "Region is required",
415
378
  },
416
- ], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" || isEditMode }) })] }))] }), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
379
+ ], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" }) })] }))] })), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
417
380
  {
418
381
  required: true,
419
382
  message: "Subdomain is required",
420
383
  },
421
- ], children: _jsx(Input, { placeholder: "Subdomain", disabled: isEditMode }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview Editor" }) }), _jsx(Form.Item, { children: _jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, disabled: !isFormValid || loading, children: "Submit" }) })] })) }));
384
+ ], children: _jsx(Input, { placeholder: "Subdomain", disabled: isEditMode }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview Editor" }) }), _jsx(Form.Item, { shouldUpdate: true, style: { marginBottom: 0 }, children: () => {
385
+ var _a, _b, _c, _d, _e, _f, _g, _h;
386
+ const values = form.getFieldsValue(true);
387
+ const hasName = !!((_a = values === null || values === void 0 ? void 0 : values.name) === null || _a === void 0 ? void 0 : _a.trim());
388
+ const hasAccessTypes = Array.isArray(values === null || values === void 0 ? void 0 : values.accessTypes) && values.accessTypes.length > 0;
389
+ const hasAdminTeams = Array.isArray(values === null || values === void 0 ? void 0 : values.adminTeams) && values.adminTeams.length > 0;
390
+ const hasSubdomain = !!((_b = values === null || values === void 0 ? void 0 : values.subdomain) === null || _b === void 0 ? void 0 : _b.trim());
391
+ const baseValid = hasName && hasAccessTypes && hasAdminTeams && hasSubdomain;
392
+ let damLocationValid = true;
393
+ if (!isEditMode) {
394
+ const dl = (values === null || values === void 0 ? void 0 : values.damLocationDetails) || {};
395
+ damLocationValid = !!((dl === null || dl === void 0 ? void 0 : dl.type) && ((_c = dl === null || dl === void 0 ? void 0 : dl.rootPath) === null || _c === void 0 ? void 0 : _c.trim()));
396
+ if (damLocationValid && damLocationType === "external") {
397
+ damLocationValid = !!(((_d = dl === null || dl === void 0 ? void 0 : dl.bucket) === null || _d === void 0 ? void 0 : _d.trim()) &&
398
+ ((_e = dl === null || dl === void 0 ? void 0 : dl.accessKeyId) === null || _e === void 0 ? void 0 : _e.trim()) &&
399
+ ((_f = dl === null || dl === void 0 ? void 0 : dl.secretAccessKey) === null || _f === void 0 ? void 0 : _f.trim()) &&
400
+ ((_g = dl === null || dl === void 0 ? void 0 : dl.url) === null || _g === void 0 ? void 0 : _g.trim()) &&
401
+ ((_h = dl === null || dl === void 0 ? void 0 : dl.region) === null || _h === void 0 ? void 0 : _h.trim()));
402
+ }
403
+ }
404
+ const isFormValid = baseValid && damLocationValid;
405
+ return (_jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, disabled: !isFormValid, children: "Submit" }));
406
+ } })] })) }));
422
407
  };
423
408
  export default CreateClientForm;
@@ -9,49 +9,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { Button } from "antd";
12
- import { useState } from "react";
13
- import axios from "axios";
12
+ import { useMemo, useState } from "react";
14
13
  import { showNotification } from "../common/notifications";
15
14
  import { NotificationStatus } from "../utilities/constants/interface";
16
15
  import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
17
16
  import { get } from "lodash";
18
- import { REFRESH_KEY_URL, USER_LOGIN } from "../utilities/constants/apiUrls";
17
+ import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
19
18
  import { useDamConfig } from "../hocs/DamConfigContext";
20
- import { getBaseUrl } from "../hocs/helpers";
19
+ import { createApiClient } from "../hocs/configureAxios";
21
20
  export default function RefreshKeyBtn() {
22
21
  const [loading, setLoading] = useState(false);
23
22
  const damConfig = useDamConfig();
24
- const { damAccessKey, secretKey, subdomain, teamIds, appType } = damConfig;
23
+ const { damAccessKey, secretKey } = damConfig;
24
+ const api = useMemo(() => createApiClient(damConfig), [damConfig]);
25
25
  const onRefreshKey = () => __awaiter(this, void 0, void 0, function* () {
26
- if (!damAccessKey || !secretKey || !subdomain) {
27
- showNotification("Access key, secret key, and subdomain are required to refresh", NotificationStatus.ERROR);
28
- return;
29
- }
30
26
  setLoading(true);
31
27
  try {
32
- // Step 1: Login with keys to get DAM token (same as Edit Client flow)
33
- const loginResponse = yield axios.post(getBaseUrl(appType) + USER_LOGIN, {
28
+ const response = yield api.put(REFRESH_KEY_URL, {
34
29
  accessKey: damAccessKey,
35
30
  secretKey,
36
- subdomain,
37
- teams: teamIds && teamIds.length > 0 ? teamIds : [""],
38
- });
39
- const token = get(loginResponse, "data.data.access_token");
40
- if (!token) {
41
- throw new Error("Failed to get token from login");
42
- }
43
- // Step 2: Call refresh API with the DAM token (include subdomain header)
44
- const response = yield axios.put(getBaseUrl(appType) + REFRESH_KEY_URL, { accessKey: damAccessKey, secretKey }, {
45
- headers: {
46
- Authorization: `Bearer ${token}`,
47
- subdomain: subdomain,
48
- },
49
31
  });
32
+ // console.log(response);
50
33
  setLoading(false);
51
34
  showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
52
35
  }
53
36
  catch (error) {
54
- showNotification(get(error, "response.data.message", get(error, "message", SOMETHING_WENT_WRONG)), NotificationStatus.ERROR);
37
+ showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
55
38
  setLoading(false);
56
39
  }
57
40
  });
@@ -143,7 +143,6 @@ export const DamConfigProvider = ({ children, config }) => {
143
143
  loading,
144
144
  setAccessToken,
145
145
  setDamUser,
146
- setBrand,
147
146
  appType,
148
147
  setRootFolderId,
149
148
  rootFolderId,
@@ -44,10 +44,10 @@ export const createApiClient = ({ accessToken, appType, subdomain, damAccessKey,
44
44
  const token = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.access_token;
45
45
  const userData = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.user;
46
46
  const brandData = (_f = (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.brand;
47
- setAccessToken === null || setAccessToken === void 0 ? void 0 : setAccessToken(token);
48
- setDamUser === null || setDamUser === void 0 ? void 0 : setDamUser(userData);
49
- setBrand === null || setBrand === void 0 ? void 0 : setBrand(brandData);
50
- setRootFolderId === null || setRootFolderId === void 0 ? void 0 : setRootFolderId(get(response, "data.data.rootFolderId"));
47
+ setAccessToken(token);
48
+ setDamUser(userData);
49
+ setBrand(brandData);
50
+ setRootFolderId(get(response, "data.data.rootFolderId"));
51
51
  originalRequest.headers["Authorization"] = `Bearer ${token}`;
52
52
  return api(originalRequest);
53
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.200",
3
+ "version": "5.8.203",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",