UNPKG

@localazy/strapi-plugin

Version:

The official Strapi Plugin by Localazy.

49 lines (48 loc) 1.95 kB
import { c as createStrapiApiAxiosInstance } from "./index-Dj68Ixl2.mjs"; import { jsxs, jsx } from "react/jsx-runtime"; import { useState, useEffect } from "react"; import { u as useTranslation, q as Field, M as MultiSelect, t as MultiSelectOption, n as cloneDeep } from "./set-Dnhh_SyE.mjs"; const strapiApiInstance = createStrapiApiAxiosInstance(); class ProjectService { static async getConnectedProject() { try { const result = await strapiApiInstance.get(`/project`); return result.data; } catch (e) { throw e; } } } const LanguagesSelector = (props) => { const { t } = useTranslation(); const [selectedLanguages, setSelectedLanguages] = useState([]); const onChange = (values) => { setSelectedLanguages(values); props.onChange(cloneDeep(values)); }; useEffect(() => { const existingPreselectedLanguages = props.projectLanguages.filter((lang) => props.preselectedLanguages.includes(lang.code)).map((lang) => lang.code); setSelectedLanguages(existingPreselectedLanguages); }, [props.projectLanguages, props.preselectedLanguages]); return /* @__PURE__ */ jsxs(Field.Root, { hint: props.hint || t("common.select_languages"), children: [ /* @__PURE__ */ jsx(Field.Label, { children: props.label || t("common.select_languages") }), /* @__PURE__ */ jsx( MultiSelect, { clearLabel: t("plugin_settings.clear"), placeholder: props.placeholder || t("common.select_languages"), onClear: () => setSelectedLanguages([]), value: selectedLanguages || [], onChange: (values) => onChange(values), multi: true, withTags: true, children: props.projectLanguages.map((lang) => /* @__PURE__ */ jsx(MultiSelectOption, { value: lang.code, children: `${lang.name} (${lang.code})` }, lang.id)) } ), /* @__PURE__ */ jsx(Field.Hint, {}) ] }); }; export { LanguagesSelector as L, ProjectService as P };