@bindu-dashing/dam-solution-v2 5.8.151 → 5.8.153
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.
|
@@ -12,7 +12,7 @@ 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 } 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 { CREATE_SUCCESS, SOMETHING_WENT_WRONG, } from "../utilities/constants/messages";
|
|
@@ -21,8 +21,9 @@ import { showNotification } from "../common/notifications";
|
|
|
21
21
|
import { get } from "lodash";
|
|
22
22
|
const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess, clientSubdomain, existingClientData, }) => {
|
|
23
23
|
const damConfig = useDamConfig();
|
|
24
|
-
const { appType } = damConfig;
|
|
24
|
+
const { appType, brand } = damConfig;
|
|
25
25
|
const [loading, setLoading] = useState(false);
|
|
26
|
+
const [fetchingClientData, setFetchingClientData] = useState(false);
|
|
26
27
|
const [damLocationType, setDamLocationType] = useState("external");
|
|
27
28
|
const [filteredTeams, setFilteredTeams] = useState([]);
|
|
28
29
|
const api = useMemo(() => createApiClient(damConfig), [damConfig]);
|
|
@@ -32,14 +33,59 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
32
33
|
setDamLocationType(e);
|
|
33
34
|
form.setFieldValue("dam_location_details", { type: e });
|
|
34
35
|
};
|
|
36
|
+
// Fetch client data when editing
|
|
35
37
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const fetchClientData = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
if (isEditMode && (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain)) {
|
|
40
|
+
setFetchingClientData(true);
|
|
41
|
+
try {
|
|
42
|
+
const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
|
|
43
|
+
const clientData = get(response, "data.data", {});
|
|
44
|
+
// Populate form with existing client data
|
|
45
|
+
if (clientData) {
|
|
46
|
+
form.setFieldsValue({
|
|
47
|
+
name: get(clientData, "name", ""),
|
|
48
|
+
subdomain: get(clientData, "subdomain", existingClientData.subdomain),
|
|
49
|
+
accessTypes: get(clientData, "accessTypes", []),
|
|
50
|
+
adminTeams: get(clientData, "adminTeams", []),
|
|
51
|
+
showFilePreview: get(clientData, "showFilePreview", false),
|
|
52
|
+
damLocationDetails: {
|
|
53
|
+
type: get(clientData, "damLocationDetails.locationType") === "EXTERNAL" ? "external" : "internal",
|
|
54
|
+
bucket: get(clientData, "damLocationDetails.bucket", ""),
|
|
55
|
+
rootPath: get(clientData, "damLocationDetails.rootPath", ""),
|
|
56
|
+
accessKeyId: get(clientData, "damLocationDetails.accessKeyId", ""),
|
|
57
|
+
secretAccessKey: get(clientData, "damLocationDetails.secretAccessKey", ""),
|
|
58
|
+
url: get(clientData, "damLocationDetails.url", ""),
|
|
59
|
+
region: get(clientData, "damLocationDetails.region", ""),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
// Set DAM location type
|
|
63
|
+
const locationType = get(clientData, "damLocationDetails.locationType");
|
|
64
|
+
if (locationType === "EXTERNAL") {
|
|
65
|
+
setDamLocationType("external");
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
setDamLocationType("internal");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error("Error fetching client data:", error);
|
|
74
|
+
// If fetch fails, still set subdomain
|
|
75
|
+
if (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) {
|
|
76
|
+
form.setFieldValue("subdomain", existingClientData.subdomain);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
setFetchingClientData(false);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (clientSubdomain) {
|
|
84
|
+
form.setFieldValue("subdomain", clientSubdomain);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
fetchClientData();
|
|
88
|
+
}, [isEditMode, existingClientData, api, form]);
|
|
43
89
|
const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
90
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
45
91
|
try {
|
|
@@ -107,7 +153,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
107
153
|
console.log("Error while fetching external teams", err);
|
|
108
154
|
}
|
|
109
155
|
});
|
|
110
|
-
return (_jsx(Drawer, { open: true, title: isEditMode ? "Edit Client" : "Create Client", onClose: toggleShow, width: 500, maskClosable: false, children: _jsxs(Form, { layout: "vertical", form: form, onFinish: onFinish, children: [_jsx(Form.Item, { label: "Name", name: "name", rules: [
|
|
156
|
+
return (_jsx(Drawer, { open: true, title: isEditMode ? "Edit Client" : "Create Client", onClose: toggleShow, width: 500, maskClosable: false, children: fetchingClientData ? (_jsx("div", { style: { textAlign: "center", padding: "20px" }, children: _jsx(Typography.Text, { children: "Loading client data..." }) })) : (_jsxs(Form, { layout: "vertical", form: form, onFinish: onFinish, children: [_jsx(Form.Item, { label: "Name", name: "name", rules: [
|
|
111
157
|
{
|
|
112
158
|
required: true,
|
|
113
159
|
message: "Name is required",
|
|
@@ -164,6 +210,6 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
|
|
|
164
210
|
required: true,
|
|
165
211
|
message: "Subdomain is required",
|
|
166
212
|
},
|
|
167
|
-
], children: _jsx(Input, { placeholder: "Subdomain" }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview" }) }), _jsx(Form.Item, { children: _jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, children: "Submit" }) })] }) }));
|
|
213
|
+
], children: _jsx(Input, { placeholder: "Subdomain" }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview" }) }), _jsx(Form.Item, { children: _jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, children: "Submit" }) })] })) }));
|
|
168
214
|
};
|
|
169
215
|
export default CreateClientForm;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Layout, Button } from "antd";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
|
|
5
5
|
import PreviewDetails from "./Previewdetails";
|
|
6
6
|
import MapFile from "../files/MapFile";
|
|
7
|
+
import { useDamConfig } from "../../hocs/DamConfigContext";
|
|
8
|
+
import { get } from "lodash";
|
|
7
9
|
const { Content } = Layout;
|
|
8
10
|
const FileViewer = ({ file, onNext, onPrev, hasNext, hasPrev, handleClose, }) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
+
const damConfig = useDamConfig();
|
|
12
|
+
const brand = damConfig === null || damConfig === void 0 ? void 0 : damConfig.brand;
|
|
13
|
+
const showFilePreview = get(brand, "showFilePreview", false);
|
|
14
|
+
const [metadataOpen, setMetadataOpen] = useState(showFilePreview);
|
|
15
|
+
return (_jsx(Layout, { className: "md-lib-h-full", children: _jsxs(Content, { className: "md-lib-flex md-lib-h-full md-lib-w-full", children: [_jsx("div", { className: `md-lib-flex md-lib-items-center md-lib-justify-center md-lib-relative md-lib-bg-textColorActive dark:md-lib-bg-darkSecondaryColor md-lib-min-h-full ${metadataOpen ? "md-lib-flex-1" : "md-lib-flex-1 md-lib-w-full"}`, children: _jsx(PreviewDetails, { file: file, hasNext: hasNext, hasPrev: hasPrev, onNext: onNext, onPrev: onPrev }) }), showFilePreview && (_jsxs(_Fragment, { children: [_jsx(Button, { type: "text", className: "md-lib-shrink-0 md-lib-flex md-lib-items-center md-lib-justify-center md-lib-w-10 md-lib-h-10 md-lib-rounded-none md-lib-bg-black/50 hover:md-lib-bg-black/70 dark:md-lib-bg-white/20 dark:hover:md-lib-bg-white/30 md-lib-text-white md-lib-border-0 md-lib-self-start md-lib-mt-4", onClick: () => setMetadataOpen((prev) => !prev), "aria-label": metadataOpen ? "Hide showFilePreviewEditor" : "Show showFilePreviewEditor", children: metadataOpen ? (_jsx(RightOutlined, { className: "md-lib-text-lg" })) : (_jsx(LeftOutlined, { className: "md-lib-text-lg" })) }), metadataOpen && (_jsx("div", { className: "md-lib-w-[400px] md-lib-min-w-[320px] md-lib-shrink-0 md-lib-border-l md-lib-border-borderColor dark:md-lib-border-darkBorderColor md-lib-bg-backgroundColor dark:md-lib-bg-darkPrimary md-lib-overflow-y-auto", children: _jsx(MapFile, { fromUpload: false, filesList: file ? [file] : [], handleCancel: handleClose ? () => handleClose() : undefined }) }))] }))] }) }));
|
|
11
16
|
};
|
|
12
17
|
export default FileViewer;
|
|
@@ -231,6 +231,6 @@ function MapFile({ open, handleCancel, filesList, fromUpload, parentFolderId, })
|
|
|
231
231
|
const getMetadataForm = (_jsxs(Form, { layout: "vertical", form: form, scrollToFirstError: true, onFinish: fromUpload ? handleSubmit : handleUpdate, className: "md-lib-m-2", children: [_jsx(AssetSelectionFormItem, { handleAssetTemplateChange: handleAssetTemplateChange, assetOptions: assetOptions, assetsLoading: assetsLoading }), selectedAssetTemplate && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { name: "teamIds", label: "Teams", children: _jsx(Select, { options: teamOptions, placeholder: "Select teams", mode: "multiple", onChange: (val) => onChangeTeams(val), style: { width: "100%" }, showSearch: true, optionFilterProp: "key" }) }), _jsx(Form.Item, { name: "expiryDate", label: "Expiry Date", children: _jsx(DatePicker, { placeholder: "Expiry Date", style: { width: "100%" } }) }), _jsx(Metadata, { asset: selectedAssetTemplate, form: form, file: (filesList === null || filesList === void 0 ? void 0 : filesList[0]) || null })] })), _jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-justify-end md-lib-gap-3", children: [_jsx(Button, { onClick: handleCancelWithConfirmation, children: "Cancel" }), _jsx(Button, { disabled: !selectedAssetTemplate, type: "primary",
|
|
232
232
|
// onClick={handleSubmit}
|
|
233
233
|
loading: loading || updateFileMutation.isLoading, htmlType: "submit", children: "Save" })] })] }));
|
|
234
|
-
return (_jsx(_Fragment, { children: fromUpload ? (_jsx(Drawer, { title: "
|
|
234
|
+
return (_jsx(_Fragment, { children: fromUpload ? (_jsx(Drawer, { title: "showFilePreviewEditor", open: open, onClose: handleCancelWithConfirmation, maskClosable: false, children: getMetadataForm })) : (_jsxs("div", { className: "md-lib-p-2 md-lib-overflow-y-scroll md-lib-max-h-[calc(100vh-65px)]", children: [_jsx("p", { className: "md-lib-text-lg md-lib-font-semibold", children: "showFilePreviewEditor" }), getMetadataForm] })) }));
|
|
235
235
|
}
|
|
236
236
|
export default MapFile;
|