@strapi/i18n 0.0.0-experimental.a65a85fdea97faae8679d3ffc5f9d79af61abd26 → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +1 -17
  2. package/package.json +4 -83
  3. package/dist/_chunks/SettingsPage-B73NO_8-.js +0 -585
  4. package/dist/_chunks/SettingsPage-B73NO_8-.js.map +0 -1
  5. package/dist/_chunks/SettingsPage-pvdzbKEM.mjs +0 -565
  6. package/dist/_chunks/SettingsPage-pvdzbKEM.mjs.map +0 -1
  7. package/dist/_chunks/de-9eCAqqrB.mjs +0 -66
  8. package/dist/_chunks/de-9eCAqqrB.mjs.map +0 -1
  9. package/dist/_chunks/de-DtWiGdHl.js +0 -66
  10. package/dist/_chunks/de-DtWiGdHl.js.map +0 -1
  11. package/dist/_chunks/dk-2qBjxt-P.mjs +0 -66
  12. package/dist/_chunks/dk-2qBjxt-P.mjs.map +0 -1
  13. package/dist/_chunks/dk-D8C-casx.js +0 -66
  14. package/dist/_chunks/dk-D8C-casx.js.map +0 -1
  15. package/dist/_chunks/en-BuBc6LKZ.js +0 -69
  16. package/dist/_chunks/en-BuBc6LKZ.js.map +0 -1
  17. package/dist/_chunks/en-CnrTsjWS.mjs +0 -69
  18. package/dist/_chunks/en-CnrTsjWS.mjs.map +0 -1
  19. package/dist/_chunks/es-DS-XFGSw.js +0 -66
  20. package/dist/_chunks/es-DS-XFGSw.js.map +0 -1
  21. package/dist/_chunks/es-DlmMVaBG.mjs +0 -66
  22. package/dist/_chunks/es-DlmMVaBG.mjs.map +0 -1
  23. package/dist/_chunks/fr-3S6ke71d.mjs +0 -66
  24. package/dist/_chunks/fr-3S6ke71d.mjs.map +0 -1
  25. package/dist/_chunks/fr-BTjekDpq.js +0 -66
  26. package/dist/_chunks/fr-BTjekDpq.js.map +0 -1
  27. package/dist/_chunks/index-kcYwoCdE.js +0 -1082
  28. package/dist/_chunks/index-kcYwoCdE.js.map +0 -1
  29. package/dist/_chunks/index-lckTPHiZ.mjs +0 -1058
  30. package/dist/_chunks/index-lckTPHiZ.mjs.map +0 -1
  31. package/dist/_chunks/ko-DmcGUBQ3.js +0 -65
  32. package/dist/_chunks/ko-DmcGUBQ3.js.map +0 -1
  33. package/dist/_chunks/ko-qTjQ8IMw.mjs +0 -65
  34. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +0 -1
  35. package/dist/_chunks/pl-B67TSHqT.mjs +0 -66
  36. package/dist/_chunks/pl-B67TSHqT.mjs.map +0 -1
  37. package/dist/_chunks/pl-Cn5RYonZ.js +0 -66
  38. package/dist/_chunks/pl-Cn5RYonZ.js.map +0 -1
  39. package/dist/_chunks/ru-BMBgVL3s.js +0 -68
  40. package/dist/_chunks/ru-BMBgVL3s.js.map +0 -1
  41. package/dist/_chunks/ru-hagMa57T.mjs +0 -68
  42. package/dist/_chunks/ru-hagMa57T.mjs.map +0 -1
  43. package/dist/_chunks/tr-CarUU76c.js +0 -66
  44. package/dist/_chunks/tr-CarUU76c.js.map +0 -1
  45. package/dist/_chunks/tr-Dw_jmkG-.mjs +0 -66
  46. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +0 -1
  47. package/dist/_chunks/zh-57YM4amO.mjs +0 -66
  48. package/dist/_chunks/zh-57YM4amO.mjs.map +0 -1
  49. package/dist/_chunks/zh-CukOviB0.js +0 -66
  50. package/dist/_chunks/zh-CukOviB0.js.map +0 -1
  51. package/dist/_chunks/zh-Hans-DSHIXAa3.js +0 -57
  52. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +0 -1
  53. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +0 -57
  54. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +0 -1
  55. package/dist/admin/index.js +0 -6
  56. package/dist/admin/index.js.map +0 -1
  57. package/dist/admin/index.mjs +0 -7
  58. package/dist/admin/index.mjs.map +0 -1
  59. package/dist/admin/src/components/CMHeaderActions.d.ts +0 -4
  60. package/dist/admin/src/components/CMListViewModalsAdditionalInformation.d.ts +0 -4
  61. package/dist/admin/src/components/CheckboxConfirmation.d.ts +0 -20
  62. package/dist/admin/src/components/CreateLocale.d.ts +0 -29
  63. package/dist/admin/src/components/DeleteLocale.d.ts +0 -5
  64. package/dist/admin/src/components/EditLocale.d.ts +0 -13
  65. package/dist/admin/src/components/Initializer.d.ts +0 -5
  66. package/dist/admin/src/components/LocaleListCell.d.ts +0 -9
  67. package/dist/admin/src/components/LocalePicker.d.ts +0 -2
  68. package/dist/admin/src/components/LocaleTable.d.ts +0 -11
  69. package/dist/admin/src/constants.d.ts +0 -22
  70. package/dist/admin/src/contentManagerHooks/editView.d.ts +0 -6
  71. package/dist/admin/src/contentManagerHooks/listView.d.ts +0 -22
  72. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +0 -36
  73. package/dist/admin/src/hooks/useI18n.d.ts +0 -16
  74. package/dist/admin/src/index.d.ts +0 -16
  75. package/dist/admin/src/middlewares/extendCTBAttributeInitialData.d.ts +0 -4
  76. package/dist/admin/src/middlewares/extendCTBInitialData.d.ts +0 -4
  77. package/dist/admin/src/middlewares/rbac-middleware.d.ts +0 -3
  78. package/dist/admin/src/pages/SettingsPage.d.ts +0 -3
  79. package/dist/admin/src/pluginId.d.ts +0 -1
  80. package/dist/admin/src/services/api.d.ts +0 -3
  81. package/dist/admin/src/services/locales.d.ts +0 -4
  82. package/dist/admin/src/types.d.ts +0 -9
  83. package/dist/admin/src/utils/baseQuery.d.ts +0 -20
  84. package/dist/admin/src/utils/fields.d.ts +0 -7
  85. package/dist/admin/src/utils/getTranslation.d.ts +0 -2
  86. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +0 -3
  87. package/dist/admin/src/utils/schemas.d.ts +0 -24
  88. package/dist/admin/src/utils/strings.d.ts +0 -2
  89. package/dist/server/index.js +0 -3522
  90. package/dist/server/index.js.map +0 -1
  91. package/dist/server/index.mjs +0 -3503
  92. package/dist/server/index.mjs.map +0 -1
  93. package/dist/server/src/bootstrap.d.ts +0 -6
  94. package/dist/server/src/bootstrap.d.ts.map +0 -1
  95. package/dist/server/src/constants/index.d.ts +0 -15
  96. package/dist/server/src/constants/index.d.ts.map +0 -1
  97. package/dist/server/src/content-types/index.d.ts +0 -37
  98. package/dist/server/src/content-types/index.d.ts.map +0 -1
  99. package/dist/server/src/content-types/locale/index.d.ts +0 -35
  100. package/dist/server/src/content-types/locale/index.d.ts.map +0 -1
  101. package/dist/server/src/controllers/content-types.d.ts +0 -6
  102. package/dist/server/src/controllers/content-types.d.ts.map +0 -1
  103. package/dist/server/src/controllers/index.d.ts +0 -10
  104. package/dist/server/src/controllers/index.d.ts.map +0 -1
  105. package/dist/server/src/controllers/iso-locales.d.ts +0 -4
  106. package/dist/server/src/controllers/iso-locales.d.ts.map +0 -1
  107. package/dist/server/src/controllers/locales.d.ts +0 -4
  108. package/dist/server/src/controllers/locales.d.ts.map +0 -1
  109. package/dist/server/src/controllers/validate-locale-creation.d.ts +0 -4
  110. package/dist/server/src/controllers/validate-locale-creation.d.ts.map +0 -1
  111. package/dist/server/src/domain/locale.d.ts +0 -11
  112. package/dist/server/src/domain/locale.d.ts.map +0 -1
  113. package/dist/server/src/graphql.d.ts +0 -8
  114. package/dist/server/src/graphql.d.ts.map +0 -1
  115. package/dist/server/src/index.d.ts +0 -148
  116. package/dist/server/src/index.d.ts.map +0 -1
  117. package/dist/server/src/migrations/content-type/disable/index.d.ts +0 -3
  118. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +0 -1
  119. package/dist/server/src/migrations/content-type/enable/index.d.ts +0 -3
  120. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +0 -1
  121. package/dist/server/src/register.d.ts +0 -6
  122. package/dist/server/src/register.d.ts.map +0 -1
  123. package/dist/server/src/routes/admin.d.ts +0 -18
  124. package/dist/server/src/routes/admin.d.ts.map +0 -1
  125. package/dist/server/src/routes/content-api.d.ts +0 -10
  126. package/dist/server/src/routes/content-api.d.ts.map +0 -1
  127. package/dist/server/src/routes/index.d.ts +0 -28
  128. package/dist/server/src/routes/index.d.ts.map +0 -1
  129. package/dist/server/src/services/content-types.d.ts +0 -13
  130. package/dist/server/src/services/content-types.d.ts.map +0 -1
  131. package/dist/server/src/services/entity-service-decorator.d.ts +0 -29
  132. package/dist/server/src/services/entity-service-decorator.d.ts.map +0 -1
  133. package/dist/server/src/services/index.d.ts +0 -71
  134. package/dist/server/src/services/index.d.ts.map +0 -1
  135. package/dist/server/src/services/iso-locales.d.ts +0 -10
  136. package/dist/server/src/services/iso-locales.d.ts.map +0 -1
  137. package/dist/server/src/services/locales.d.ts +0 -17
  138. package/dist/server/src/services/locales.d.ts.map +0 -1
  139. package/dist/server/src/services/localizations.d.ts +0 -8
  140. package/dist/server/src/services/localizations.d.ts.map +0 -1
  141. package/dist/server/src/services/metrics.d.ts +0 -8
  142. package/dist/server/src/services/metrics.d.ts.map +0 -1
  143. package/dist/server/src/services/permissions/actions.d.ts +0 -16
  144. package/dist/server/src/services/permissions/actions.d.ts.map +0 -1
  145. package/dist/server/src/services/permissions/conditions.d.ts +0 -15
  146. package/dist/server/src/services/permissions/conditions.d.ts.map +0 -1
  147. package/dist/server/src/services/permissions/engine.d.ts +0 -6
  148. package/dist/server/src/services/permissions/engine.d.ts.map +0 -1
  149. package/dist/server/src/services/permissions/sections-builder.d.ts +0 -6
  150. package/dist/server/src/services/permissions/sections-builder.d.ts.map +0 -1
  151. package/dist/server/src/services/permissions.d.ts +0 -28
  152. package/dist/server/src/services/permissions.d.ts.map +0 -1
  153. package/dist/server/src/utils/index.d.ts +0 -43
  154. package/dist/server/src/utils/index.d.ts.map +0 -1
  155. package/dist/server/src/validation/content-types.d.ts +0 -3
  156. package/dist/server/src/validation/content-types.d.ts.map +0 -1
  157. package/dist/server/src/validation/locales.d.ts +0 -12
  158. package/dist/server/src/validation/locales.d.ts.map +0 -1
  159. package/dist/shared/contracts/content-manager.d.ts +0 -27
  160. package/dist/shared/contracts/iso-locales.d.ts +0 -21
  161. package/dist/shared/contracts/locales.d.ts +0 -77
  162. package/dist/shared/contracts/shared.d.ts +0 -6
  163. package/strapi-server.js +0 -3
@@ -1,585 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
- const strapiAdmin = require("@strapi/admin/strapi-admin");
6
- const designSystem = require("@strapi/design-system");
7
- const symbols = require("@strapi/icons/symbols");
8
- const reactIntl = require("react-intl");
9
- const icons = require("@strapi/icons");
10
- const yup = require("yup");
11
- const index = require("./index-kcYwoCdE.js");
12
- function _interopNamespace(e) {
13
- if (e && e.__esModule)
14
- return e;
15
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
16
- if (e) {
17
- for (const k in e) {
18
- if (k !== "default") {
19
- const d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: () => e[k]
23
- });
24
- }
25
- }
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
- const React__namespace = /* @__PURE__ */ _interopNamespace(React);
31
- const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
32
- const CreateLocale = ({ disabled, variant = "default" }) => {
33
- const { formatMessage } = reactIntl.useIntl();
34
- const [visible, setVisible] = React__namespace.useState(false);
35
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
36
- /* @__PURE__ */ jsxRuntime.jsx(
37
- designSystem.Button,
38
- {
39
- variant,
40
- disabled,
41
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
42
- onClick: () => setVisible(true),
43
- size: "S",
44
- children: formatMessage({
45
- id: index.getTranslation("Settings.list.actions.add"),
46
- defaultMessage: "Add new locale"
47
- })
48
- }
49
- ),
50
- visible ? /* @__PURE__ */ jsxRuntime.jsx(CreateModal, { onClose: () => setVisible(false) }) : null
51
- ] });
52
- };
53
- const LOCALE_SCHEMA = yup__namespace.object().shape({
54
- code: yup__namespace.string().required({
55
- id: "Settings.locales.modal.create.code.error",
56
- defaultMessage: "Please select a locale"
57
- }),
58
- name: yup__namespace.string().max(50, {
59
- id: "Settings.locales.modal.create.name.error.min",
60
- defaultMessage: "The locale display name can only be less than 50 characters."
61
- }).required({
62
- id: "Settings.locales.modal.create.name.error.required",
63
- defaultMessage: "Please give the locale a display name"
64
- }),
65
- isDefault: yup__namespace.boolean()
66
- });
67
- const initialFormValues = {
68
- code: "",
69
- name: "",
70
- isDefault: false
71
- };
72
- const CreateModal = ({ onClose }) => {
73
- const { toggleNotification } = strapiAdmin.useNotification();
74
- const {
75
- _unstableFormatAPIError: formatAPIError,
76
- _unstableFormatValidationErrors: formatValidationErrors
77
- } = strapiAdmin.useAPIErrorHandler();
78
- const [createLocale] = index.useCreateLocaleMutation();
79
- const { formatMessage } = reactIntl.useIntl();
80
- const refetchPermissions = strapiAdmin.useAuth("CreateModal", (state) => state.refetchPermissions);
81
- const handleSubmit = async (values, helpers) => {
82
- try {
83
- const res = await createLocale(values);
84
- if ("error" in res) {
85
- if (index.isBaseQueryError(res.error) && res.error.name === "ValidationError") {
86
- helpers.setErrors(formatValidationErrors(res.error));
87
- } else {
88
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
89
- }
90
- return;
91
- }
92
- toggleNotification({
93
- type: "success",
94
- message: formatMessage({
95
- id: index.getTranslation("Settings.locales.modal.create.success"),
96
- defaultMessage: "Created locale"
97
- })
98
- });
99
- refetchPermissions();
100
- onClose();
101
- } catch (err) {
102
- toggleNotification({
103
- type: "danger",
104
- message: formatMessage({
105
- id: "notification.error",
106
- defaultMessage: "An error occurred, please try again"
107
- })
108
- });
109
- }
110
- };
111
- const titleId = React__namespace.useId();
112
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxRuntime.jsxs(
113
- strapiAdmin.Form,
114
- {
115
- method: "POST",
116
- initialValues: initialFormValues,
117
- validationSchema: LOCALE_SCHEMA,
118
- onSubmit: handleSubmit,
119
- children: [
120
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
121
- id: index.getTranslation("Settings.list.actions.add"),
122
- defaultMessage: "Add new locale"
123
- }) }) }),
124
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalBody, { children: /* @__PURE__ */ jsxRuntime.jsxs(
125
- designSystem.TabGroup,
126
- {
127
- label: formatMessage({
128
- id: index.getTranslation("Settings.locales.modal.title"),
129
- defaultMessage: "Configurations"
130
- }),
131
- variant: "simple",
132
- children: [
133
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", children: [
134
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { as: "h2", variant: "beta", children: formatMessage({
135
- id: index.getTranslation("Settings.locales.modal.title"),
136
- defaultMessage: "Configuration"
137
- }) }),
138
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs, { children: [
139
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
140
- id: index.getTranslation("Settings.locales.modal.base"),
141
- defaultMessage: "Basic settings"
142
- }) }),
143
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
144
- id: index.getTranslation("Settings.locales.modal.advanced"),
145
- defaultMessage: "Advanced settings"
146
- }) })
147
- ] })
148
- ] }),
149
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
150
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.TabPanels, { children: [
151
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(BaseForm, {}) }),
152
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(AdvancedForm, {}) })
153
- ] }) })
154
- ]
155
- }
156
- ) }),
157
- /* @__PURE__ */ jsxRuntime.jsx(
158
- designSystem.ModalFooter,
159
- {
160
- startActions: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
161
- endActions: /* @__PURE__ */ jsxRuntime.jsx(SubmitButton, {})
162
- }
163
- )
164
- ]
165
- }
166
- ) });
167
- };
168
- const SubmitButton = () => {
169
- const { formatMessage } = reactIntl.useIntl();
170
- const isSubmitting = strapiAdmin.useForm("SubmitButton", (state) => state.isSubmitting);
171
- const modified = strapiAdmin.useForm("SubmitButton", (state) => state.modified);
172
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { type: "submit", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}), disabled: isSubmitting || !modified, children: formatMessage({ id: "global.save", defaultMessage: "Save" }) });
173
- };
174
- const BaseForm = ({ mode = "create" }) => {
175
- const { formatMessage } = reactIntl.useIntl();
176
- const { toggleNotification } = strapiAdmin.useNotification();
177
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
178
- const { data: defaultLocales = [], error } = index.useGetDefaultLocalesQuery();
179
- const { data: locales = [] } = index.useGetLocalesQuery();
180
- React__namespace.useEffect(() => {
181
- if (error) {
182
- toggleNotification({
183
- type: "danger",
184
- message: formatAPIError(error)
185
- });
186
- }
187
- }, [error, formatAPIError, toggleNotification]);
188
- if (!Array.isArray(defaultLocales) || !Array.isArray(locales)) {
189
- return null;
190
- }
191
- const options = defaultLocales.map((locale) => ({
192
- label: locale.name,
193
- value: locale.code
194
- }));
195
- const translatedForm = [
196
- {
197
- disabled: mode !== "create",
198
- label: {
199
- id: index.getTranslation("Settings.locales.modal.create.code.label"),
200
- defaultMessage: "Locales"
201
- },
202
- name: "code",
203
- options,
204
- placeholder: {
205
- id: "components.placeholder.select",
206
- defaultMessage: "Select"
207
- },
208
- required: true,
209
- size: 6,
210
- type: "enumeration"
211
- },
212
- {
213
- hint: {
214
- id: index.getTranslation("Settings.locales.modal.create.name.label.description"),
215
- defaultMessage: "Locale will be displayed under that name in the administration panel"
216
- },
217
- label: {
218
- id: index.getTranslation("Settings.locales.modal.create.name.label"),
219
- defaultMessage: "Locale display name"
220
- },
221
- name: "name",
222
- required: true,
223
- size: 6,
224
- type: "string"
225
- }
226
- ].map((field) => ({
227
- ...field,
228
- hint: field.hint ? formatMessage(field.hint) : void 0,
229
- label: formatMessage(field.label),
230
- placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
231
- }));
232
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid, { gap: 4, children: translatedForm.map(({ size, ...field }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: size, children: /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { ...field }) }, field.name)) });
233
- };
234
- const AdvancedForm = ({ isDefaultLocale }) => {
235
- const { formatMessage } = reactIntl.useIntl();
236
- const form = [
237
- {
238
- disabled: isDefaultLocale,
239
- hint: {
240
- id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
241
- defaultMessage: "One default locale is required, change it by selecting another one"
242
- },
243
- label: {
244
- id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault"),
245
- defaultMessage: "Set as default locale"
246
- },
247
- name: "isDefault",
248
- size: 6,
249
- type: "boolean"
250
- }
251
- ].map((field) => ({
252
- ...field,
253
- hint: field.hint ? formatMessage(field.hint) : void 0,
254
- label: formatMessage(field.label)
255
- }));
256
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid, { gap: 4, children: form.map(({ size, ...field }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: size, children: /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { ...field }) }, field.name)) });
257
- };
258
- const FormRenderer = (field) => {
259
- switch (field.type) {
260
- case "enumeration":
261
- return /* @__PURE__ */ jsxRuntime.jsx(EnumerationInput, { ...field });
262
- default:
263
- return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.InputRenderer, { ...field });
264
- }
265
- };
266
- const EnumerationInput = ({
267
- disabled,
268
- hint,
269
- label,
270
- name,
271
- options,
272
- placeholder,
273
- required
274
- }) => {
275
- const { value, error, onChange } = strapiAdmin.useField(name);
276
- const { data: defaultLocales = [] } = index.useGetDefaultLocalesQuery();
277
- const handleChange = (value2) => {
278
- if (Array.isArray(defaultLocales)) {
279
- const locale = defaultLocales.find((locale2) => locale2.code === value2);
280
- onChange(name, value2);
281
- onChange("name", locale.name);
282
- } else {
283
- onChange(name, value2);
284
- }
285
- };
286
- return /* @__PURE__ */ jsxRuntime.jsx(
287
- designSystem.SingleSelect,
288
- {
289
- disabled,
290
- error,
291
- hint,
292
- label,
293
- name,
294
- onChange: handleChange,
295
- placeholder,
296
- required,
297
- value,
298
- children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: option.value, children: option.label }, option.value))
299
- }
300
- );
301
- };
302
- const DeleteLocale = ({ id, name }) => {
303
- const { formatMessage } = reactIntl.useIntl();
304
- const { toggleNotification } = strapiAdmin.useNotification();
305
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
306
- const [visible, setVisible] = React__namespace.useState(false);
307
- const [deleteLocale] = index.useDeleteLocaleMutation();
308
- const handleConfirm = async () => {
309
- try {
310
- const res = await deleteLocale(id);
311
- if ("error" in res) {
312
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
313
- return;
314
- }
315
- toggleNotification({
316
- type: "success",
317
- message: formatMessage({
318
- id: index.getTranslation("Settings.locales.modal.delete.success"),
319
- defaultMessage: "Deleted locale"
320
- })
321
- });
322
- } catch (err) {
323
- toggleNotification({
324
- type: "danger",
325
- message: formatMessage({
326
- id: "notification.error",
327
- defaultMessage: "An error occurred, please try again"
328
- })
329
- });
330
- }
331
- };
332
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
333
- /* @__PURE__ */ jsxRuntime.jsx(
334
- designSystem.IconButton,
335
- {
336
- onClick: () => setVisible(true),
337
- label: formatMessage(
338
- {
339
- id: index.getTranslation("Settings.list.actions.delete"),
340
- defaultMessage: "Delete {name} locale"
341
- },
342
- {
343
- name
344
- }
345
- ),
346
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
347
- borderWidth: 0
348
- }
349
- ),
350
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.ConfirmDialog, { onConfirm: handleConfirm, onClose: () => setVisible(false), isOpen: visible })
351
- ] });
352
- };
353
- const EditLocale = (props) => {
354
- const { formatMessage } = reactIntl.useIntl();
355
- const [visible, setVisible] = React__namespace.useState(false);
356
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
357
- /* @__PURE__ */ jsxRuntime.jsx(
358
- designSystem.IconButton,
359
- {
360
- onClick: () => setVisible(true),
361
- label: formatMessage(
362
- {
363
- id: index.getTranslation("Settings.list.actions.edit"),
364
- defaultMessage: "Edit {name} locale"
365
- },
366
- {
367
- name: props.name
368
- }
369
- ),
370
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}),
371
- borderWidth: 0
372
- }
373
- ),
374
- visible ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...props, onClose: () => setVisible(false) }) : null
375
- ] });
376
- };
377
- const EditModal = ({ id, code, isDefault, name, onClose }) => {
378
- const { toggleNotification } = strapiAdmin.useNotification();
379
- const {
380
- _unstableFormatAPIError: formatAPIError,
381
- _unstableFormatValidationErrors: formatValidationErrors
382
- } = strapiAdmin.useAPIErrorHandler();
383
- const refetchPermissions = strapiAdmin.useAuth("EditModal", (state) => state.refetchPermissions);
384
- const { formatMessage } = reactIntl.useIntl();
385
- const titleId = React__namespace.useId();
386
- const [updateLocale] = index.useUpdateLocaleMutation();
387
- const handleSubmit = async ({ code: _code, ...data }, helpers) => {
388
- try {
389
- const res = await updateLocale({
390
- id,
391
- ...data
392
- });
393
- if ("error" in res) {
394
- if (index.isBaseQueryError(res.error) && res.error.name === "ValidationError") {
395
- helpers.setErrors(formatValidationErrors(res.error));
396
- } else {
397
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
398
- }
399
- return;
400
- }
401
- toggleNotification({
402
- type: "success",
403
- message: formatMessage({
404
- id: index.getTranslation("Settings.locales.modal.edit.success"),
405
- defaultMessage: "Updated locale"
406
- })
407
- });
408
- refetchPermissions();
409
- onClose();
410
- } catch (err) {
411
- toggleNotification({
412
- type: "danger",
413
- message: formatMessage({
414
- id: "notification.error",
415
- defaultMessage: "An error occurred, please try again"
416
- })
417
- });
418
- }
419
- };
420
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxRuntime.jsxs(
421
- strapiAdmin.Form,
422
- {
423
- method: "PUT",
424
- onSubmit: handleSubmit,
425
- initialValues: {
426
- code,
427
- name,
428
- isDefault
429
- },
430
- validationSchema: LOCALE_SCHEMA,
431
- children: [
432
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
433
- id: index.getTranslation("Settings.list.actions.edit"),
434
- defaultMessage: "Edit a locale"
435
- }) }) }),
436
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalBody, { children: /* @__PURE__ */ jsxRuntime.jsxs(
437
- designSystem.TabGroup,
438
- {
439
- label: formatMessage({
440
- id: index.getTranslation("Settings.locales.modal.title"),
441
- defaultMessage: "Configurations"
442
- }),
443
- variant: "simple",
444
- children: [
445
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", children: [
446
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { as: "h2", variant: "beta", children: formatMessage({
447
- id: index.getTranslation("Settings.locales.modal.title"),
448
- defaultMessage: "Configuration"
449
- }) }),
450
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs, { children: [
451
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
452
- id: index.getTranslation("Settings.locales.modal.base"),
453
- defaultMessage: "Basic settings"
454
- }) }),
455
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
456
- id: index.getTranslation("Settings.locales.modal.advanced"),
457
- defaultMessage: "Advanced settings"
458
- }) })
459
- ] })
460
- ] }),
461
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
462
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.TabPanels, { children: [
463
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(BaseForm, { mode: "edit" }) }),
464
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
465
- ] }) })
466
- ]
467
- }
468
- ) }),
469
- /* @__PURE__ */ jsxRuntime.jsx(
470
- designSystem.ModalFooter,
471
- {
472
- startActions: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
473
- endActions: /* @__PURE__ */ jsxRuntime.jsx(SubmitButton, {})
474
- }
475
- )
476
- ]
477
- }
478
- ) });
479
- };
480
- const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
481
- const [editLocaleId, setEditLocaleId] = React__namespace.useState();
482
- const { formatMessage } = reactIntl.useIntl();
483
- const handleClick = (localeId) => () => {
484
- if (canUpdate) {
485
- setEditLocaleId(localeId);
486
- }
487
- };
488
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 4, rowCount: locales.length + 1, children: [
489
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
490
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
491
- id: index.getTranslation("Settings.locales.row.id"),
492
- defaultMessage: "ID"
493
- }) }) }),
494
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
495
- id: index.getTranslation("Settings.locales.row.displayName"),
496
- defaultMessage: "Display name"
497
- }) }) }),
498
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
499
- id: index.getTranslation("Settings.locales.row.default-locale"),
500
- defaultMessage: "Default locale"
501
- }) }) }),
502
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: "Actions" }) })
503
- ] }) }),
504
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
505
- /* @__PURE__ */ jsxRuntime.jsxs(
506
- designSystem.Tr,
507
- {
508
- onClick: handleClick(locale.id),
509
- style: { cursor: canUpdate ? "pointer" : "default" },
510
- children: [
511
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.id }) }),
512
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.name }) }),
513
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
514
- id: index.getTranslation("Settings.locales.default"),
515
- defaultMessage: "Default"
516
- }) : null }) }),
517
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
518
- canUpdate && /* @__PURE__ */ jsxRuntime.jsx(EditLocale, { ...locale }),
519
- canDelete && !locale.isDefault && /* @__PURE__ */ jsxRuntime.jsx(DeleteLocale, { ...locale })
520
- ] }) })
521
- ]
522
- }
523
- ),
524
- editLocaleId === locale.id ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...locale, onClose: () => setEditLocaleId(void 0) }) : null
525
- ] }, locale.id)) })
526
- ] });
527
- };
528
- const SettingsPage = () => {
529
- const { formatMessage } = reactIntl.useIntl();
530
- const { toggleNotification } = strapiAdmin.useNotification();
531
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
532
- const { data: locales, isLoading: isLoadingLocales, error } = index.useGetLocalesQuery();
533
- const {
534
- isLoading: isLoadingRBAC,
535
- allowedActions: { canUpdate, canCreate, canDelete }
536
- } = strapiAdmin.useRBAC(index.PERMISSIONS);
537
- React__namespace.useEffect(() => {
538
- if (error) {
539
- toggleNotification({
540
- type: "danger",
541
- message: formatAPIError(error)
542
- });
543
- }
544
- }, [error, formatAPIError, toggleNotification]);
545
- const isLoading = isLoadingLocales || isLoadingRBAC;
546
- if (isLoading) {
547
- return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
548
- }
549
- if (error || !Array.isArray(locales)) {
550
- return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Error, {});
551
- }
552
- return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Page.Main, { tabIndex: -1, children: [
553
- /* @__PURE__ */ jsxRuntime.jsx(
554
- designSystem.HeaderLayout,
555
- {
556
- primaryAction: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate }),
557
- title: formatMessage({
558
- id: index.getTranslation("plugin.name"),
559
- defaultMessage: "Internationalization"
560
- }),
561
- subtitle: formatMessage({
562
- id: index.getTranslation("Settings.list.description"),
563
- defaultMessage: "Configure the settings"
564
- })
565
- }
566
- ),
567
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.ContentLayout, { children: locales.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsxRuntime.jsx(
568
- designSystem.EmptyStateLayout,
569
- {
570
- icon: /* @__PURE__ */ jsxRuntime.jsx(symbols.EmptyDocuments, { width: void 0, height: void 0 }),
571
- content: formatMessage({
572
- id: index.getTranslation("Settings.list.empty.title"),
573
- defaultMessage: "There are no locales"
574
- }),
575
- action: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
576
- }
577
- ) })
578
- ] });
579
- };
580
- const ProtectedSettingsPage = () => {
581
- return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions: index.PERMISSIONS.read, children: /* @__PURE__ */ jsxRuntime.jsx(SettingsPage, {}) });
582
- };
583
- exports.ProtectedSettingsPage = ProtectedSettingsPage;
584
- exports.SettingsPage = SettingsPage;
585
- //# sourceMappingURL=SettingsPage-B73NO_8-.js.map