@bindu-dashing/dam-solution-v2 5.8.198 → 5.8.202
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.
|
@@ -9,12 +9,11 @@ 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 } from "react";
|
|
13
|
-
import axios from "axios";
|
|
12
|
+
import { useState, useMemo } from "react";
|
|
14
13
|
import CreateClientForm from "./CreateClientForm";
|
|
15
14
|
import { useDamConfig } from "../hocs/DamConfigContext";
|
|
16
|
-
import {
|
|
17
|
-
import { REFRESH_KEY_URL
|
|
15
|
+
import { createApiClient } from "../hocs/configureAxios";
|
|
16
|
+
import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
|
|
18
17
|
import { showNotification } from "../common/notifications";
|
|
19
18
|
import { NotificationStatus } from "../utilities/constants/interface";
|
|
20
19
|
import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
|
|
@@ -24,57 +23,29 @@ const CreateClient = ({ onSuccess, clientSubdomain, teamsApi, username, password
|
|
|
24
23
|
const [refreshingKey, setRefreshingKey] = useState(false);
|
|
25
24
|
const isEditMode = !!existingClientData;
|
|
26
25
|
const damConfig = useDamConfig();
|
|
27
|
-
const
|
|
26
|
+
const api = useMemo(() => createApiClient(damConfig), [damConfig]);
|
|
28
27
|
const toggleShow = () => {
|
|
29
28
|
setShowForm(!showForm);
|
|
30
29
|
};
|
|
31
30
|
const onRefreshKey = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
var _a, _b;
|
|
33
31
|
if (!(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) || !(existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey)) {
|
|
34
32
|
showNotification("Access key and secret key are required to refresh", NotificationStatus.ERROR);
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
const accessKey = existingClientData.accessKey;
|
|
38
|
-
const secretKey = existingClientData.secretKey;
|
|
39
|
-
const subdomain = existingClientData.subdomain || clientSubdomain || (damConfig === null || damConfig === void 0 ? void 0 : damConfig.subdomain) || "";
|
|
40
|
-
if (!subdomain) {
|
|
41
|
-
showNotification("Subdomain is required to refresh key", NotificationStatus.ERROR);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
35
|
setRefreshingKey(true);
|
|
45
36
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
secretKey,
|
|
50
|
-
subdomain,
|
|
51
|
-
teams: teamIds && teamIds.length > 0 ? teamIds : [""],
|
|
52
|
-
});
|
|
53
|
-
const token = get(loginResponse, "data.data.access_token");
|
|
54
|
-
if (!token) {
|
|
55
|
-
throw new Error("Failed to get token from login");
|
|
56
|
-
}
|
|
57
|
-
// Step 2: Call refresh API with the DAM token (include subdomain header)
|
|
58
|
-
const response = yield axios.put(getBaseUrl(appType) + REFRESH_KEY_URL, { accessKey, secretKey }, {
|
|
59
|
-
headers: {
|
|
60
|
-
Authorization: `Bearer ${token}`,
|
|
61
|
-
subdomain: subdomain,
|
|
62
|
-
},
|
|
37
|
+
const response = yield api.put(REFRESH_KEY_URL, {
|
|
38
|
+
accessKey: existingClientData.accessKey,
|
|
39
|
+
secretKey: existingClientData.secretKey,
|
|
63
40
|
});
|
|
64
41
|
setRefreshingKey(false);
|
|
65
|
-
showNotification(get(response, "data.
|
|
42
|
+
showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
|
|
66
43
|
if (onSuccess) {
|
|
67
|
-
|
|
68
|
-
const keyObj = get(response, "data.data.key", get(response, "data.key", {}));
|
|
69
|
-
onSuccess({
|
|
70
|
-
accessKey: (_a = keyObj.accessKey) !== null && _a !== void 0 ? _a : accessKey,
|
|
71
|
-
secretKey: (_b = keyObj.secretKey) !== null && _b !== void 0 ? _b : secretKey,
|
|
72
|
-
subdomain: subdomain,
|
|
73
|
-
});
|
|
44
|
+
onSuccess(response === null || response === void 0 ? void 0 : response.data);
|
|
74
45
|
}
|
|
75
46
|
}
|
|
76
47
|
catch (error) {
|
|
77
|
-
showNotification(get(error, "
|
|
48
|
+
showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
|
|
78
49
|
setRefreshingKey(false);
|
|
79
50
|
}
|
|
80
51
|
});
|
|
@@ -19,7 +19,7 @@ import { getBaseUrl } from "../hocs/helpers";
|
|
|
19
19
|
import { CREATE_SUCCESS, SOMETHING_WENT_WRONG, } from "../utilities/constants/messages";
|
|
20
20
|
import { NotificationStatus } from "../utilities/constants/interface";
|
|
21
21
|
import { showNotification } from "../common/notifications";
|
|
22
|
-
import { get
|
|
22
|
+
import { get } from "lodash";
|
|
23
23
|
const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess, clientSubdomain, existingClientData, }) => {
|
|
24
24
|
const damConfig = useDamConfig();
|
|
25
25
|
const { appType } = damConfig;
|
|
@@ -34,51 +34,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
34
34
|
const api = useMemo(() => createApiClient(damConfig), [damConfig]);
|
|
35
35
|
const [form] = Form.useForm();
|
|
36
36
|
const isEditMode = !!existingClientData;
|
|
37
|
-
// Watch form values to enable/disable Submit button
|
|
38
|
-
const formValues = Form.useWatch([], form);
|
|
39
|
-
const isFormValid = useMemo(() => {
|
|
40
|
-
var _a;
|
|
41
|
-
if (!formValues)
|
|
42
|
-
return false;
|
|
43
|
-
// In edit mode, disabled fields (subdomain, damLocationDetails) may be excluded from form values - use clientData as fallback
|
|
44
|
-
const damLocationDetails = formValues.damLocationDetails || get(clientData, "damLocationDetails", {}) || {};
|
|
45
|
-
const name = formValues.name;
|
|
46
|
-
const accessTypes = formValues.accessTypes;
|
|
47
|
-
const adminTeams = formValues.adminTeams;
|
|
48
|
-
const subdomain = (_a = formValues.subdomain) !== null && _a !== void 0 ? _a : (isEditMode ? (get(clientData, "subdomain") || (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) : undefined);
|
|
49
|
-
const type = damLocationDetails.type;
|
|
50
|
-
const rootPath = damLocationDetails.rootPath;
|
|
51
|
-
if (!(name === null || name === void 0 ? void 0 : name.trim()))
|
|
52
|
-
return false;
|
|
53
|
-
if (!(accessTypes === null || accessTypes === void 0 ? void 0 : accessTypes.length))
|
|
54
|
-
return false;
|
|
55
|
-
if (!(adminTeams === null || adminTeams === void 0 ? void 0 : adminTeams.length))
|
|
56
|
-
return false;
|
|
57
|
-
if (!(subdomain === null || subdomain === void 0 ? void 0 : subdomain.trim()))
|
|
58
|
-
return false;
|
|
59
|
-
if (!type)
|
|
60
|
-
return false;
|
|
61
|
-
if (!(rootPath === null || rootPath === void 0 ? void 0 : rootPath.trim()))
|
|
62
|
-
return false;
|
|
63
|
-
if (damLocationType === "external") {
|
|
64
|
-
const bucket = damLocationDetails.bucket;
|
|
65
|
-
const accessKeyId = damLocationDetails.accessKeyId;
|
|
66
|
-
const secretAccessKey = damLocationDetails.secretAccessKey;
|
|
67
|
-
const url = damLocationDetails.url;
|
|
68
|
-
const region = damLocationDetails.region;
|
|
69
|
-
if (!(bucket === null || bucket === void 0 ? void 0 : bucket.trim()))
|
|
70
|
-
return false;
|
|
71
|
-
if (!(accessKeyId === null || accessKeyId === void 0 ? void 0 : accessKeyId.trim()))
|
|
72
|
-
return false;
|
|
73
|
-
if (!(secretAccessKey === null || secretAccessKey === void 0 ? void 0 : secretAccessKey.trim()))
|
|
74
|
-
return false;
|
|
75
|
-
if (!(url === null || url === void 0 ? void 0 : url.trim()))
|
|
76
|
-
return false;
|
|
77
|
-
if (!(region === null || region === void 0 ? void 0 : region.trim()))
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}, [formValues, damLocationType, isEditMode, clientData, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain]);
|
|
82
37
|
const onChangeDamLocationType = (e) => {
|
|
83
38
|
setDamLocationType(e);
|
|
84
39
|
form.setFieldValue("dam_location_details", { type: e });
|
|
@@ -197,7 +152,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
197
152
|
fetchClientData();
|
|
198
153
|
}, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api, form]);
|
|
199
154
|
const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
|
-
var _a, _b, _c, _d;
|
|
155
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
201
156
|
try {
|
|
202
157
|
// Use teamsApiDetails from clientData if available (from API response), otherwise use props
|
|
203
158
|
const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
|
|
@@ -208,85 +163,54 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
208
163
|
const adminTeamsAsStrings = Array.isArray(data.adminTeams)
|
|
209
164
|
? data.adminTeams.map((team) => String(team))
|
|
210
165
|
: [];
|
|
166
|
+
const values = Object.assign(Object.assign({}, data), { adminTeams: adminTeamsAsStrings, showFilePreview: (_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false, accessKey: appType == "reactJs"
|
|
167
|
+
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
|
|
168
|
+
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
|
|
169
|
+
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SECRET_KEY
|
|
170
|
+
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
|
|
171
|
+
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
|
|
172
|
+
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
|
|
173
|
+
teamsApi: finalTeamsApi,
|
|
174
|
+
username: finalUsername,
|
|
175
|
+
password: finalPassword,
|
|
176
|
+
}, damLocationDetails: damLocationType === "external"
|
|
177
|
+
? {
|
|
178
|
+
bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
|
|
179
|
+
locationType: "EXTERNAL",
|
|
180
|
+
rootPath: (_c = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _c === void 0 ? void 0 : _c.rootPath,
|
|
181
|
+
accessKeyId: (_d = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _d === void 0 ? void 0 : _d.accessKeyId,
|
|
182
|
+
secretAccessKey: (_e = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _e === void 0 ? void 0 : _e.secretAccessKey,
|
|
183
|
+
url: (_f = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _f === void 0 ? void 0 : _f.url,
|
|
184
|
+
region: (_g = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _g === void 0 ? void 0 : _g.region,
|
|
185
|
+
}
|
|
186
|
+
: {
|
|
187
|
+
locationType: "INTERNAL",
|
|
188
|
+
rootPath: (_h = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _h === void 0 ? void 0 : _h.rootPath,
|
|
189
|
+
} });
|
|
211
190
|
setLoading(true);
|
|
212
191
|
let response;
|
|
213
192
|
const baseUrl = getBaseUrl(appType);
|
|
214
193
|
if (isEditMode && brandIdForUpdate && authToken) {
|
|
215
|
-
//
|
|
216
|
-
const
|
|
217
|
-
const originalAdminTeamsStr = Array.isArray(originalAdminTeams)
|
|
218
|
-
? originalAdminTeams.map((t) => String(t)).sort()
|
|
219
|
-
: [];
|
|
220
|
-
const newAdminTeamsStr = [...adminTeamsAsStrings].sort();
|
|
221
|
-
const payload = {};
|
|
222
|
-
if (data.name !== undefined && data.name !== get(clientData, "name")) {
|
|
223
|
-
payload.name = data.name;
|
|
224
|
-
}
|
|
225
|
-
if (!isEqual(newAdminTeamsStr, originalAdminTeamsStr)) {
|
|
226
|
-
payload.adminTeams = adminTeamsAsStrings;
|
|
227
|
-
}
|
|
228
|
-
if (!isEqual(data.accessTypes || [], get(clientData, "accessTypes", []))) {
|
|
229
|
-
payload.accessTypes = data.accessTypes;
|
|
230
|
-
}
|
|
231
|
-
if (((_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false) !== get(clientData, "showFilePreview", false)) {
|
|
232
|
-
payload.showFilePreview = (_b = data.showFilePreview) !== null && _b !== void 0 ? _b : false;
|
|
233
|
-
}
|
|
234
|
-
if (Object.keys(payload).length === 0) {
|
|
235
|
-
setLoading(false);
|
|
236
|
-
showNotification("No changes to save", NotificationStatus.INFO);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, payload, {
|
|
194
|
+
// Update existing client: PUT to /brands/{brandId}
|
|
195
|
+
const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, values, {
|
|
240
196
|
headers: {
|
|
241
197
|
'Authorization': `Bearer ${authToken}`,
|
|
242
198
|
'Content-Type': 'application/json',
|
|
243
199
|
'accept': 'application/json, text/plain, */*'
|
|
244
200
|
}
|
|
245
201
|
});
|
|
202
|
+
// Extract data from axios response (API returns { data: {...} } or { data: { data: {...} } })
|
|
246
203
|
response = get(putResponse, "data.data", get(putResponse, "data", putResponse));
|
|
247
204
|
}
|
|
248
205
|
else {
|
|
249
|
-
// Create mode: send full payload
|
|
250
|
-
const damLocationDetailsFromForm = data === null || data === void 0 ? void 0 : data.damLocationDetails;
|
|
251
|
-
const subdomainValue = data.subdomain;
|
|
252
|
-
const values = Object.assign(Object.assign({}, data), { subdomain: subdomainValue, adminTeams: adminTeamsAsStrings, showFilePreview: (_c = data.showFilePreview) !== null && _c !== void 0 ? _c : false, accessKey: appType == "reactJs"
|
|
253
|
-
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
|
|
254
|
-
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
|
|
255
|
-
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SECRET_KEY
|
|
256
|
-
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
|
|
257
|
-
? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
|
|
258
|
-
: process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
|
|
259
|
-
teamsApi: finalTeamsApi,
|
|
260
|
-
username: finalUsername,
|
|
261
|
-
password: finalPassword,
|
|
262
|
-
}, damLocationDetails: damLocationType === "external"
|
|
263
|
-
? {
|
|
264
|
-
bucket: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.bucket,
|
|
265
|
-
locationType: "EXTERNAL",
|
|
266
|
-
rootPath: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.rootPath,
|
|
267
|
-
accessKeyId: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.accessKeyId,
|
|
268
|
-
secretAccessKey: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.secretAccessKey,
|
|
269
|
-
url: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.url,
|
|
270
|
-
region: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.region,
|
|
271
|
-
}
|
|
272
|
-
: {
|
|
273
|
-
locationType: "INTERNAL",
|
|
274
|
-
rootPath: damLocationDetailsFromForm === null || damLocationDetailsFromForm === void 0 ? void 0 : damLocationDetailsFromForm.rootPath,
|
|
275
|
-
} });
|
|
276
206
|
// Create new client: POST to /brands/sub-brand
|
|
277
207
|
response = yield api.post(CREATE_SUB_BRAND, values);
|
|
278
208
|
}
|
|
279
209
|
setLoading(false);
|
|
280
|
-
showNotification((
|
|
210
|
+
showNotification((_j = response === null || response === void 0 ? void 0 : response.message) !== null && _j !== void 0 ? _j : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
|
|
281
211
|
toggleShow();
|
|
282
212
|
if (onSuccess) {
|
|
283
|
-
|
|
284
|
-
// For PATCH (edit), response may be partial - merge with clientData and existingClientData
|
|
285
|
-
// so parent gets accessKey, secretKey, subdomain (credentials may not be in API response)
|
|
286
|
-
const apiBrand = get(response, "data", response);
|
|
287
|
-
const brandData = isEditMode
|
|
288
|
-
? Object.assign(Object.assign(Object.assign({}, (clientData || {})), (existingClientData || {})), apiBrand) : apiBrand;
|
|
289
|
-
onSuccess(brandData);
|
|
213
|
+
onSuccess(response === null || response === void 0 ? void 0 : response.data);
|
|
290
214
|
}
|
|
291
215
|
}
|
|
292
216
|
catch (error) {
|
|
@@ -383,41 +307,41 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
383
307
|
},
|
|
384
308
|
], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
|
|
385
309
|
onChangeDamLocationType(e);
|
|
386
|
-
}, placeholder: "Type"
|
|
310
|
+
}, placeholder: "Type" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
|
|
387
311
|
{
|
|
388
312
|
required: true,
|
|
389
313
|
message: "Root path is required",
|
|
390
314
|
},
|
|
391
|
-
], children: _jsx(Input, { placeholder: "Root path"
|
|
315
|
+
], children: _jsx(Input, { placeholder: "Root path" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
|
|
392
316
|
{
|
|
393
317
|
required: damLocationType === "external",
|
|
394
318
|
message: "Bucket is required",
|
|
395
319
|
},
|
|
396
|
-
], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal"
|
|
320
|
+
], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
|
|
397
321
|
{
|
|
398
322
|
required: damLocationType === "external",
|
|
399
323
|
message: "Access key is required",
|
|
400
324
|
},
|
|
401
|
-
], children: _jsx(Input, { placeholder: "Access Key", disabled: damLocationType === "internal"
|
|
325
|
+
], children: _jsx(Input, { placeholder: "Access Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Secret Access Key", name: ["damLocationDetails", "secretAccessKey"], rules: [
|
|
402
326
|
{
|
|
403
327
|
required: damLocationType === "external",
|
|
404
328
|
message: "Secret Access Key is required",
|
|
405
329
|
},
|
|
406
|
-
], children: _jsx(Input, { placeholder: "Secret Key", disabled: damLocationType === "internal"
|
|
330
|
+
], children: _jsx(Input, { placeholder: "Secret Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Url", name: ["damLocationDetails", "url"], rules: [
|
|
407
331
|
{
|
|
408
332
|
required: damLocationType === "external",
|
|
409
333
|
message: "Url is required",
|
|
410
334
|
},
|
|
411
|
-
], children: _jsx(Input, { placeholder: "Url", disabled: damLocationType === "internal"
|
|
335
|
+
], children: _jsx(Input, { placeholder: "Url", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Region", name: ["damLocationDetails", "region"], rules: [
|
|
412
336
|
{
|
|
413
337
|
required: damLocationType === "external",
|
|
414
338
|
message: "Region is required",
|
|
415
339
|
},
|
|
416
|
-
], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal"
|
|
340
|
+
], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" }) })] }))] }), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
|
|
417
341
|
{
|
|
418
342
|
required: true,
|
|
419
343
|
message: "Subdomain is required",
|
|
420
344
|
},
|
|
421
|
-
], children: _jsx(Input, { placeholder: "Subdomain"
|
|
345
|
+
], 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" }) })] })) }));
|
|
422
346
|
};
|
|
423
347
|
export default CreateClientForm;
|
|
@@ -9,49 +9,32 @@ 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 { useState } from "react";
|
|
13
|
-
import axios from "axios";
|
|
12
|
+
import { useMemo, useState } from "react";
|
|
14
13
|
import { showNotification } from "../common/notifications";
|
|
15
14
|
import { NotificationStatus } from "../utilities/constants/interface";
|
|
16
15
|
import { SOMETHING_WENT_WRONG } from "../utilities/constants/messages";
|
|
17
16
|
import { get } from "lodash";
|
|
18
|
-
import { REFRESH_KEY_URL
|
|
17
|
+
import { REFRESH_KEY_URL } from "../utilities/constants/apiUrls";
|
|
19
18
|
import { useDamConfig } from "../hocs/DamConfigContext";
|
|
20
|
-
import {
|
|
19
|
+
import { createApiClient } from "../hocs/configureAxios";
|
|
21
20
|
export default function RefreshKeyBtn() {
|
|
22
21
|
const [loading, setLoading] = useState(false);
|
|
23
22
|
const damConfig = useDamConfig();
|
|
24
|
-
const { damAccessKey, secretKey
|
|
23
|
+
const { damAccessKey, secretKey } = damConfig;
|
|
24
|
+
const api = useMemo(() => createApiClient(damConfig), [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
|
-
}
|
|
30
26
|
setLoading(true);
|
|
31
27
|
try {
|
|
32
|
-
|
|
33
|
-
const loginResponse = yield axios.post(getBaseUrl(appType) + USER_LOGIN, {
|
|
28
|
+
const response = yield api.put(REFRESH_KEY_URL, {
|
|
34
29
|
accessKey: damAccessKey,
|
|
35
30
|
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
|
-
},
|
|
49
31
|
});
|
|
32
|
+
// console.log(response);
|
|
50
33
|
setLoading(false);
|
|
51
34
|
showNotification(get(response, "data.message", "Key refreshed successfully"), NotificationStatus.SUCCESS);
|
|
52
35
|
}
|
|
53
36
|
catch (error) {
|
|
54
|
-
showNotification(get(error, "
|
|
37
|
+
showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
|
|
55
38
|
setLoading(false);
|
|
56
39
|
}
|
|
57
40
|
});
|