@bindu-dashing/dam-solution-v2 5.8.190 → 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
@@ -285,6 +314,11 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
285
314
  return false;
286
315
  return d.hour() !== 0 || d.minute() !== 0 || d.second() !== 0;
287
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
+ };
288
322
  rules.push({
289
323
  validator: (_, value) => {
290
324
  const allowTime = !!get(settings, `${InputSupportedTypes.ALLOW_TIME}.allow`);
@@ -296,10 +330,14 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
296
330
  typeof value.hour === "function" &&
297
331
  typeof value.minute === "function" &&
298
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
+ }
299
337
  if (allowTime && !hasTimeMethods) {
300
338
  return Promise.reject("Please select a date with time (hour/minute/second).");
301
339
  }
302
- // When time is not allowed: reject only if user selected a non-zero time
340
+ // When time is not allowed: strip time (handled in onValuesChange) - reject only if still has non-zero time
303
341
  if (!allowTime && hasNonZeroTime(value)) {
304
342
  return Promise.reject("Time is not allowed. Please select only a date.");
305
343
  }
@@ -315,10 +353,16 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
315
353
  typeof end.hour === "function" &&
316
354
  typeof end.minute === "function" &&
317
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
+ }
318
362
  if (allowTime && (!startHasTimeMethods || !endHasTimeMethods)) {
319
363
  return Promise.reject("Please select both start and end dates with time.");
320
364
  }
321
- // When time is not allowed: reject only if user selected a non-zero time
365
+ // When time is not allowed: strip time (handled in onValuesChange) - reject only if still has non-zero time
322
366
  if (!allowTime && (hasNonZeroTime(start) || hasNonZeroTime(end))) {
323
367
  return Promise.reject("Time is not allowed. Please select only dates.");
324
368
  }
@@ -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
  }
@@ -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.190",
3
+ "version": "5.8.193",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",