@localazy/strapi-plugin
Version:
The official Strapi Plugin by Localazy.
50 lines (49 loc) • 2.11 kB
JavaScript
;
const index = require("./index-Q3-srfXc.js");
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const set = require("./set-CmcBsVOP.js");
const index$1 = require("./index-CaY3BYnQ.js");
const useTranslation = require("./useTranslation-BdIl-aLe.js");
const strapiApiInstance = index.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.useTranslation();
const [selectedLanguages, setSelectedLanguages] = React.useState([]);
const onChange = (values) => {
setSelectedLanguages(values);
props.onChange(set.cloneDeep(values));
};
React.useEffect(() => {
const existingPreselectedLanguages = props.projectLanguages.filter((lang) => props.preselectedLanguages.includes(lang.code)).map((lang) => lang.code);
setSelectedLanguages(existingPreselectedLanguages);
}, [props.projectLanguages, props.preselectedLanguages]);
return /* @__PURE__ */ jsxRuntime.jsxs(index$1.Field.Root, { hint: props.hint || t("common.select_languages"), children: [
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Label, { children: props.label || t("common.select_languages") }),
/* @__PURE__ */ jsxRuntime.jsx(
index$1.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__ */ jsxRuntime.jsx(index$1.MultiSelectOption, { value: lang.code, children: `${lang.name} (${lang.code})` }, lang.id))
}
),
/* @__PURE__ */ jsxRuntime.jsx(index$1.Field.Hint, {})
] });
};
exports.LanguagesSelector = LanguagesSelector;
exports.ProjectService = ProjectService;