UNPKG

@localazy/strapi-plugin

Version:

The official Strapi Plugin by Localazy.

235 lines (234 loc) 11.3 kB
import { jsxs, Fragment, jsx } from "react/jsx-runtime"; import { useState, useEffect } from "react"; import { P as PluginSettingsService$1, c as cloneDeep, s as set } from "./set-BRyy4Ra6.mjs"; import { Layouts } from "@strapi/strapi/admin"; import { F as Flex, B as Button, b as ForwardRef$4z, c as Box, A as Alert, T as Typography, d as Field, a as Toggle, M as MultiSelect, e as MultiSelectOption, D as Divider, S as SingleSelect, f as SingleSelectOption } from "./index-DOCSzcPH.mjs"; import { i as isEqual } from "./isEqual-BazjlHGf.mjs"; import { L as LanguagesSelector, P as ProjectService } from "./LanguagesSelector-u9iDsQqB.mjs"; import { c as createStrapiApiAxiosInstance } from "./index-C15Goe6p.mjs"; import "./i18n-RoETLXdU.mjs"; import { u as useTranslation } from "./useTranslation-CZQ4lU1m.mjs"; class PluginSettingsService { static async getAdminPanelUsers() { try { const axiosInstance = 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(); const [projectLanguages, setProjectLanguages] = useState([]); const [isLoading, setIsLoading] = useState(true); const [showSavedAlert, setShowSavedAlert] = useState(false); const [users, setUsers] = useState([]); const [originalFormModel, setOriginalFormModel] = useState([]); const [formModel, setFormModel] = useState({}); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); const onCancelClick = () => { setFormModel(cloneDeep(originalFormModel)); setHasUnsavedChanges(false); }; const saveGlobalSettings = async (data) => { try { await PluginSettingsService$1.updatePluginSettings(data); setOriginalFormModel(cloneDeep(data)); setHasUnsavedChanges(false); setShowSavedAlert(true); } catch (e) { throw e.data; } }; const patchFormModel = (key, value) => { const newFormModel = cloneDeep(formModel); set(newFormModel, key, value); setFormModel(newFormModel); setHasUnsavedChanges(!isEqual(originalFormModel, newFormModel)); }; const getUserLabel = (user) => { return `${user.firstname} ${user.lastname || ""}${user.lastname ? " " : ""}(${user.email})`; }; useEffect(() => { async function fetchData() { setIsLoading(true); const project = await ProjectService.getConnectedProject(); const projectLanguagesWithoutDefaultLanguage = project?.languages?.filter((language) => language.id !== project.sourceLanguage) || []; setProjectLanguages(projectLanguagesWithoutDefaultLanguage); const globalSettings = await PluginSettingsService$1.getPluginSettings(); setFormModel(globalSettings); setOriginalFormModel(cloneDeep(globalSettings)); const users2 = await PluginSettingsService.getAdminPanelUsers(); setUsers(users2); setIsLoading(false); } fetchData(); }, []); return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx( Layouts.Header, { title: t("plugin_settings.global_settings"), subtitle: t("plugin_settings.global_settings_description"), primaryAction: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [ /* @__PURE__ */ jsx(Button, { variant: "secondary", disabled: !hasUnsavedChanges, onClick: onCancelClick, children: t("plugin_settings.cancel") }), /* @__PURE__ */ jsx( Button, { startIcon: /* @__PURE__ */ jsx(ForwardRef$4z, {}), disabled: !hasUnsavedChanges, onClick: () => { saveGlobalSettings(formModel); }, children: t("plugin_settings.save") } ) ] }), as: "h2" } ), /* @__PURE__ */ jsxs(Box, { marginRight: 10, marginLeft: 10, children: [ !isLoading && showSavedAlert && /* @__PURE__ */ jsx(Box, { marginBottom: 8, children: /* @__PURE__ */ jsx( 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__ */ jsx(Box, { background: "neutral0", padding: 7, paddingTop: 6, shadow: "tableShadow", hasRadius: true, children: /* @__PURE__ */ jsxs( Box, { style: { maxWidth: "500px" }, children: [ /* @__PURE__ */ jsx(Typography, { variant: "delta", textColor: "neutral800", children: t("plugin_settings.upload_settings") }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs(Field.Root, { hint: t("plugin_settings.allow_automated_upload_to_localazy_info"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: t("plugin_settings.allow_automated_upload_to_localazy") }), /* @__PURE__ */ jsx( 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__ */ jsx(Field.Hint, {}) ] }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs(Field.Root, { hint: t("plugin_settings.automated_upload_triggers_info"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: t("plugin_settings.automated_upload_triggers") }), /* @__PURE__ */ jsxs( 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__ */ jsx(MultiSelectOption, { value: "created", children: t("plugin_settings.creating_new_data_entry") }), /* @__PURE__ */ jsx(MultiSelectOption, { value: "updated", children: t("plugin_settings.editing_data_entry") }) ] } ), /* @__PURE__ */ jsx(Field.Hint, {}) ] }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs(Field.Root, { hint: t("plugin_settings.deprecate_source_keys_on_delete_info"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: t("plugin_settings.deprecate_source_keys_on_delete") }), /* @__PURE__ */ jsx( 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__ */ jsx(Field.Hint, {}) ] }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx(Typography, { variant: "delta", textColor: "neutral800", children: t("plugin_settings.download_settings") }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs(Field.Root, { hint: t("plugin_settings.processing_of_download_webhook_info"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: t("plugin_settings.processing_of_download_webhook") }), /* @__PURE__ */ jsx( 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__ */ jsx(Field.Hint, {}) ] }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs(Field.Root, { hint: t("plugin_settings.webhook_author_info"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: t("plugin_settings.webhook_author") }), /* @__PURE__ */ jsx( 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__ */ jsx(SingleSelectOption, { value: user.id, children: getUserLabel(user) }, user.id)) } ), /* @__PURE__ */ jsx(Field.Hint, {}) ] }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx( 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") } ) ] } ) }) ] }) ] }); }; export { GlobalSettings };