UNPKG

strapi-plugin-comments

Version:
418 lines (417 loc) 19.8 kB
import { jsx as e, Fragment as O, jsxs as i } from "react/jsx-runtime"; import { Button as F, Flex as I, Typography as h, Badge as oe, Box as m, Grid as s, Field as n, MultiSelect as q, MultiSelectOption as A, Accordion as y, Switch as re, Toggle as B, Alert as se } from "@strapi/design-system"; import { Check as le, Play as ae, ArrowClockwise as W } from "@strapi/icons"; import { useNotification as ce, Page as j, Layouts as N, Form as de } from "@strapi/strapi/admin"; import { useMutation as T, useQuery as v, useQueryClient as ge } from "@tanstack/react-query"; import { u as U, f as he, a as pe, g as t, l as D, e as me } from "./index-BIaTg-pL.mjs"; import { useMemo as ue, useRef as be, useState as fe, useCallback as Q } from "react"; import ye from "styled-components"; import { v as Se } from "./index-CynNsAVf.mjs"; const P = ({ children: c, condition: a }) => a ? /* @__PURE__ */ e(O, { children: c }) : null, we = (c = {}) => { const a = U(), S = T({ mutationFn: a.settings.update, onSuccess: c.updateSettingsMutationSuccess, onError: c.updateSettingsMutationError }), p = T({ mutationFn: a.settings.restore, onSuccess: c.restoreSettingsMutationSuccess, onError: c.restoreSettingsMutationError }), w = T({ mutationFn: a.settings.restart, onSuccess: c.restartStrapiMutationSuccess, onError: c.restartStrapiMutationError }), u = v({ queryKey: a.config.getKey(), queryFn: a.config.query }), b = v({ queryKey: a.contentTypeBuilder.all.getKey(), queryFn: a.contentTypeBuilder.all.query }), f = v({ queryKey: a.roles.getKey(), queryFn: a.roles.query }); return ue(() => ({ config: u, collectionTypes: b, roles: f, restoreSettingsMutation: p, updateSettingsMutation: S, restartStrapiMutation: w }), [ u, f, b, p, S, w ]); }, Ce = Se, R = { background: "neutral0", hasRadius: !0, shadow: "filterShadow", padding: 6, width: "100%" }, Ie = ye(se)(() => ({ "[role]": { flexDirection: "column" } })), Re = () => { const c = be(null), { toggleNotification: a } = ce(), [S, p] = fe(!1), { isLoadingForPermissions: w, canSettingsChange: u } = pe(), b = ge(), f = U(), { config: d, collectionTypes: M, roles: L, restoreSettingsMutation: V, updateSettingsMutation: k, restartStrapiMutation: G } = we({ restoreSettingsMutationSuccess: () => { b.invalidateQueries({ queryKey: f.config.getKey(), exact: !1 }), p(!0), a({ message: t("page.settings.actions.restore.success"), type: "success" }); }, restartStrapiMutationSuccess: () => { p(!1); }, updateSettingsMutationSuccess: () => { b.invalidateQueries({ queryKey: f.config.getKey(), exact: !1 }), p(!0); } }), z = Q(() => { c.current?.requestSubmit(); }, []), J = Q( (r) => { k.mutate({ ...r, blockedAuthorProps: r.blockedAuthorProps.split(",").map((l) => l.trim()) }); }, [k] ); if (d.status !== "success" || M.status !== "success" || L.status !== "success" || w) return t("page.settings.loading"); const x = M.data.filter((r) => r.uid.includes("api::")), X = d.data.enabledCollections.filter( (r) => x.some((l) => l.uid === r) ), Y = D.isNil(d.data.badWords) ? !0 : d.data?.badWords, Z = !!d.data.gql?.auth, _ = d.data.moderatorRoles.filter( (r) => L.data.filter((l) => l.code === r) ), $ = d.data.client?.url, ee = d.data.client?.contactEmail, te = d.data.blockedAuthorProps ?? [], ne = () => p(!1); return /* @__PURE__ */ i(O, { children: [ /* @__PURE__ */ e(j.Title, { children: "Comments - settings" }), /* @__PURE__ */ i(j.Main, { children: [ /* @__PURE__ */ e( N.Header, { title: t("page.settings.header.title"), subtitle: /* @__PURE__ */ i(I, { direction: "row", gap: 3, alignItems: "center", justifyContent: "space-between", children: [ /* @__PURE__ */ e(h, { variant: "epsilon", textColor: "neutral600", tag: "p", children: t("page.settings.header.description") }), /* @__PURE__ */ e(oe, { color: "neutral", minWidth: "fit-content", children: /* @__PURE__ */ i("span", { style: { textTransform: "none" }, children: [ "v", Ce ] }) }) ] }), primaryAction: /* @__PURE__ */ e(P, { condition: u, children: /* @__PURE__ */ e(F, { type: "submit", startIcon: /* @__PURE__ */ e(le, {}), onClick: z, children: t("page.settings.actions.submit") }) }) } ), /* @__PURE__ */ i(N.Content, { children: [ S && /* @__PURE__ */ e(m, { marginBottom: 4, children: /* @__PURE__ */ e( Ie, { closeLabel: t("page.settings.actions.restart.alert.close"), title: t("page.settings.actions.restart.alert.title"), onClose: ne, action: /* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(F, { onClick: G.mutate, startIcon: /* @__PURE__ */ e(ae, {}), children: t("page.settings.actions.restart") }) }), children: /* @__PURE__ */ e(m, { marginTop: 4, children: t("page.settings.actions.restart.alert.description") }) } ) }), /* @__PURE__ */ e( de, { method: "POST", width: "auto", height: "auto", ref: c, onSubmit: J, initialValues: { enabledCollections: X, moderatorRoles: _, badWords: Y, clientEmail: ee, clientUrl: $, gqlAuthEnabled: Z, approvalFlow: d.data.approvalFlow, entryLabel: d.data.entryLabel, blockedAuthorProps: te.join(", ") }, children: ({ values: r, onChange: l }) => /* @__PURE__ */ i(I, { gap: 4, direction: "column", children: [ /* @__PURE__ */ i(m, { ...R, children: [ /* @__PURE__ */ e(h, { variant: "delta", as: "h2", children: t("page.settings.section.general") }), /* @__PURE__ */ i(s.Root, { gap: 4, marginTop: 4, width: "100%", children: [ /* @__PURE__ */ e(s.Item, { xs: 12, children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.enabledCollections.hint"), children: [ /* @__PURE__ */ e(n.Label, { htmlFor: "enabledCollections", children: t("page.settings.form.enabledCollections.label") }), /* @__PURE__ */ e( q, { withTags: !0, name: "enabledCollections", value: r.enabledCollections, onChange: (o) => { l("enabledCollections", o); }, children: x.map((o) => /* @__PURE__ */ e(A, { value: o.uid, children: o.schema.displayName }, o.uid)) } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), r.enabledCollections.length > 0 && /* @__PURE__ */ e(s.Item, { children: /* @__PURE__ */ i(s.Root, { gap: 4, width: "100%", children: [ /* @__PURE__ */ e(s.Item, { children: /* @__PURE__ */ e(h, { children: t("page.settings.form.contentTypesSettings.label") }) }), /* @__PURE__ */ e(s.Item, { children: /* @__PURE__ */ e(y.Root, { style: { width: "100%" }, children: D.orderBy(r.enabledCollections).map((o) => { const E = x.find((C) => C.uid === o); if (E) { const { schema: { displayName: C, attributes: H } } = E, K = Object.keys(H).filter( (g) => H[g].type === "string" ); return /* @__PURE__ */ i(y.Item, { value: o, children: [ /* @__PURE__ */ e(y.Header, { children: /* @__PURE__ */ e(y.Trigger, { children: /* @__PURE__ */ e(h, { variant: "epsilon", as: "h3", children: C }) }) }), /* @__PURE__ */ e(y.Content, { children: /* @__PURE__ */ i(s.Root, { padding: 6, gap: 4, children: [ /* @__PURE__ */ e(s.Item, { children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t({ id: "page.settings.form.approvalFlow.hint", props: { name: C } }), children: [ /* @__PURE__ */ e(n.Label, { children: t( "page.settings.form.approvalFlow.label" ) }), /* @__PURE__ */ e( re, { visibleLabels: !0, onLabel: t("components.toogle.enabled"), offLabel: t("components.toogle.disabled"), checked: r.approvalFlow.includes(o), onCheckedChange: (g) => { l( "approvalFlow", g ? [...r.approvalFlow, o] : r.approvalFlow.filter( (ie) => ie !== o ) ); } } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), /* @__PURE__ */ e(P, { condition: K.length > 0, children: /* @__PURE__ */ e(s.Item, { children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t( "page.settings.form.entryLabel.hint" ), children: [ /* @__PURE__ */ e(n.Label, { children: t( "page.settings.form.entryLabel.label" ) }), /* @__PURE__ */ e( q, { withTags: !0, placeholder: t( "page.settings.form.entryLabel.placeholder" ), name: "enabledCollections", value: r.entryLabel[o] ?? [], onChange: (g) => { l("entryLabel", { ...r.entryLabel, [o]: g }); }, children: K.map((g) => /* @__PURE__ */ e(A, { value: g, children: g }, g)) } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }) }) ] }) }) ] }, o); } return null; }) }) }) ] }) }) ] }) ] }), /* @__PURE__ */ i(m, { ...R, children: [ /* @__PURE__ */ e(h, { variant: "delta", as: "h2", children: t("page.settings.section.additional") }), /* @__PURE__ */ i(s.Root, { gap: 4, marginTop: 4, width: "100%", children: [ /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.enabledCollections.hint"), children: [ /* @__PURE__ */ e(n.Label, { htmlFor: "enabledCollections", children: t("page.settings.form.enabledCollections.label") }), /* @__PURE__ */ e( B, { name: "badWords", checked: r.badWords, onChange: l, onLabel: t("components.toogle.enabled"), offLabel: t("components.toogle.disabled"), width: "100%" } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.author.blockedProps.hint"), children: [ /* @__PURE__ */ e(n.Label, { htmlFor: "enabledCollections", children: t("page.settings.form.author.blockedProps.label") }), /* @__PURE__ */ e( n.Input, { name: "blockedAuthorProps", value: r.blockedAuthorProps, onChange: l } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i(n.Root, { width: "100%", hint: t("page.settings.form.gqlAuth.hint"), children: [ /* @__PURE__ */ e(n.Label, { children: t("page.settings.form.gqlAuth.label") }), /* @__PURE__ */ e( B, { name: "gqlAuthEnabled", checked: r.gqlAuthEnabled, onChange: l, onLabel: t("components.toogle.enabled"), offLabel: t("components.toogle.disabled"), width: "100%" } ), /* @__PURE__ */ e(n.Hint, {}) ] }) }) ] }) ] }), /* @__PURE__ */ i(m, { ...R, children: [ /* @__PURE__ */ e(h, { variant: "delta", as: "h2", children: t("page.settings.section.client") }), /* @__PURE__ */ i(s.Root, { gap: 4, marginTop: 4, width: "100%", children: [ /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.client.url.hint"), children: [ /* @__PURE__ */ e(n.Label, { children: t("page.settings.form.client.url.label") }), /* @__PURE__ */ e(n.Input, { name: "clientUrl", onChange: l }), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.client.email.hint"), children: [ /* @__PURE__ */ e(n.Label, { children: t("page.settings.form.client.email.label") }), /* @__PURE__ */ e(n.Input, { name: "clientEmail", onChange: l }), /* @__PURE__ */ e(n.Hint, {}) ] } ) }), /* @__PURE__ */ e(s.Item, { col: 4, xs: 12, alignItems: "start", children: /* @__PURE__ */ i( n.Root, { width: "100%", hint: t("page.settings.form.moderatorRoles.hint"), children: [ /* @__PURE__ */ e(n.Label, { children: t("page.settings.form.moderatorRoles.label") }), /* @__PURE__ */ e( q, { withTags: !0, placeholder: t("page.settings.form.moderatorRoles.placeholder"), name: "enabledCollections", value: r.moderatorRoles, onChange: (o) => { l("moderatorRoles", o); }, children: L.data.map((o) => /* @__PURE__ */ e(A, { value: o.code, children: o.name }, o.code)) } ), /* @__PURE__ */ e(n.Hint, {}) ] } ) }) ] }) ] }), /* @__PURE__ */ e(P, { condition: u, children: /* @__PURE__ */ e(m, { ...R, children: /* @__PURE__ */ i(I, { gap: 4, direction: "column", alignItems: "flex-start", children: [ /* @__PURE__ */ i(I, { gap: 2, direction: "column", alignItems: "flex-start", children: [ /* @__PURE__ */ e(h, { variant: "delta", as: "h2", children: t("page.settings.section.restore") }), /* @__PURE__ */ e(h, { variant: "pi", as: "h4", children: t("page.settings.section.restore.subtitle") }) ] }), /* @__PURE__ */ e( me, { Trigger: ({ onClick: o }) => /* @__PURE__ */ e( F, { variant: "danger-light", startIcon: /* @__PURE__ */ e(W, {}), onClick: o, children: t("page.settings.actions.restore") } ), onConfirm: V.mutate, title: t("page.settings.actions.restore.confirmation.header"), labelConfirm: t( "page.settings.actions.restore.confirmation.button.confirm" ), iconConfirm: /* @__PURE__ */ e(W, {}), children: t("page.settings.actions.restore.confirmation.description") } ) ] }) }) }) ] }) } ) ] }) ] }) ] }); }, ke = () => /* @__PURE__ */ e(he, { children: /* @__PURE__ */ e(Re, {}) }); export { ke as default };