Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 110 additions & 39 deletions admin/src/pages/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { Accordion, Alert, Box, Button, Field, Flex, Grid, MultiSelect, MultiSelectOption, Switch, Toggle, Typography } from '@strapi/design-system';
import {
Accordion,
Alert,
Box,
Button,
Field,
Flex,
Grid,
MultiSelect,
MultiSelectOption,
Switch,
Toggle,
Typography,
} from '@strapi/design-system';
import { ArrowClockwise, Check, Play } from '@strapi/icons';
import { Form, Layouts, Page, useNotification } from '@strapi/strapi/admin';
import { useQueryClient } from '@tanstack/react-query';

import { Badge } from '@strapi/design-system';
import { isNil, orderBy } from 'lodash';
import { useCallback, useRef, useState } from 'react';
import styled from 'styled-components';
import * as pluginPkg from '../../../../package.json';
import { ConfirmationDialog } from '../../components/ConfirmationDialog';
import { RenderIf } from '../../components/RenderIf';
import { useAPI } from '../../hooks/useAPI';
Expand All @@ -14,6 +29,8 @@ import { CommonProviders } from '../../providers/CommonProviders';
import { getMessage } from '../../utils';
import { useSettingsAPI } from './hooks/useSettingsAPI';

const pluginVersion = pluginPkg.version;

const boxDefaultProps = {
background: 'neutral0',
hasRadius: true,
Expand Down Expand Up @@ -71,13 +88,15 @@ const Settings = () => {
formRef.current?.requestSubmit();
}, []);

const onSubmit = useCallback((values: any) => {
updateSettingsMutation.mutate({
...values,
blockedAuthorProps: values.blockedAuthorProps.split(',').map((prop: string) => prop.trim()),
});
}, [updateSettingsMutation]);

const onSubmit = useCallback(
(values: any) => {
updateSettingsMutation.mutate({
...values,
blockedAuthorProps: values.blockedAuthorProps.split(',').map((prop: string) => prop.trim()),
});
},
[updateSettingsMutation]
);

if (
config.status !== 'success' ||
Expand All @@ -89,13 +108,15 @@ const Settings = () => {
return getMessage('page.settings.loading');
}

const allCollections = collectionTypes.data.filter(ct => ct.uid.includes('api::'));
const enabledCollections = config.data.enabledCollections
.filter((uid: string) => allCollections.some(ct => ct.uid === uid));
const allCollections = collectionTypes.data.filter((ct) => ct.uid.includes('api::'));
const enabledCollections = config.data.enabledCollections.filter((uid: string) =>
allCollections.some((ct) => ct.uid === uid)
);
const badWords = isNil(config.data.badWords) ? true : config.data?.badWords;
const gqlAuthEnabled = Boolean(config.data.gql?.auth || null);
const moderatorRoles = config.data.moderatorRoles
.filter((role: string) => roles.data.filter((r) => r.code === role));
const moderatorRoles = config.data.moderatorRoles.filter((role: string) =>
roles.data.filter((r) => r.code === role)
);
const clientUrl = config.data.client?.url;
const clientEmail = config.data.client?.contactEmail;
const blockedAuthorProps = config.data.blockedAuthorProps ?? [];
Expand All @@ -107,15 +128,23 @@ const Settings = () => {
<Page.Main>
<Layouts.Header
title={getMessage('page.settings.header.title')}
subtitle={getMessage('page.settings.header.description')}
as="h2"
primaryAction={(
subtitle={
<Flex direction="row" gap={3} alignItems="center" justifyContent="space-between">
<Typography variant="epsilon" textColor="neutral600" tag="p">
{getMessage('page.settings.header.description')}
</Typography>
<Badge color="neutral" minWidth="fit-content">
<span style={{ textTransform: 'none' }}>v{pluginVersion}</span>
</Badge>
</Flex>
}
primaryAction={
<RenderIf condition={canSettingsChange}>
<Button type="submit" startIcon={<Check />} onClick={onTriggerSubmit}>
{getMessage('page.settings.actions.submit')}
</Button>
</RenderIf>
)}
}
/>
<Layouts.Content>
{isRestartRequired && (
Expand Down Expand Up @@ -164,7 +193,10 @@ const Settings = () => {
</Typography>
<Grid.Root gap={4} marginTop={4} width="100%">
<Grid.Item xs={12}>
<Field.Root width="100%" hint={getMessage('page.settings.form.enabledCollections.hint')}>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.enabledCollections.hint')}
>
<Field.Label htmlFor="enabledCollections">
{getMessage('page.settings.form.enabledCollections.label')}
</Field.Label>
Expand Down Expand Up @@ -195,11 +227,15 @@ const Settings = () => {
</Grid.Item>
<Grid.Item>
<Accordion.Root style={{ width: '100%' }}>
{orderBy(values.enabledCollections).map(uid => {
const collection = allCollections.find(ct => ct.uid === uid);
{orderBy(values.enabledCollections).map((uid) => {
const collection = allCollections.find((ct) => ct.uid === uid);
if (collection) {
const { schema: { displayName, attributes } } = collection;
const stringAttributes = Object.keys(attributes).filter((key) => attributes[key].type === 'string');
const {
schema: { displayName, attributes },
} = collection;
const stringAttributes = Object.keys(attributes).filter(
(key) => attributes[key].type === 'string'
);
return (
<Accordion.Item key={uid} value={uid}>
<Accordion.Header>
Expand All @@ -220,15 +256,24 @@ const Settings = () => {
})}
>
<Field.Label>
{getMessage('page.settings.form.approvalFlow.label')}
{getMessage(
'page.settings.form.approvalFlow.label'
)}
</Field.Label>
<Switch
visibleLabels
onLabel={getMessage('components.toogle.enabled')}
offLabel={getMessage('components.toogle.disabled')}
checked={values.approvalFlow.includes(uid)}
onCheckedChange={(checked: boolean) => {
onChange('approvalFlow', checked ? [...values.approvalFlow, uid] : values.approvalFlow.filter((c: string) => c !== uid));
onChange(
'approvalFlow',
checked
? [...values.approvalFlow, uid]
: values.approvalFlow.filter(
(c: string) => c !== uid
)
);
}}
/>
<Field.Hint />
Expand All @@ -238,18 +283,27 @@ const Settings = () => {
<Grid.Item>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.entryLabel.hint')}
hint={getMessage(
'page.settings.form.entryLabel.hint'
)}
>
<Field.Label>
{getMessage('page.settings.form.entryLabel.label')}
{getMessage(
'page.settings.form.entryLabel.label'
)}
</Field.Label>
<MultiSelect
withTags
placeholder={getMessage('page.settings.form.entryLabel.placeholder')}
placeholder={getMessage(
'page.settings.form.entryLabel.placeholder'
)}
name="enabledCollections"
value={values.entryLabel[uid] ?? []}
onChange={(value: string[]) => {
onChange('entryLabel', { ...values.entryLabel, [uid]: value });
onChange('entryLabel', {
...values.entryLabel,
[uid]: value,
});
}}
>
{stringAttributes.map((attr) => (
Expand Down Expand Up @@ -282,7 +336,10 @@ const Settings = () => {
</Typography>
<Grid.Root gap={4} marginTop={4} width="100%">
<Grid.Item col={4} xs={12} alignItems="start">
<Field.Root width="100%" hint={getMessage('page.settings.form.enabledCollections.hint')}>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.enabledCollections.hint')}
>
<Field.Label htmlFor="enabledCollections">
{getMessage('page.settings.form.enabledCollections.label')}
</Field.Label>
Expand All @@ -298,19 +355,24 @@ const Settings = () => {
</Field.Root>
</Grid.Item>
<Grid.Item col={4} xs={12} alignItems="start">
<Field.Root width="100%" hint={getMessage('page.settings.form.author.blockedProps.hint')}>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.author.blockedProps.hint')}
>
<Field.Label htmlFor="enabledCollections">
{getMessage('page.settings.form.author.blockedProps.label')}
</Field.Label>
<Field.Input name="blockedAuthorProps" value={values.blockedAuthorProps} onChange={onChange} />
<Field.Input
name="blockedAuthorProps"
value={values.blockedAuthorProps}
onChange={onChange}
/>
<Field.Hint />
</Field.Root>
</Grid.Item>
<Grid.Item col={4} xs={12} alignItems="start">
<Field.Root width="100%" hint={getMessage('page.settings.form.gqlAuth.hint')}>
<Field.Label>
{getMessage('page.settings.form.gqlAuth.label')}
</Field.Label>
<Field.Label>{getMessage('page.settings.form.gqlAuth.label')}</Field.Label>
<Toggle
name="gqlAuthEnabled"
checked={values.gqlAuthEnabled}
Expand All @@ -330,7 +392,10 @@ const Settings = () => {
</Typography>
<Grid.Root gap={4} marginTop={4} width="100%">
<Grid.Item col={4} xs={12} alignItems="start">
<Field.Root width="100%" hint={getMessage('page.settings.form.client.url.hint')}>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.client.url.hint')}
>
<Field.Label>
{getMessage('page.settings.form.client.url.label')}
</Field.Label>
Expand All @@ -339,7 +404,10 @@ const Settings = () => {
</Field.Root>
</Grid.Item>
<Grid.Item col={4} xs={12} alignItems="start">
<Field.Root width="100%" hint={getMessage('page.settings.form.client.email.hint')}>
<Field.Root
width="100%"
hint={getMessage('page.settings.form.client.email.hint')}
>
<Field.Label>
{getMessage('page.settings.form.client.email.label')}
</Field.Label>
Expand Down Expand Up @@ -398,8 +466,11 @@ const Settings = () => {
)}
onConfirm={restoreSettingsMutation.mutate}
title={getMessage('page.settings.actions.restore.confirmation.header')}
labelConfirm={getMessage('page.settings.actions.restore.confirmation.button.confirm')}
iconConfirm={<ArrowClockwise />}>
labelConfirm={getMessage(
'page.settings.actions.restore.confirmation.button.confirm'
)}
iconConfirm={<ArrowClockwise />}
>
{getMessage('page.settings.actions.restore.confirmation.description')}
</ConfirmationDialog>
</Flex>
Expand All @@ -418,4 +489,4 @@ export default () => (
<CommonProviders>
<Settings />
</CommonProviders>
);
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-comments",
"version": "3.2.3-beta.2",
"version": "3.2.3",
"description": "Strapi - Comments plugin",
"strapi": {
"name": "comments",
Expand Down