@localazy/strapi-plugin
Version:
The official Strapi Plugin by Localazy.
235 lines (234 loc) • 12.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const set = require("./set-CmcBsVOP.js");
const admin = require("@strapi/strapi/admin");
const index$1 = require("./index-CaY3BYnQ.js");
const isEqual = require("./isEqual-CrlZhAtq.js");
const LanguagesSelector = require("./LanguagesSelector-Bfrsr3-P.js");
const index = require("./index-Q3-srfXc.js");
require("./i18n-0dV2P-Hm.js");
const useTranslation = require("./useTranslation-BdIl-aLe.js");
class PluginSettingsService {
static async getAdminPanelUsers() {
try {
const axiosInstance = index.createStrapiApiAxiosInstance("/admin/users");
const result = await axiosInstance.get("", {
params: {
pageSize: 100,
page: 1,
sort: "firstname"
}
});
return result.data.data.results;
} catch (e) {
throw e;
}
}
}
const GlobalSettings = () => {
const { t } = useTranslation.useTranslation();
const [projectLanguages, setProjectLanguages] = React.useState([]);
const [isLoading, setIsLoading] = React.useState(true);
const [showSavedAlert, setShowSavedAlert] = React.useState(false);
const [users, setUsers] = React.useState([]);
const [originalFormModel, setOriginalFormModel] = React.useState([]);
const [formModel, setFormModel] = React.useState({});
const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false);
const onCancelClick = () => {
setFormModel(set.cloneDeep(originalFormModel));
setHasUnsavedChanges(false);
};
const saveGlobalSettings = async (data) => {
try {
await set.PluginSettingsService.updatePluginSettings(data);
setOriginalFormModel(set.cloneDeep(data));
setHasUnsavedChanges(false);
setShowSavedAlert(true);
} catch (e) {
throw e.data;
}
};
const patchFormModel = (key, value) => {
const newFormModel = set.cloneDeep(formModel);
set.set(newFormModel, key, value);
setFormModel(newFormModel);
setHasUnsavedChanges(!isEqual.isEqual(originalFormModel, newFormModel));
};
const getUserLabel = (user) => {
return `${user.firstname} ${user.lastname || ""}${user.lastname ? " " : ""}(${user.email})`;
};
React.useEffect(() => {
async function fetchData() {
setIsLoading(true);
const project = await LanguagesSelector.ProjectService.getConnectedProject();
const projectLanguagesWithoutDefaultLanguage = project?.languages?.filter((language) => language.id !== project.sourceLanguage) || [];
setProjectLanguages(projectLanguagesWithoutDefaultLanguage);
const globalSettings = await set.PluginSettingsService.getPluginSettings();
setFormModel(globalSettings);
setOriginalFormModel(set.cloneDeep(globalSettings));
const users2 = await PluginSettingsService.getAdminPanelUsers();
setUsers(users2);
setIsLoading(false);
}
fetchData();
}, []);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
/* @__PURE__ */ jsxRuntime.jsx(
admin.Layouts.Header,
{
title: t("plugin_settings.global_settings"),
subtitle: t("plugin_settings.global_settings_description"),
primaryAction: /* @__PURE__ */ jsxRuntime.jsxs(index$1.Flex, { gap: 2, children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Button, { variant: "secondary", disabled: !hasUnsavedChanges, onClick: onCancelClick, children: t("plugin_settings.cancel") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.Button,
{
startIcon: /* @__PURE__ */ jsxRuntime.jsx(index$1.ForwardRef$4z, {}),
disabled: !hasUnsavedChanges,
onClick: () => {
saveGlobalSettings(formModel);
},
children: t("plugin_settings.save")
}
)
] }),
as: "h2"
}
),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Box, { marginRight: 10, marginLeft: 10, children: [
!isLoading && showSavedAlert && /* @__PURE__ */ jsxRuntime.jsx(index$1.Box, { marginBottom: 8, children: /* @__PURE__ */ jsxRuntime.jsx(
index$1.Alert,
{
onClose: () => setShowSavedAlert(false),
closeLabel: t("plugin_settings.close"),
title: t("plugin_settings.content_transfer_setup_saved"),
variant: "success",
children: t("plugin_settings.global_settings_saved_successfully")
}
) }),
!isLoading && /* @__PURE__ */ jsxRuntime.jsx(index$1.Box, { background: "neutral0", padding: 7, paddingTop: 6, shadow: "tableShadow", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
index$1.Box,
{
style: {
maxWidth: "500px"
},
children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Typography, { variant: "delta", textColor: "neutral800", children: t("plugin_settings.upload_settings") }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: t("plugin_settings.allow_automated_upload_to_localazy_info"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: t("plugin_settings.allow_automated_upload_to_localazy") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.Toggle,
{
offLabel: t("plugin_settings.off"),
onLabel: t("plugin_settings.on"),
checked: typeof formModel?.upload?.allowAutomated === "boolean" ? formModel.upload.allowAutomated : false,
onChange: (e) => patchFormModel("upload.allowAutomated", e.target.checked)
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: t("plugin_settings.automated_upload_triggers_info"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: t("plugin_settings.automated_upload_triggers") }),
/* @__PURE__ */ jsxRuntime.jsxs(
index$1.MultiSelect,
{
label: t("plugin_settings.automated_upload_triggers"),
hint: t("plugin_settings.automated_upload_triggers_info"),
clearLabel: t("plugin_settings.clear"),
placeholder: t("plugin_settings.automated_upload_triggers_placeholder"),
onClear: () => patchFormModel("upload.automatedTriggers", []),
value: formModel?.upload?.automatedTriggers || [],
onChange: (values) => patchFormModel("upload.automatedTriggers", values),
disabled: typeof formModel?.upload?.allowAutomated === "boolean" ? !formModel.upload.allowAutomated : true,
multi: true,
withTags: true,
children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.MultiSelectOption, { value: "created", children: t("plugin_settings.creating_new_data_entry") }),
/* @__PURE__ */ jsxRuntime.jsx(index$1.MultiSelectOption, { value: "updated", children: t("plugin_settings.editing_data_entry") })
]
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: t("plugin_settings.deprecate_source_keys_on_delete_info"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: t("plugin_settings.deprecate_source_keys_on_delete") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.Toggle,
{
hint: t("plugin_settings.deprecate_source_keys_on_delete_info"),
offLabel: t("plugin_settings.off"),
onLabel: t("plugin_settings.on"),
checked: typeof formModel?.upload?.allowDeprecate === "boolean" ? formModel.upload.allowDeprecate : false,
onChange: (e) => patchFormModel("upload.allowDeprecate", e.target.checked)
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Divider, {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Typography, { variant: "delta", textColor: "neutral800", children: t("plugin_settings.download_settings") }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: t("plugin_settings.processing_of_download_webhook_info"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: t("plugin_settings.processing_of_download_webhook") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.Toggle,
{
hint: t("plugin_settings.processing_of_download_webhook_info"),
offLabel: t("plugin_settings.off"),
onLabel: t("plugin_settings.on"),
checked: typeof formModel?.download?.processDownloadWebhook === "boolean" ? formModel.download.processDownloadWebhook : true,
onChange: (e) => patchFormModel("download.processDownloadWebhook", e.target.checked)
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: t("plugin_settings.webhook_author_info"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: t("plugin_settings.webhook_author") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.SingleSelect,
{
hint: t("plugin_settings.webhook_author_info"),
clearLabel: t("plugin_settings.clear"),
placeholder: t("plugin_settings.webhook_author_placeholder"),
onClear: () => patchFormModel("download.webhookAuthorId", null),
value: formModel?.download?.webhookAuthorId || null,
onChange: (value) => patchFormModel("download.webhookAuthorId", value),
children: users.map((user) => /* @__PURE__ */ jsxRuntime.jsx(index$1.SingleSelectOption, { value: user.id, children: getUserLabel(user) }, user.id))
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] }),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx(
LanguagesSelector.LanguagesSelector,
{
preselectedLanguages: formModel?.download?.webhookLanguages || [],
projectLanguages,
onChange: (languages) => patchFormModel("download.webhookLanguages", languages),
label: t("plugin_settings.webhook_languages"),
hint: t("plugin_settings.webhook_languages_info"),
placeholder: t("plugin_settings.webhook_languages_placeholder")
}
)
]
}
) })
] })
] });
};
exports.GlobalSettings = GlobalSettings;