@bindu-dashing/dam-solution-v2 5.8.189 → 5.8.193

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.
@@ -214,13 +214,42 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
214
214
  setDisabledReason(null);
215
215
  }, 100);
216
216
  }, [field, form]);
217
+ // Strip time from dayjs (set to midnight) - used when "Allow time" is toggled OFF
218
+ const stripTimeFromDayjs = (d) => {
219
+ if (!d || typeof d.hour !== "function")
220
+ return d;
221
+ return d.hour(0).minute(0).second(0).millisecond(0);
222
+ };
217
223
  // Update defaultValueInput whenever form values change
218
- const handleFormValuesChange = () => {
224
+ const handleFormValuesChange = (changedValues, allValues) => {
219
225
  var _a;
220
- const formValues = form.getFieldsValue(true);
226
+ const formValues = allValues !== null && allValues !== void 0 ? allValues : form.getFieldsValue(true);
221
227
  const defaultName = currentInputType === null || currentInputType === void 0 ? void 0 : currentInputType.defaultName;
228
+ // When "Allow time" is toggled OFF for DATE/DATE_RANGE, strip time from defaultValue
229
+ const settings = get(formValues, "inputTypeSettings", {});
230
+ const allowTime = !!get(settings, `${InputSupportedTypes.ALLOW_TIME}.allow`);
231
+ const allowTimeChanged = changedValues && get(changedValues, "inputTypeSettings");
232
+ if (allowTimeChanged &&
233
+ !allowTime &&
234
+ (defaultName === InputTypes.DATE || defaultName === InputTypes.DATE_RANGE)) {
235
+ const currentDefault = get(formValues, "defaultValue");
236
+ if (currentDefault) {
237
+ let normalized = null;
238
+ if (defaultName === InputTypes.DATE_RANGE && isArray(currentDefault)) {
239
+ normalized = [
240
+ stripTimeFromDayjs(first(currentDefault)),
241
+ stripTimeFromDayjs(nth(currentDefault, 1)),
242
+ ];
243
+ }
244
+ else if (defaultName === InputTypes.DATE) {
245
+ normalized = stripTimeFromDayjs(currentDefault);
246
+ }
247
+ if (normalized !== null) {
248
+ form.setFieldValue("defaultValue", normalized);
249
+ }
250
+ }
251
+ }
222
252
  const options = ((_a = formValues.options) === null || _a === void 0 ? void 0 : _a.filter((opt) => (opt === null || opt === void 0 ? void 0 : opt.label) && (opt === null || opt === void 0 ? void 0 : opt.value))) || [];
223
- const settings = formValues.inputTypeSettings || {};
224
253
  const isOptionsBasedField = includes([InputTypes.SELECT, InputTypes.CHECKBOX, InputTypes.RADIO], defaultName);
225
254
  if (isOptionsBasedField && options.length === 0) {
226
255
  // Don't show Default Value field if no options exist
@@ -280,6 +309,16 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
280
309
  if ((defaultName === InputTypes.DATE ||
281
310
  defaultName === InputTypes.DATE_RANGE) &&
282
311
  settings[InputSupportedTypes.ALLOW_TIME] !== undefined) {
312
+ const hasNonZeroTime = (d) => {
313
+ if (!d || typeof d.hour !== "function")
314
+ return false;
315
+ return d.hour() !== 0 || d.minute() !== 0 || d.second() !== 0;
316
+ };
317
+ const hasOnlyDateNoTime = (d) => {
318
+ if (!d || typeof d.hour !== "function")
319
+ return false;
320
+ return d.hour() === 0 && d.minute() === 0 && d.second() === 0;
321
+ };
283
322
  rules.push({
284
323
  validator: (_, value) => {
285
324
  const allowTime = !!get(settings, `${InputSupportedTypes.ALLOW_TIME}.allow`);
@@ -291,10 +330,15 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
291
330
  typeof value.hour === "function" &&
292
331
  typeof value.minute === "function" &&
293
332
  typeof value.second === "function";
333
+ // When time is allowed: reject if user selected date-only (must re-select with time)
334
+ if (allowTime && hasTimeMethods && hasOnlyDateNoTime(value)) {
335
+ return Promise.reject("Please select a date with time (hour/minute/second).");
336
+ }
294
337
  if (allowTime && !hasTimeMethods) {
295
338
  return Promise.reject("Please select a date with time (hour/minute/second).");
296
339
  }
297
- if (!allowTime && hasTimeMethods) {
340
+ // When time is not allowed: strip time (handled in onValuesChange) - reject only if still has non-zero time
341
+ if (!allowTime && hasNonZeroTime(value)) {
298
342
  return Promise.reject("Time is not allowed. Please select only a date.");
299
343
  }
300
344
  }
@@ -309,10 +353,17 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
309
353
  typeof end.hour === "function" &&
310
354
  typeof end.minute === "function" &&
311
355
  typeof end.second === "function";
356
+ // When time is allowed: reject if either date is date-only (must re-select with time)
357
+ if (allowTime && (startHasTimeMethods || endHasTimeMethods)) {
358
+ if (hasOnlyDateNoTime(start) || hasOnlyDateNoTime(end)) {
359
+ return Promise.reject("Please select both start and end dates with time.");
360
+ }
361
+ }
312
362
  if (allowTime && (!startHasTimeMethods || !endHasTimeMethods)) {
313
363
  return Promise.reject("Please select both start and end dates with time.");
314
364
  }
315
- if (!allowTime && (startHasTimeMethods || endHasTimeMethods)) {
365
+ // When time is not allowed: strip time (handled in onValuesChange) - reject only if still has non-zero time
366
+ if (!allowTime && (hasNonZeroTime(start) || hasNonZeroTime(end))) {
316
367
  return Promise.reject("Time is not allowed. Please select only dates.");
317
368
  }
318
369
  }
@@ -218,13 +218,13 @@ export default function EditAssetTemplate({ assetTemplate, inputTypes, }) {
218
218
  {
219
219
  key: "1",
220
220
  label: "Fields",
221
- children: (_jsx(AddWidgets, { name: name, inputTypes: inputTypes, transformInputTypePayload: transformInputTypePayload, currentFieldIndex: currentFieldIndex, setState: setState, fields: fields, imagePickerOutputFormat: imagePickerOutputFormat, setCurrentFieldIndex: (value) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { currentFieldIndex: value }))), showOutputFormat: false })),
221
+ children: (_jsx(AddWidgets, { name: name, inputTypes: inputTypes, transformInputTypePayload: transformInputTypePayload, currentFieldIndex: currentFieldIndex, setState: setState, fields: fields, imagePickerOutputFormat: imagePickerOutputFormat, setCurrentFieldIndex: (value) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { currentFieldIndex: value }))), showOutputFormat: false, assetId: id || get(assetTemplate, "_id") })),
222
222
  },
223
223
  {
224
224
  key: "2",
225
225
  label: "Image picker output format",
226
226
  disabled: fields.length === 0,
227
- children: (_jsx(AddWidgets, { name: name, inputTypes: inputTypes, transformInputTypePayload: transformInputTypePayload, currentFieldIndex: currentFieldIndex, setState: setState, fields: fields, imagePickerOutputFormat: imagePickerOutputFormat, setCurrentFieldIndex: (value) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { currentFieldIndex: value }))), showOutputFormat: true })),
227
+ children: (_jsx(AddWidgets, { name: name, inputTypes: inputTypes, transformInputTypePayload: transformInputTypePayload, currentFieldIndex: currentFieldIndex, setState: setState, fields: fields, imagePickerOutputFormat: imagePickerOutputFormat, setCurrentFieldIndex: (value) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { currentFieldIndex: value }))), showOutputFormat: true, assetId: id || get(assetTemplate, "_id") })),
228
228
  },
229
229
  ];
230
230
  // console.log("edit asset template", fields, imagePickerOutputFormat);
@@ -1,7 +1,7 @@
1
1
  import { SetStateAction } from "react";
2
2
  import { InputTypeEntity } from "../utilities/constants/interface";
3
3
  export declare const getWidgetIcon: (defaultName: string | undefined | null) => import("react-icons").IconType | null;
4
- export default function FieldsSection({ name, inputTypes, transformInputTypePayload, currentFieldIndex, setCurrentFieldIndex, fields, setState, showOutputFormat, imagePickerOutputFormat, }: {
4
+ export default function FieldsSection({ name, inputTypes, transformInputTypePayload, currentFieldIndex, setCurrentFieldIndex, fields, setState, showOutputFormat, imagePickerOutputFormat, assetId: assetIdProp, }: {
5
5
  name: string;
6
6
  inputTypes: InputTypeEntity[];
7
7
  transformInputTypePayload: (values: any, field: InputTypeEntity, mapId: string) => void;
@@ -11,4 +11,5 @@ export default function FieldsSection({ name, inputTypes, transformInputTypePayl
11
11
  setState: React.Dispatch<SetStateAction<any>>;
12
12
  showOutputFormat: boolean;
13
13
  imagePickerOutputFormat: InputTypeEntity[];
14
+ assetId?: string;
14
15
  }): JSX.Element;
@@ -76,8 +76,9 @@ export const getWidgetIcon = (defaultName) => {
76
76
  return null;
77
77
  }
78
78
  };
79
- export default function FieldsSection({ name, inputTypes, transformInputTypePayload, currentFieldIndex, setCurrentFieldIndex, fields, setState, showOutputFormat, imagePickerOutputFormat, }) {
80
- const { id } = useAppParams();
79
+ export default function FieldsSection({ name, inputTypes, transformInputTypePayload, currentFieldIndex, setCurrentFieldIndex, fields, setState, showOutputFormat, imagePickerOutputFormat, assetId: assetIdProp, }) {
80
+ const { id: idFromParams } = useAppParams();
81
+ const assetId = assetIdProp !== null && assetIdProp !== void 0 ? assetIdProp : idFromParams;
81
82
  const [fieldState, setFieldState] = useState({
82
83
  showConfirmModal: false,
83
84
  selectedField: null,
@@ -166,9 +167,13 @@ export default function FieldsSection({ name, inputTypes, transformInputTypePayl
166
167
  }
167
168
  };
168
169
  const onDeleteExistedField = () => __awaiter(this, void 0, void 0, function* () {
170
+ if (!assetId) {
171
+ showNotification("Asset ID is missing. Unable to delete field.", NotificationStatus.ERROR);
172
+ return;
173
+ }
169
174
  setFieldState((prevState) => (Object.assign(Object.assign({}, prevState), { loading: true })));
170
175
  try {
171
- const response = yield api.delete(DELETE_ASSET_FIELD_URL.replace(":assetId", id).replace(":id", get(selectedField, "_id")));
176
+ const response = yield api.delete(DELETE_ASSET_FIELD_URL.replace(":assetId", assetId).replace(":id", get(selectedField, "_id")));
172
177
  const updatedFields = filter(fields, (field, index) => get(field, "_id") !== get(selectedField, "_id"));
173
178
  const updatedImagePickerOutputFormat = filter(imagePickerOutputFormat, (field, index) => get(field, "mapId") !== get(selectedField, "mapId"));
174
179
  setState((prevState) => (Object.assign(Object.assign({}, prevState), { fields: updatedFields, currentFieldIndex: null, imagePickerOutputFormat: updatedImagePickerOutputFormat })));
@@ -9,11 +9,12 @@ 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, useMemo } from "react";
12
+ import { useState } from "react";
13
+ import axios from "axios";
13
14
  import CreateClientForm from "./CreateClientForm";
14
15
  import { useDamConfig } from "../hocs/DamConfigContext";
15
- import { createApiClient } from "../hocs/configureAxios";
16
- import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
16
+ import { getBaseUrl } from "../hocs/helpers";
17
+ import { REFRESH_KEY_URL, USER_LOGIN } from "../utilities/constants/apiUrls";
17
18
  import { showNotification } from "../common/notifications";
18
19
  import { NotificationStatus } from "../utilities/constants/interface";
19
20
  import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
@@ -23,7 +24,7 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
23
24
  const [refreshingKey, setRefreshingKey] = useState(false);
24
25
  const isEditMode = !!existingClientData;
25
26
  const damConfig = useDamConfig();
26
- const api = useMemo(() => createApiClient(damConfig), [damConfig]);
27
+ const { appType, teamIds } = damConfig;
27
28
  const toggleShow = () => {
28
29
  setShowForm(!showForm);
29
30
  };
@@ -32,11 +33,32 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
32
33
  showNotification("Access key and secret key are required to refresh", NotificationStatus.ERROR);
33
34
  return;
34
35
  }
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
+ }
35
43
  setRefreshingKey(true);
36
44
  try {
37
- const response = yield api.put(REFRESH_KEY_URL, {
38
- accessKey: existingClientData.accessKey,
39
- secretKey: existingClientData.secretKey,
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
+ },
40
62
  });
41
63
  setRefreshingKey(false);
42
64
  showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
@@ -45,7 +67,7 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
45
67
  }
46
68
  }
47
69
  catch (error) {
48
- showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
70
+ showNotification(get(error, "response.data.message", get(error, "message", SOMETHING_WENT_WRONG)), NotificationStatus.ERROR);
49
71
  setRefreshingKey(false);
50
72
  }
51
73
  });
@@ -2,5 +2,5 @@ import { type FolderTypes } from "../utilities/FoldersContext";
2
2
  export default function MyDriveMainContainer({ folders, setFolders, onFolderChange, }: {
3
3
  folders: FolderTypes[];
4
4
  setFolders: React.Dispatch<React.SetStateAction<FolderTypes[]>>;
5
- onFolderChange?: (folderId: string) => void;
5
+ onFolderChange?: (folderId: string | undefined) => void;
6
6
  }): JSX.Element;
@@ -51,13 +51,16 @@ export default function MyDriveMainContainer({ folders, setFolders, onFolderChan
51
51
  setExpandedKeys(map(keys, (k) => k.toString()));
52
52
  };
53
53
  // Wrapper function to handle both string and string[] for setSelectedKeys
54
+ // Also updates URL via onFolderChange so folder persists on refresh
54
55
  const handleSetSelectedKeys = (keys) => {
55
56
  const next = typeof keys === "string" ? [keys] : keys;
56
57
  setSelectedKeys(next);
57
58
  const singleFolderId = Array.isArray(next) && next.length === 1 ? next[0] : null;
58
- if (singleFolderId && onFolderChange) {
59
- onFolderChange(singleFolderId);
59
+ if (onFolderChange) {
60
+ // Update URL: subfolder id for subfolders, undefined for root/My Drive (so URL stays /digital-asset-management)
61
+ const urlFolderId = singleFolderId && singleFolderId !== rootFolderId ? singleFolderId : undefined;
62
+ onFolderChange(urlFolderId);
60
63
  }
61
64
  };
62
- return (_jsxs(FoldersProvider, { value: { setFolders, folders, globalSearch }, children: [_jsx(FolderTree, { currentRootId: currentRootId, handleExpand: handleExpand, setSelectedKeys: setSelectedKeys, expandedKeys: expandedKeys, selectedKeys: selectedKeys, folders: folders, setExpandedKeys: setExpandedKeys, setFolders: setFolders, setGlobalSearch: setGlobalSearch, globalSearch: globalSearch }), _jsx("div", { className: "md-lib-h-[inherit] md-lib-overflow-x-auto", children: _jsx(DriveContainer, { parentFolderId: selectedFolderId, globalSearch: globalSearch, setGlobalSearch: setGlobalSearch, setSelectedKeys: handleSetSelectedKeys }) })] }));
65
+ return (_jsxs(FoldersProvider, { value: { setFolders, folders, globalSearch }, children: [_jsx(FolderTree, { currentRootId: currentRootId, handleExpand: handleExpand, setSelectedKeys: handleSetSelectedKeys, expandedKeys: expandedKeys, selectedKeys: selectedKeys, folders: folders, setExpandedKeys: setExpandedKeys, setFolders: setFolders, setGlobalSearch: setGlobalSearch, globalSearch: globalSearch }), _jsx("div", { className: "md-lib-h-[inherit] md-lib-overflow-x-auto", children: _jsx(DriveContainer, { parentFolderId: selectedFolderId, globalSearch: globalSearch, setGlobalSearch: setGlobalSearch, setSelectedKeys: handleSetSelectedKeys }) })] }));
63
66
  }
@@ -231,7 +231,15 @@ function MapFile({ open, handleCancel, filesList, fromUpload, parentFolderId, })
231
231
  },
232
232
  });
233
233
  };
234
- const getMetadataForm = (_jsxs(Form, { layout: "vertical", form: form, scrollToFirstError: true, onFinish: fromUpload ? handleSubmit : handleUpdate, className: "md-lib-m-2", children: [_jsx(AssetSelectionFormItem, { handleAssetTemplateChange: handleAssetTemplateChange, assetOptions: assetOptions, assetsLoading: assetsLoading }), selectedAssetTemplate && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { name: "teamIds", label: "Teams", children: _jsx(Select, { options: teamOptions, placeholder: "Select teams", mode: "multiple", onChange: (val) => onChangeTeams(val), style: { width: "100%" }, showSearch: true, optionFilterProp: "key" }) }), _jsx(Form.Item, { name: "expiryDate", label: "Expiry Date", children: _jsx(DatePicker, { placeholder: "Expiry Date", style: { width: "100%" } }) }), _jsx(Metadata, { asset: selectedAssetTemplate, form: form, file: (filesList === null || filesList === void 0 ? void 0 : filesList[0]) || null })] })), _jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-justify-end md-lib-gap-3", children: [_jsx(Button, { onClick: handleCancelWithConfirmation, children: "Cancel" }), _jsx(Button, { disabled: !selectedAssetTemplate, type: "primary",
234
+ const preventEnterSubmit = (e) => {
235
+ if (e.key === "Enter" && e.target instanceof HTMLElement) {
236
+ const tagName = e.target.tagName.toLowerCase();
237
+ if (tagName !== "textarea") {
238
+ e.preventDefault();
239
+ }
240
+ }
241
+ };
242
+ const getMetadataForm = (_jsxs(Form, { layout: "vertical", form: form, scrollToFirstError: true, onFinish: fromUpload ? handleSubmit : handleUpdate, onKeyDown: preventEnterSubmit, className: "md-lib-m-2", children: [_jsx(AssetSelectionFormItem, { handleAssetTemplateChange: handleAssetTemplateChange, assetOptions: assetOptions, assetsLoading: assetsLoading }), selectedAssetTemplate && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { name: "teamIds", label: "Teams", children: _jsx(Select, { options: teamOptions, placeholder: "Select teams", mode: "multiple", onChange: (val) => onChangeTeams(val), style: { width: "100%" }, showSearch: true, optionFilterProp: "key" }) }), _jsx(Form.Item, { name: "expiryDate", label: "Expiry Date", children: _jsx(DatePicker, { placeholder: "Expiry Date", style: { width: "100%" } }) }), _jsx(Metadata, { asset: selectedAssetTemplate, form: form, file: (filesList === null || filesList === void 0 ? void 0 : filesList[0]) || null })] })), _jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-justify-end md-lib-gap-3", children: [_jsx(Button, { onClick: handleCancelWithConfirmation, children: "Cancel" }), _jsx(Button, { disabled: !selectedAssetTemplate, type: "primary",
235
243
  // onClick={handleSubmit}
236
244
  loading: loading || updateFileMutation.isLoading, htmlType: "submit", children: "Save" })] })] }));
237
245
  return (_jsx(_Fragment, { children: fromUpload ? (_jsx(Drawer, { title: "Metadata", open: open, onClose: handleCancelWithConfirmation, maskClosable: false, children: getMetadataForm })) : (_jsxs("div", { className: "md-lib-p-2 md-lib-overflow-y-scroll md-lib-max-h-[calc(100vh-65px)]", children: [_jsx("p", { className: "md-lib-text-lg md-lib-font-semibold", children: "Metadata" }), getMetadataForm] })) }));
@@ -11,7 +11,7 @@ declare function App(props: {
11
11
  parentId?: string;
12
12
  showSubfolders?: boolean;
13
13
  userEmail?: string;
14
- onFolderChange?: (folderId: string) => void;
14
+ onFolderChange?: (folderId: string | undefined) => void;
15
15
  /** Height of host app header (e.g. navbar) in px. When set, preview modal positions below it instead of covering. */
16
16
  headerHeight?: number;
17
17
  }): JSX.Element;
@@ -4,7 +4,7 @@ type AppRoutesProps = {
4
4
  folders: FolderTypes[];
5
5
  setFolders: React.Dispatch<React.SetStateAction<FolderTypes[]>>;
6
6
  routerVersion: 4 | 5 | 6;
7
- onFolderChange?: (folderId: string) => void;
7
+ onFolderChange?: (folderId: string | undefined) => void;
8
8
  };
9
9
  export default function AppRoutes({ folders, setFolders, routerVersion, onFolderChange, }: AppRoutesProps): JSX.Element;
10
10
  export {};
@@ -9,32 +9,49 @@ 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 { useMemo, useState } from "react";
12
+ import { useState } from "react";
13
+ import axios from "axios";
13
14
  import { showNotification } from "../common/notifications";
14
15
  import { NotificationStatus } from "../utilities/constants/interface";
15
16
  import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
16
17
  import { get } from "lodash";
17
- import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
18
+ import { REFRESH_KEY_URL, USER_LOGIN } from "../utilities/constants/apiUrls";
18
19
  import { useDamConfig } from "../hocs/DamConfigContext";
19
- import { createApiClient } from "../hocs/configureAxios";
20
+ import { getBaseUrl } from "../hocs/helpers";
20
21
  export default function RefreshKeyBtn() {
21
22
  const [loading, setLoading] = useState(false);
22
23
  const damConfig = useDamConfig();
23
- const { damAccessKey, secretKey } = damConfig;
24
- const api = useMemo(() => createApiClient(damConfig), [damConfig]);
24
+ const { damAccessKey, secretKey, subdomain, teamIds, appType } = 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
+ }
26
30
  setLoading(true);
27
31
  try {
28
- const response = yield api.put(REFRESH_KEY_URL, {
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, {
29
34
  accessKey: damAccessKey,
30
35
  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
+ },
31
49
  });
32
- // console.log(response);
33
50
  setLoading(false);
34
51
  showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
35
52
  }
36
53
  catch (error) {
37
- showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
54
+ showNotification(get(error, "response.data.message", get(error, "message", SOMETHING_WENT_WRONG)), NotificationStatus.ERROR);
38
55
  setLoading(false);
39
56
  }
40
57
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.189",
3
+ "version": "5.8.193",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",