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

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;
@@ -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;
@@ -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;
@@ -15,6 +15,7 @@ import { useDamConfig } from "../hocs/DamConfigContext";
15
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
+ 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";
@@ -27,6 +28,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
27
28
  const [damLocationType, setDamLocationType] = useState("external");
28
29
  const [filteredTeams, setFilteredTeams] = useState([]);
29
30
  const [clientData, setClientData] = useState(null);
31
+ const [teamsFetched, setTeamsFetched] = useState(false);
30
32
  const api = useMemo(() => createApiClient(damConfig), [damConfig]);
31
33
  const [form] = Form.useForm();
32
34
  const isEditMode = !!existingClientData;
@@ -37,15 +39,27 @@ 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);
62
+ setTeamsFetched(false); // Reset teams fetched flag when new client data is loaded
49
63
  // Populate form with existing client data
50
64
  if (fetchedData && Object.keys(fetchedData).length > 0) {
51
65
  const damLocationDetails = get(fetchedData, "damLocationDetails", {});
@@ -78,10 +92,15 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
78
92
  }
79
93
  });
80
94
  fetchClientData();
81
- }, [isEditMode, existingClientData, api, form, filteredTeams]);
95
+ }, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api]);
82
96
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
83
- var _a, _b, _c, _d, _e, _f, _g, _h;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
84
98
  try {
99
+ // Use teamsApiDetails from clientData if available (from API response), otherwise use props
100
+ const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
101
+ const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
102
+ const finalUsername = teamsApiDetailsFromData.username || username;
103
+ const finalPassword = teamsApiDetailsFromData.password || password;
85
104
  const values = Object.assign(Object.assign({}, data), { showFilePreview: (_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false, accessKey: appType == "reactJs"
86
105
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
87
106
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
@@ -89,13 +108,13 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
89
108
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
90
109
  ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
91
110
  : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
92
- teamsApi: teamsApi,
93
- username: username,
94
- password: password,
111
+ teamsApi: finalTeamsApi,
112
+ username: finalUsername,
113
+ password: finalPassword,
95
114
  }, damLocationDetails: damLocationType === "external"
96
115
  ? {
97
116
  bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
98
- locationType: damLocationType === "external" ? "EXTERNAL" : "INTERNAL",
117
+ locationType: "EXTERNAL",
99
118
  rootPath: (_c = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _c === void 0 ? void 0 : _c.rootPath,
100
119
  accessKeyId: (_d = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _d === void 0 ? void 0 : _d.accessKeyId,
101
120
  secretAccessKey: (_e = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _e === void 0 ? void 0 : _e.secretAccessKey,
@@ -103,12 +122,13 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
103
122
  region: (_g = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _g === void 0 ? void 0 : _g.region,
104
123
  }
105
124
  : {
106
- locationType: damLocationType === "external" ? "EXTERNAL" : "INTERNAL",
125
+ locationType: "INTERNAL",
126
+ rootPath: (_h = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _h === void 0 ? void 0 : _h.rootPath,
107
127
  } });
108
128
  setLoading(true);
109
129
  const response = yield api.post(CREATE_SUB_BRAND, values);
110
130
  setLoading(false);
111
- showNotification((_h = response === null || response === void 0 ? void 0 : response.message) !== null && _h !== void 0 ? _h : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
131
+ showNotification((_j = response === null || response === void 0 ? void 0 : response.message) !== null && _j !== void 0 ? _j : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
112
132
  toggleShow();
113
133
  if (onSuccess) {
114
134
  onSuccess(response === null || response === void 0 ? void 0 : response.data);
@@ -150,18 +170,28 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
150
170
  },
151
171
  });
152
172
  }
153
- }, [clientData, filteredTeams, form, existingClientData]);
173
+ }, [clientData, form, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain]);
174
+ // Extract teamsApiDetails from clientData to avoid dependency on entire clientData object
175
+ const teamsApiFromData = useMemo(() => get(clientData, "teamsApiDetails.teamsApi"), [clientData]);
176
+ const usernameFromData = useMemo(() => get(clientData, "teamsApiDetails.username"), [clientData]);
177
+ const passwordFromData = useMemo(() => get(clientData, "teamsApiDetails.password"), [clientData]);
154
178
  useEffect(() => {
155
- if (teamsApi && username && password) {
156
- fetchTeams();
179
+ // Use teamsApiDetails from clientData if available, otherwise use props
180
+ const finalTeamsApi = teamsApiFromData || teamsApi;
181
+ const finalUsername = usernameFromData || username;
182
+ const finalPassword = passwordFromData || password;
183
+ // Only fetch teams if we have the required credentials and haven't fetched yet
184
+ if (!teamsFetched && finalTeamsApi && finalUsername && finalPassword) {
185
+ fetchTeams(finalTeamsApi, finalUsername, finalPassword);
186
+ setTeamsFetched(true);
157
187
  }
158
- }, [teamsApi, username, password]);
159
- const fetchTeams = () => __awaiter(void 0, void 0, void 0, function* () {
188
+ }, [teamsApi, username, password, teamsApiFromData, usernameFromData, passwordFromData, teamsFetched]);
189
+ const fetchTeams = (apiUrl, apiUsername, apiPassword) => __awaiter(void 0, void 0, void 0, function* () {
160
190
  var _a, _b;
161
191
  try {
162
- const response = yield axios.get(teamsApi, {
192
+ const response = yield axios.get(apiUrl, {
163
193
  headers: {
164
- Authorization: "Basic " + btoa(username + ":" + password),
194
+ Authorization: "Basic " + btoa(apiUsername + ":" + apiPassword),
165
195
  },
166
196
  });
167
197
  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) => {
@@ -202,17 +232,17 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
202
232
  },
203
233
  ], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
204
234
  onChangeDamLocationType(e);
205
- }, placeholder: "Type" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
235
+ }, placeholder: "Type" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
236
+ {
237
+ required: true,
238
+ message: "Root path is required",
239
+ },
240
+ ], children: _jsx(Input, { placeholder: "Root path" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
206
241
  {
207
242
  required: damLocationType === "external",
208
243
  message: "Bucket is required",
209
244
  },
210
- ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
211
- {
212
- required: damLocationType === "external",
213
- message: "Root path is required",
214
- },
215
- ], children: _jsx(Input, { placeholder: "Root path", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
245
+ ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
216
246
  {
217
247
  required: damLocationType === "external",
218
248
  message: "Access key is required",
@@ -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.159",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",