@bindu-dashing/dam-solution-v2 5.8.156 → 5.8.158

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.
@@ -8,6 +8,7 @@ declare const CreateClient: ({ onSuccess, clientSubdomain, teamsApi, username, p
8
8
  accessKey: string;
9
9
  secretKey: string;
10
10
  subdomain: string;
11
+ brandId?: string;
11
12
  } | null;
12
13
  }) => JSX.Element;
13
14
  export default CreateClient;
@@ -9,6 +9,7 @@ declare const CreateClientForm: ({ teamsApi, username, password, toggleShow, onS
9
9
  accessKey: string;
10
10
  secretKey: string;
11
11
  subdomain: string;
12
+ brandId?: string;
12
13
  } | null;
13
14
  }) => JSX.Element;
14
15
  export default CreateClientForm;
@@ -8,13 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
- import { Button, Checkbox, Drawer, Form, Input, Select, Typography } from "antd";
11
+ import { Button, Checkbox, Drawer, Form, Input, Select, Typography, Space } 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, REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
16
16
  import axios from "axios";
17
17
  import { createApiClient } from "../hocs/configureAxios";
18
+ import { fetchBrandDetails } from "../react-query/services/brand-services";
18
19
  import { CREATE_SUCCESS, SOMETHING_WENT_WRONG, } from "../utilities/constants/messages";
19
20
  import { NotificationStatus } from "../utilities/constants/interface";
20
21
  import { showNotification } from "../common/notifications";
@@ -24,6 +25,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
24
25
  const { appType, brand } = damConfig;
25
26
  const [loading, setLoading] = useState(false);
26
27
  const [fetchingClientData, setFetchingClientData] = useState(false);
28
+ const [refreshingKey, setRefreshingKey] = useState(false);
27
29
  const [damLocationType, setDamLocationType] = useState("external");
28
30
  const [filteredTeams, setFilteredTeams] = useState([]);
29
31
  const [clientData, setClientData] = useState(null);
@@ -37,12 +39,23 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
37
39
  // Fetch client data when editing
38
40
  useEffect(() => {
39
41
  const fetchClientData = () => __awaiter(void 0, void 0, void 0, function* () {
40
- if (isEditMode && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
42
+ if (isEditMode) {
41
43
  setFetchingClientData(true);
42
44
  try {
43
- const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
44
- // API response structure: { status: true, code: 200, data: { _id, name, adminTeams, subdomain, ... } }
45
- const fetchedData = get(response, "data.data", {});
45
+ let fetchedData;
46
+ // Prioritize brandId if available, otherwise use subdomain
47
+ if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) {
48
+ // Use reusable fetchBrandDetails function
49
+ fetchedData = yield fetchBrandDetails(api, existingClientData.brandId);
50
+ }
51
+ else if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
52
+ const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
53
+ fetchedData = get(response, "data.data", {});
54
+ }
55
+ else {
56
+ setFetchingClientData(false);
57
+ return;
58
+ }
46
59
  console.log("Fetched client data:", fetchedData);
47
60
  // Store client data in state
48
61
  setClientData(fetchedData);
@@ -82,6 +95,11 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
82
95
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
83
96
  var _a, _b, _c, _d, _e, _f, _g, _h;
84
97
  try {
98
+ // Use teamsApiDetails from clientData if available (from API response), otherwise use props
99
+ const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
100
+ const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
101
+ const finalUsername = teamsApiDetailsFromData.username || username;
102
+ const finalPassword = teamsApiDetailsFromData.password || password;
85
103
  const values = Object.assign(Object.assign({}, data), { showFilePreview: (_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false, accessKey: appType == "reactJs"
86
104
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
87
105
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
@@ -89,9 +107,9 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
89
107
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
90
108
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
91
109
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
92
- teamsApi: teamsApi,
93
- username: username,
94
- password: password,
110
+ teamsApi: finalTeamsApi,
111
+ username: finalUsername,
112
+ password: finalPassword,
95
113
  }, damLocationDetails: damLocationType === "external"
96
114
  ? {
97
115
  bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
@@ -152,16 +170,24 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
152
170
  }
153
171
  }, [clientData, filteredTeams, form, existingClientData]);
154
172
  useEffect(() => {
155
- if (teamsApi && username && password) {
156
- fetchTeams();
173
+ // Use teamsApiDetails from clientData if available, otherwise use props
174
+ const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
175
+ const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
176
+ const finalUsername = teamsApiDetailsFromData.username || username;
177
+ const finalPassword = teamsApiDetailsFromData.password || password;
178
+ if (finalTeamsApi && finalUsername && finalPassword) {
179
+ fetchTeams(finalTeamsApi, finalUsername, finalPassword);
157
180
  }
158
- }, [teamsApi, username, password]);
159
- const fetchTeams = () => __awaiter(void 0, void 0, void 0, function* () {
181
+ else if (teamsApi && username && password) {
182
+ fetchTeams(teamsApi, username, password);
183
+ }
184
+ }, [teamsApi, username, password, clientData]);
185
+ const fetchTeams = (apiUrl, apiUsername, apiPassword) => __awaiter(void 0, void 0, void 0, function* () {
160
186
  var _a, _b;
161
187
  try {
162
- const response = yield axios.get(teamsApi, {
188
+ const response = yield axios.get(apiUrl, {
163
189
  headers: {
164
- Authorization: "Basic " + btoa(username + ":" + password),
190
+ Authorization: "Basic " + btoa(apiUsername + ":" + apiPassword),
165
191
  },
166
192
  });
167
193
  const options = (_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.map((team) => {
@@ -177,6 +203,26 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
177
203
  console.log("Error while fetching external teams", err);
178
204
  }
179
205
  });
206
+ // Refresh key functionality
207
+ const onRefreshKey = () => __awaiter(void 0, void 0, void 0, function* () {
208
+ if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) || !(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey)) {
209
+ showNotification("Access key and secret key are required to refresh", NotificationStatus.ERROR);
210
+ return;
211
+ }
212
+ setRefreshingKey(true);
213
+ try {
214
+ const response = yield api.put(REFRESH_KEY_URL, {
215
+ accessKey: existingClientData.accessKey,
216
+ secretKey: existingClientData.secretKey,
217
+ });
218
+ setRefreshingKey(false);
219
+ showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
220
+ }
221
+ catch (error) {
222
+ showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
223
+ setRefreshingKey(false);
224
+ }
225
+ });
180
226
  // Debug: Log edit mode and location type
181
227
  const shouldShowExternalFields = damLocationType === "external" || isEditMode;
182
228
  console.log("CreateClientForm - isEditMode:", isEditMode, "damLocationType:", damLocationType, "shouldShowExternalFields:", shouldShowExternalFields, "existingClientData:", existingClientData);
@@ -237,6 +283,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
237
283
  required: true,
238
284
  message: "Subdomain is required",
239
285
  },
240
- ], children: _jsx(Input, { placeholder: "Subdomain" }) }), _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, children: "Submit" }) })] })) }));
286
+ ], children: _jsx(Input, { placeholder: "Subdomain" }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview Editor" }) }), _jsx(Form.Item, { children: _jsxs(Space, { style: { width: "100%" }, children: [_jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, children: "Submit" }), isEditMode && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey) && (_jsx(Button, { type: "default", loading: refreshingKey, onClick: onRefreshKey, children: "Refresh Key" }))] }) })] })) }));
241
287
  };
242
288
  export default CreateClientForm;
@@ -14,6 +14,7 @@ declare function App(props: {
14
14
  accessKey: string;
15
15
  secretKey: string;
16
16
  subdomain: string;
17
+ brandId?: string;
17
18
  } | null;
18
19
  }): JSX.Element;
19
20
  export default App;
@@ -1,3 +1,4 @@
1
+ export declare function fetchBrandDetails(api: any, brandId: string): Promise<any>;
1
2
  export declare function useCurrentBrand(headers: {
2
3
  headers: any;
3
4
  }, brandId: string, enabled: boolean): import("react-query").UseQueryResult<any, unknown>;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { FETCH_BRAND_URL } from "../../utilities/constants/apiUrls";
10
+ import { FETCH_BRAND_URL, FETCH_BRAND_DETAILS_URL } from "../../utilities/constants/apiUrls";
11
11
  import { QueryKeys } from "../../utilities/constants/queryKeys";
12
12
  import { get } from "lodash";
13
13
  import { useQuery } from "react-query";
@@ -22,6 +22,19 @@ function fetchBrand(api, brandId) {
22
22
  }
23
23
  });
24
24
  }
25
+ export function fetchBrandDetails(api, brandId) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ try {
28
+ const response = yield api.get(FETCH_BRAND_DETAILS_URL.replace(":brandId", brandId));
29
+ // API response structure: { status: true, code: 200, data: { ... } }
30
+ // The axios interceptor already extracts response.data, so response is { status, code, data }
31
+ return get(response, "data", {});
32
+ }
33
+ catch (error) {
34
+ throw error;
35
+ }
36
+ });
37
+ }
25
38
  export function useCurrentBrand(headers, brandId, enabled) {
26
39
  return useQuery([QueryKeys.BRAND, brandId], () => fetchBrand(headers, brandId), {
27
40
  enabled: enabled && !!get(headers, "headers.Authorization"),
@@ -83,6 +83,7 @@ export declare const USER_LOGIN = "/users/login/keys";
83
83
  export declare const FETCH_BRAND_USING_SUBDOMAIN = "/brands/subdomain";
84
84
  export declare const FETCH_TEAMS_LIST = "/teams/:teamID/list";
85
85
  export declare const CREATE_SUB_BRAND = "/brands/sub-brand";
86
+ export declare const FETCH_BRAND_DETAILS_URL = "/brands/details/:brandId";
86
87
  export declare const FETCH_IMAGEPICKERS_URL = "/image-picker";
87
88
  export declare const FETCH_IMAGEPICKER_URL = "/image-picker/:id";
88
89
  export declare const FETCH_META_FIELD_OPTIONS_URL = "/image-picker/file-filters/:id";
@@ -99,6 +99,7 @@ export const FETCH_BRAND_USING_SUBDOMAIN = "/brands/subdomain";
99
99
  export const FETCH_TEAMS_LIST = "/teams/:teamID/list";
100
100
  // brand
101
101
  export const CREATE_SUB_BRAND = "/brands/sub-brand";
102
+ export const FETCH_BRAND_DETAILS_URL = "/brands/details/:brandId";
102
103
  //image picker
103
104
  export const FETCH_IMAGEPICKERS_URL = "/image-picker";
104
105
  export const FETCH_IMAGEPICKER_URL = "/image-picker/:id";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.156",
3
+ "version": "5.8.158",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",