@bindu-dashing/dam-solution-v2 5.8.158 → 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.
|
@@ -1,13 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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;
|
|
@@ -59,6 +59,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
59
59
|
console.log("Fetched client data:", fetchedData);
|
|
60
60
|
// Store client data in state
|
|
61
61
|
setClientData(fetchedData);
|
|
62
|
+
setTeamsFetched(false); // Reset teams fetched flag when new client data is loaded
|
|
62
63
|
// Populate form with existing client data
|
|
63
64
|
if (fetchedData && Object.keys(fetchedData).length > 0) {
|
|
64
65
|
const damLocationDetails = get(fetchedData, "damLocationDetails", {});
|
|
@@ -91,9 +92,9 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
91
92
|
}
|
|
92
93
|
});
|
|
93
94
|
fetchClientData();
|
|
94
|
-
}, [isEditMode, existingClientData
|
|
95
|
+
}, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api]);
|
|
95
96
|
const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
97
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
97
98
|
try {
|
|
98
99
|
// Use teamsApiDetails from clientData if available (from API response), otherwise use props
|
|
99
100
|
const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
|
|
@@ -113,7 +114,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
113
114
|
}, damLocationDetails: damLocationType === "external"
|
|
114
115
|
? {
|
|
115
116
|
bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
|
|
116
|
-
locationType:
|
|
117
|
+
locationType: "EXTERNAL",
|
|
117
118
|
rootPath: (_c = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _c === void 0 ? void 0 : _c.rootPath,
|
|
118
119
|
accessKeyId: (_d = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _d === void 0 ? void 0 : _d.accessKeyId,
|
|
119
120
|
secretAccessKey: (_e = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _e === void 0 ? void 0 : _e.secretAccessKey,
|
|
@@ -121,12 +122,13 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
121
122
|
region: (_g = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _g === void 0 ? void 0 : _g.region,
|
|
122
123
|
}
|
|
123
124
|
: {
|
|
124
|
-
locationType:
|
|
125
|
+
locationType: "INTERNAL",
|
|
126
|
+
rootPath: (_h = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _h === void 0 ? void 0 : _h.rootPath,
|
|
125
127
|
} });
|
|
126
128
|
setLoading(true);
|
|
127
129
|
const response = yield api.post(CREATE_SUB_BRAND, values);
|
|
128
130
|
setLoading(false);
|
|
129
|
-
showNotification((
|
|
131
|
+
showNotification((_j = response === null || response === void 0 ? void 0 : response.message) !== null && _j !== void 0 ? _j : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
|
|
130
132
|
toggleShow();
|
|
131
133
|
if (onSuccess) {
|
|
132
134
|
onSuccess(response === null || response === void 0 ? void 0 : response.data);
|
|
@@ -168,20 +170,22 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
168
170
|
},
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
|
-
}, [clientData,
|
|
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]);
|
|
172
178
|
useEffect(() => {
|
|
173
179
|
// Use teamsApiDetails from clientData if available, otherwise use props
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
if (finalTeamsApi && finalUsername && finalPassword) {
|
|
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) {
|
|
179
185
|
fetchTeams(finalTeamsApi, finalUsername, finalPassword);
|
|
186
|
+
setTeamsFetched(true);
|
|
180
187
|
}
|
|
181
|
-
|
|
182
|
-
fetchTeams(teamsApi, username, password);
|
|
183
|
-
}
|
|
184
|
-
}, [teamsApi, username, password, clientData]);
|
|
188
|
+
}, [teamsApi, username, password, teamsApiFromData, usernameFromData, passwordFromData, teamsFetched]);
|
|
185
189
|
const fetchTeams = (apiUrl, apiUsername, apiPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
190
|
var _a, _b;
|
|
187
191
|
try {
|
|
@@ -203,26 +207,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
203
207
|
console.log("Error while fetching external teams", err);
|
|
204
208
|
}
|
|
205
209
|
});
|
|
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
210
|
// Debug: Log edit mode and location type
|
|
227
211
|
const shouldShowExternalFields = damLocationType === "external" || isEditMode;
|
|
228
212
|
console.log("CreateClientForm - isEditMode:", isEditMode, "damLocationType:", damLocationType, "shouldShowExternalFields:", shouldShowExternalFields, "existingClientData:", existingClientData);
|
|
@@ -248,17 +232,17 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
248
232
|
},
|
|
249
233
|
], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
|
|
250
234
|
onChangeDamLocationType(e);
|
|
251
|
-
}, placeholder: "Type" }) }),
|
|
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: [
|
|
252
241
|
{
|
|
253
242
|
required: damLocationType === "external",
|
|
254
243
|
message: "Bucket is required",
|
|
255
244
|
},
|
|
256
|
-
], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "
|
|
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: [
|
|
245
|
+
], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
|
|
262
246
|
{
|
|
263
247
|
required: damLocationType === "external",
|
|
264
248
|
message: "Access key is required",
|
|
@@ -283,6 +267,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
283
267
|
required: true,
|
|
284
268
|
message: "Subdomain is required",
|
|
285
269
|
},
|
|
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:
|
|
270
|
+
], 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
271
|
};
|
|
288
272
|
export default CreateClientForm;
|