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

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.
@@ -1,13 +1,54 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button } from "antd";
3
- import { useState } from "react";
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { Button, Space } from "antd";
12
+ import { useState, useMemo } from "react";
4
13
  import CreateClientForm from "./CreateClientForm";
14
+ import { useDamConfig } from "../hocs/DamConfigContext";
15
+ import { createApiClient } from "../hocs/configureAxios";
16
+ import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
17
+ import { showNotification } from "../common/notifications";
18
+ import { NotificationStatus } from "../utilities/constants/interface";
19
+ import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
20
+ import { get } from "lodash";
5
21
  const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password, existingClientData, }) => {
6
22
  const [showForm, setShowForm] = useState(false);
23
+ const [refreshingKey, setRefreshingKey] = useState(false);
7
24
  const isEditMode = !!existingClientData;
25
+ const damConfig = useDamConfig();
26
+ const api = useMemo(() => createApiClient(damConfig), [damConfig]);
8
27
  const toggleShow = () => {
9
28
  setShowForm(!showForm);
10
29
  };
11
- return (_jsxs(_Fragment, { children: [_jsx(Button, { type: "primary", onClick: toggleShow, children: isEditMode ? "Edit Client" : "Create Client" }), showForm && (_jsx(CreateClientForm, { toggleShow: toggleShow, onSuccess: onSuccess, clientSubdomain: clientSubdomain, teamsApi: teamsApi, username: username, password: password, existingClientData: existingClientData }))] }));
30
+ const onRefreshKey = () => __awaiter(void 0, void 0, void 0, function* () {
31
+ if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) || !(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey)) {
32
+ showNotification("Access key and secret key are required to refresh", NotificationStatus.ERROR);
33
+ return;
34
+ }
35
+ setRefreshingKey(true);
36
+ try {
37
+ const response = yield api.put(REFRESH_KEY_URL, {
38
+ accessKey: existingClientData.accessKey,
39
+ secretKey: existingClientData.secretKey,
40
+ });
41
+ setRefreshingKey(false);
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
+ }
46
+ }
47
+ catch (error) {
48
+ showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
49
+ setRefreshingKey(false);
50
+ }
51
+ });
52
+ return (_jsxs(_Fragment, { children: [_jsxs(Space, { children: [_jsx(Button, { type: "primary", onClick: toggleShow, children: isEditMode ? "Edit Client" : "Create Client" }), 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" }))] }), showForm && (_jsx(CreateClientForm, { toggleShow: toggleShow, onSuccess: onSuccess, clientSubdomain: clientSubdomain, teamsApi: teamsApi, username: username, password: password, existingClientData: existingClientData }))] }));
12
53
  };
13
54
  export default CreateClient;
@@ -8,11 +8,11 @@ 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, Space } from "antd";
11
+ import { Button, Checkbox, Drawer, Form, Input, Select, Typography } 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, REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
15
+ import { CREATE_SUB_BRAND, FETCH_BRAND_USING_SUBDOMAIN } from "../utilities/constants/apiUrls";
16
16
  import axios from "axios";
17
17
  import { createApiClient } from "../hocs/configureAxios";
18
18
  import { fetchBrandDetails } from "../react-query/services/brand-services";
@@ -25,10 +25,10 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
25
25
  const { appType, brand } = damConfig;
26
26
  const [loading, setLoading] = useState(false);
27
27
  const [fetchingClientData, setFetchingClientData] = useState(false);
28
- const [refreshingKey, setRefreshingKey] = useState(false);
29
28
  const [damLocationType, setDamLocationType] = useState("external");
30
29
  const [filteredTeams, setFilteredTeams] = useState([]);
31
30
  const [clientData, setClientData] = useState(null);
31
+ const [teamsFetched, setTeamsFetched] = useState(false);
32
32
  const api = useMemo(() => createApiClient(damConfig), [damConfig]);
33
33
  const [form] = Form.useForm();
34
34
  const isEditMode = !!existingClientData;
@@ -43,22 +43,36 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
43
43
  setFetchingClientData(true);
44
44
  try {
45
45
  let fetchedData;
46
- // Prioritize brandId if available, otherwise use subdomain
47
- if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId) {
46
+ let brandId = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId;
47
+ // If brandId is not provided, try to get it from subdomain first
48
+ if (!brandId && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
49
+ console.log("brandId not found, fetching by subdomain first:", existingClientData.subdomain);
50
+ const subdomainResponse = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
51
+ const subdomainData = get(subdomainResponse, "data.data", {});
52
+ brandId = get(subdomainData, "_id");
53
+ console.log("Extracted brandId from subdomain response:", brandId);
54
+ }
55
+ // Prioritize brandId if available, use brands/details endpoint
56
+ if (brandId) {
57
+ console.log("Fetching brand details using brandId:", brandId);
48
58
  // Use reusable fetchBrandDetails function
49
- fetchedData = yield fetchBrandDetails(api, existingClientData.brandId);
59
+ fetchedData = yield fetchBrandDetails(api, brandId);
60
+ console.log("Fetched client data from brands/details:", fetchedData);
50
61
  }
51
62
  else if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
63
+ console.log("No brandId available, using subdomain endpoint:", existingClientData.subdomain);
52
64
  const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
53
65
  fetchedData = get(response, "data.data", {});
66
+ console.log("Fetched client data from subdomain:", fetchedData);
54
67
  }
55
68
  else {
69
+ console.warn("No brandId or subdomain provided");
56
70
  setFetchingClientData(false);
57
71
  return;
58
72
  }
59
- console.log("Fetched client data:", fetchedData);
60
73
  // Store client data in state
61
74
  setClientData(fetchedData);
75
+ setTeamsFetched(false); // Reset teams fetched flag when new client data is loaded
62
76
  // Populate form with existing client data
63
77
  if (fetchedData && Object.keys(fetchedData).length > 0) {
64
78
  const damLocationDetails = get(fetchedData, "damLocationDetails", {});
@@ -91,9 +105,9 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
91
105
  }
92
106
  });
93
107
  fetchClientData();
94
- }, [isEditMode, existingClientData, api, form, filteredTeams]);
108
+ }, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api, form]);
95
109
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
96
- var _a, _b, _c, _d, _e, _f, _g, _h;
110
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
97
111
  try {
98
112
  // Use teamsApiDetails from clientData if available (from API response), otherwise use props
99
113
  const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
@@ -113,7 +127,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
113
127
  }, damLocationDetails: damLocationType === "external"
114
128
  ? {
115
129
  bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
116
- locationType: damLocationType === "external" ? "EXTERNAL" : "INTERNAL",
130
+ locationType: "EXTERNAL",
117
131
  rootPath: (_c = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _c === void 0 ? void 0 : _c.rootPath,
118
132
  accessKeyId: (_d = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _d === void 0 ? void 0 : _d.accessKeyId,
119
133
  secretAccessKey: (_e = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _e === void 0 ? void 0 : _e.secretAccessKey,
@@ -121,12 +135,13 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
121
135
  region: (_g = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _g === void 0 ? void 0 : _g.region,
122
136
  }
123
137
  : {
124
- locationType: damLocationType === "external" ? "EXTERNAL" : "INTERNAL",
138
+ locationType: "INTERNAL",
139
+ rootPath: (_h = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _h === void 0 ? void 0 : _h.rootPath,
125
140
  } });
126
141
  setLoading(true);
127
142
  const response = yield api.post(CREATE_SUB_BRAND, values);
128
143
  setLoading(false);
129
- showNotification((_h = response === null || response === void 0 ? void 0 : response.message) !== null && _h !== void 0 ? _h : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
144
+ showNotification((_j = response === null || response === void 0 ? void 0 : response.message) !== null && _j !== void 0 ? _j : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
130
145
  toggleShow();
131
146
  if (onSuccess) {
132
147
  onSuccess(response === null || response === void 0 ? void 0 : response.data);
@@ -168,20 +183,22 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
168
183
  },
169
184
  });
170
185
  }
171
- }, [clientData, filteredTeams, form, existingClientData]);
186
+ }, [clientData, form, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain]);
187
+ // Extract teamsApiDetails from clientData to avoid dependency on entire clientData object
188
+ const teamsApiFromData = useMemo(() => get(clientData, "teamsApiDetails.teamsApi"), [clientData]);
189
+ const usernameFromData = useMemo(() => get(clientData, "teamsApiDetails.username"), [clientData]);
190
+ const passwordFromData = useMemo(() => get(clientData, "teamsApiDetails.password"), [clientData]);
172
191
  useEffect(() => {
173
192
  // 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) {
193
+ const finalTeamsApi = teamsApiFromData || teamsApi;
194
+ const finalUsername = usernameFromData || username;
195
+ const finalPassword = passwordFromData || password;
196
+ // Only fetch teams if we have the required credentials and haven't fetched yet
197
+ if (!teamsFetched && finalTeamsApi && finalUsername && finalPassword) {
179
198
  fetchTeams(finalTeamsApi, finalUsername, finalPassword);
199
+ setTeamsFetched(true);
180
200
  }
181
- else if (teamsApi && username && password) {
182
- fetchTeams(teamsApi, username, password);
183
- }
184
- }, [teamsApi, username, password, clientData]);
201
+ }, [teamsApi, username, password, teamsApiFromData, usernameFromData, passwordFromData, teamsFetched]);
185
202
  const fetchTeams = (apiUrl, apiUsername, apiPassword) => __awaiter(void 0, void 0, void 0, function* () {
186
203
  var _a, _b;
187
204
  try {
@@ -203,26 +220,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
203
220
  console.log("Error while fetching external teams", err);
204
221
  }
205
222
  });
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
- });
226
223
  // Debug: Log edit mode and location type
227
224
  const shouldShowExternalFields = damLocationType === "external" || isEditMode;
228
225
  console.log("CreateClientForm - isEditMode:", isEditMode, "damLocationType:", damLocationType, "shouldShowExternalFields:", shouldShowExternalFields, "existingClientData:", existingClientData);
@@ -248,17 +245,17 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
248
245
  },
249
246
  ], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
250
247
  onChangeDamLocationType(e);
251
- }, placeholder: "Type" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
248
+ }, placeholder: "Type" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
249
+ {
250
+ required: true,
251
+ message: "Root path is required",
252
+ },
253
+ ], children: _jsx(Input, { placeholder: "Root path" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
252
254
  {
253
255
  required: damLocationType === "external",
254
256
  message: "Bucket is required",
255
257
  },
256
- ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
257
- {
258
- required: damLocationType === "external",
259
- message: "Root path is required",
260
- },
261
- ], children: _jsx(Input, { placeholder: "Root path", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
258
+ ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
262
259
  {
263
260
  required: damLocationType === "external",
264
261
  message: "Access key is required",
@@ -283,6 +280,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
283
280
  required: true,
284
281
  message: "Subdomain is required",
285
282
  },
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" }))] }) })] })) }));
283
+ ], 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" }) })] })) }));
287
284
  };
288
285
  export default CreateClientForm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.158",
3
+ "version": "5.8.160",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",