@@ -16,7 +16,12 @@ import {
1616 Grid ,
1717 Loader ,
1818} from '@strapi/design-system' ;
19- import { useNotification , getFetchClient , Layouts } from '@strapi/strapi/admin' ;
19+ import {
20+ useNotification ,
21+ getFetchClient ,
22+ Layouts ,
23+ Page ,
24+ } from '@strapi/strapi/admin' ;
2025import { ArrowLeft , Check } from '@strapi/icons' ;
2126import schema from './utils/schema' ;
2227import { ErrorResponse } from '../../../types/error-response' ;
@@ -28,6 +33,7 @@ import { PatternFormValues, ValidatePatternResponse } from '../../../types/url-p
2833import { EnabledContentTypes } from '../../../types/enabled-contenttypes' ;
2934import LanguageCheckboxes from '../../../components/LanguageCheckboxes' ;
3035import HiddenLocalizedField from '../../../components/HiddenLocalizedField' ;
36+ import pluginPermissions from '../../../permissions' ;
3137
3238const CreatePatternPage = ( ) => {
3339 const navigate = useNavigate ( ) ;
@@ -100,118 +106,120 @@ const CreatePatternPage = () => {
100106 } ;
101107
102108 return (
103- < Formik < PatternFormValues >
104- enableReinitialize
105- initialValues = { {
106- pattern : '' , contenttype : '' , languages : [ ] , localized : false ,
107- } }
108- onSubmit = { handleCreateSubmit }
109- validationSchema = { schema }
110- validate = { validatePattern }
111- validateOnChange = { false }
112- >
113- { ( {
114- handleSubmit,
115- values,
116- errors,
117- touched,
118- isSubmitting,
119- setFieldValue,
120- } ) => (
121- < Form noValidate onSubmit = { handleSubmit } >
122- < Layouts . Header
123- title = { formatMessage ( {
124- id : 'webtools.settings.page.patterns.create.title' ,
125- defaultMessage : 'Add new pattern' ,
126- } ) }
127- subtitle = { formatMessage ( {
128- id : 'webtools.settings.page.patterns.create.description' ,
129- defaultMessage : 'Add a pattern for automatic URL alias generation.' ,
130- } ) }
131- navigationAction = { (
132- < DsLink startIcon = { < ArrowLeft /> } tag = { Link } to = { `/plugins/${ pluginId } /patterns` } >
133- { formatMessage ( {
134- id : 'global.back' ,
135- defaultMessage : 'Back' ,
136- } ) }
137- </ DsLink >
138- ) }
139- primaryAction = { (
140- < Button type = "submit" loading = { isSubmitting } startIcon = { < Check /> } >
141- { formatMessage ( {
142- id : 'global.save' ,
143- defaultMessage : 'Save' ,
144- } ) }
145- </ Button >
146- ) }
147- />
148- < Layouts . Content >
149- < Box
150- background = "neutral0"
151- hasRadius
152- shadow = "filterShadow"
153- paddingTop = { 6 }
154- paddingBottom = { 6 }
155- paddingLeft = { 7 }
156- paddingRight = { 7 }
157- >
158- < Typography variant = "delta" >
159- { formatMessage ( {
160- id : 'webtools.settings.page.patterns.create.subtitle' ,
161- defaultMessage : 'Pattern details' ,
162- } ) }
163- </ Typography >
164- < Grid . Root gap = { 4 } marginTop = { 4 } >
165- < Grid . Item col = { 6 } direction = "column" alignItems = "flex-start" gap = "4" >
166- < Select
167- name = "contenttype"
168- list = { contentTypes . data . data }
169- value = { values . contenttype || '' }
170- setFieldValue = { setFieldValue }
171- label = { formatMessage ( {
172- id : 'webtools.settings.form.contenttype.label' ,
173- defaultMessage : 'Content type' ,
174- } ) }
175- error = {
176- errors . contenttype && touched . contenttype
177- ? formatMessage ( { id : String ( errors . contenttype ) , defaultMessage : 'Invalid value' } )
178- : null
179- }
180- />
181- { ( values . contenttype !== '' ) && (
182- < PatternField
183- values = { values }
184- uid = { values . contenttype }
109+ < Page . Protect permissions = { pluginPermissions [ 'settings.patterns' ] } >
110+ < Formik < PatternFormValues >
111+ enableReinitialize
112+ initialValues = { {
113+ pattern : '' , contenttype : '' , languages : [ ] , localized : false ,
114+ } }
115+ onSubmit = { handleCreateSubmit }
116+ validationSchema = { schema }
117+ validate = { validatePattern }
118+ validateOnChange = { false }
119+ >
120+ { ( {
121+ handleSubmit,
122+ values,
123+ errors,
124+ touched,
125+ isSubmitting,
126+ setFieldValue,
127+ } ) => (
128+ < Form noValidate onSubmit = { handleSubmit } >
129+ < Layouts . Header
130+ title = { formatMessage ( {
131+ id : 'webtools.settings.page.patterns.create.title' ,
132+ defaultMessage : 'Add new pattern' ,
133+ } ) }
134+ subtitle = { formatMessage ( {
135+ id : 'webtools.settings.page.patterns.create.description' ,
136+ defaultMessage : 'Add a pattern for automatic URL alias generation.' ,
137+ } ) }
138+ navigationAction = { (
139+ < DsLink startIcon = { < ArrowLeft /> } tag = { Link } to = { `/plugins/${ pluginId } /patterns` } >
140+ { formatMessage ( {
141+ id : 'global.back' ,
142+ defaultMessage : 'Back' ,
143+ } ) }
144+ </ DsLink >
145+ ) }
146+ primaryAction = { (
147+ < Button type = "submit" loading = { isSubmitting } startIcon = { < Check /> } >
148+ { formatMessage ( {
149+ id : 'global.save' ,
150+ defaultMessage : 'Save' ,
151+ } ) }
152+ </ Button >
153+ ) }
154+ />
155+ < Layouts . Content >
156+ < Box
157+ background = "neutral0"
158+ hasRadius
159+ shadow = "filterShadow"
160+ paddingTop = { 6 }
161+ paddingBottom = { 6 }
162+ paddingLeft = { 7 }
163+ paddingRight = { 7 }
164+ >
165+ < Typography variant = "delta" >
166+ { formatMessage ( {
167+ id : 'webtools.settings.page.patterns.create.subtitle' ,
168+ defaultMessage : 'Pattern details' ,
169+ } ) }
170+ </ Typography >
171+ < Grid . Root gap = { 4 } marginTop = { 4 } >
172+ < Grid . Item col = { 6 } direction = "column" alignItems = "flex-start" gap = "4" >
173+ < Select
174+ name = "contenttype"
175+ list = { contentTypes . data . data }
176+ value = { values . contenttype || '' }
185177 setFieldValue = { setFieldValue }
178+ label = { formatMessage ( {
179+ id : 'webtools.settings.form.contenttype.label' ,
180+ defaultMessage : 'Content type' ,
181+ } ) }
186182 error = {
187- errors . pattern && touched . pattern
188- ? errors . pattern
183+ errors . contenttype && touched . contenttype
184+ ? formatMessage ( { id : String ( errors . contenttype ) , defaultMessage : 'Invalid value' } )
189185 : null
190186 }
191187 />
192- ) }
193- < HiddenLocalizedField
194- localized = { getSelectedContentType ( values . contenttype ) ?. localized }
195- setFieldValue = { setFieldValue }
196- />
197- { values . localized && (
198- < LanguageCheckboxes
199- onChange = { ( newLanguages ) => setFieldValue ( 'languages' , newLanguages ) }
200- selectedLanguages = { values . languages }
201- error = {
202- errors . languages && touched . languages
203- ? errors . languages
204- : null
205- }
188+ { ( values . contenttype !== '' ) && (
189+ < PatternField
190+ values = { values }
191+ uid = { values . contenttype }
192+ setFieldValue = { setFieldValue }
193+ error = {
194+ errors . pattern && touched . pattern
195+ ? errors . pattern
196+ : null
197+ }
198+ />
199+ ) }
200+ < HiddenLocalizedField
201+ localized = { getSelectedContentType ( values . contenttype ) ?. localized }
202+ setFieldValue = { setFieldValue }
206203 />
207- ) }
208- </ Grid . Item >
209- </ Grid . Root >
210- </ Box >
211- </ Layouts . Content >
212- </ Form >
213- ) }
214- </ Formik >
204+ { values . localized && (
205+ < LanguageCheckboxes
206+ onChange = { ( newLanguages ) => setFieldValue ( 'languages' , newLanguages ) }
207+ selectedLanguages = { values . languages }
208+ error = {
209+ errors . languages && touched . languages
210+ ? errors . languages
211+ : null
212+ }
213+ />
214+ ) }
215+ </ Grid . Item >
216+ </ Grid . Root >
217+ </ Box >
218+ </ Layouts . Content >
219+ </ Form >
220+ ) }
221+ </ Formik >
222+ </ Page . Protect >
215223 ) ;
216224} ;
217225
0 commit comments