UNPKG

@localazy/strapi-plugin

Version:

The official Strapi Plugin by Localazy.

51 lines (50 loc) 2.04 kB
import { c as createStrapiApiAxiosInstance } from "./index-C15Goe6p.mjs"; import { jsxs, jsx } from "react/jsx-runtime"; import { useState, useEffect } from "react"; import { c as cloneDeep } from "./set-BRyy4Ra6.mjs"; import { d as Field, M as MultiSelect, e as MultiSelectOption } from "./index-DOCSzcPH.mjs"; import { u as useTranslation } from "./useTranslation-CZQ4lU1m.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 };