@@ -20,13 +20,22 @@ import { FormikProvider, useFormik } from "formik";
2020import * as yup from "yup" ;
2121import MuiFormikTextField from "../../../../components/mui/formik-inputs/mui-formik-textfield" ;
2222import PageModules from "./page-template-modules-form" ;
23+ import { resetPageTemplateForm } from "../../../../actions/page-template-actions" ;
2324import {
2425 PAGES_MODULE_KINDS ,
25- PAGE_MODULES_MEDIA_TYPES
26+ PAGE_MODULES_MEDIA_TYPES ,
27+ PAGE_MODULES_DOWNLOAD
2628} from "../../../../utils/constants" ;
2729
28- const PageTemplatePopup = ( { pageTemplate, open, onClose, onSave } ) => {
30+ const PageTemplatePopup = ( {
31+ pageTemplate,
32+ open,
33+ onClose,
34+ onSave,
35+ resetPageTemplateForm
36+ } ) => {
2937 const handleClose = ( ) => {
38+ resetPageTemplateForm ( ) ;
3039 onClose ( ) ;
3140 } ;
3241
@@ -78,8 +87,16 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
7887 kind : yup . string ( ) . equals ( [ PAGES_MODULE_KINDS . DOCUMENT ] ) ,
7988 name : yup . string ( ) . required ( T . translate ( "validation.required" ) ) ,
8089 description : yup . string ( ) . required ( T . translate ( "validation.required" ) ) ,
81- external_url : yup . string ( ) ,
82- file : yup . array ( ) . min ( 1 , T . translate ( "validation.file_required" ) )
90+ external_url : yup . string ( ) . when ( "type" , {
91+ is : PAGE_MODULES_DOWNLOAD . URL ,
92+ then : ( schema ) => schema . required ( T . translate ( "validation.required" ) ) ,
93+ otherwise : ( schema ) => schema . nullable ( )
94+ } ) ,
95+ file : yup . array ( ) . when ( "type" , {
96+ is : PAGE_MODULES_DOWNLOAD . FILE ,
97+ then : ( schema ) => schema . min ( 1 , T . translate ( "validation.file_required" ) ) ,
98+ otherwise : ( schema ) => schema . nullable ( )
99+ } )
83100 } ) ;
84101
85102 const mediaModuleSchema = yup . object ( ) . shape ( {
@@ -88,7 +105,7 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
88105 type : yup . string ( ) . required ( T . translate ( "validation.required" ) ) ,
89106 upload_deadline : yup . date ( ) . required ( T . translate ( "validation.required" ) ) ,
90107 description : yup . string ( ) . required ( T . translate ( "validation.required" ) ) ,
91- file_type_id : yup . object ( ) . when ( "type" , {
108+ file_type_id : yup . number ( ) . when ( "type" , {
92109 is : PAGE_MODULES_MEDIA_TYPES . FILE ,
93110 then : ( schema ) => schema . required ( T . translate ( "validation.required" ) ) ,
94111 otherwise : ( schema ) => schema . nullable ( )
@@ -124,6 +141,7 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
124141 ...m ,
125142 custom_order : idx
126143 } ) ) ;
144+
127145 onSave ( { ...values , modules : modulesWithOrder } ) ;
128146 }
129147 } ) ;
@@ -148,24 +166,24 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
148166 >
149167 < DialogContent sx = { { p : 0 } } >
150168 < Grid2 container spacing = { 2 } size = { 12 } sx = { { p : 2 } } >
151- < Grid2 spacing = { 2 } size = { 4 } >
169+ < Grid2 size = { 4 } >
152170 < MuiFormikTextField
153171 name = "code"
154172 label = { T . translate ( "page_template_list.code" ) }
155173 fullWidth
156174 />
157175 </ Grid2 >
158- < Grid2 spacing = { 2 } size = { 8 } >
176+ < Grid2 size = { 8 } >
159177 < MuiFormikTextField
160178 name = "name"
161179 label = { T . translate ( "page_template_list.name" ) }
162180 fullWidth
163181 />
164182 </ Grid2 >
165183 </ Grid2 >
166- < Divider gutterBottom />
184+ < Divider sx = { { mb : 2 } } />
167185 < Grid2 container spacing = { 2 } size = { 12 } sx = { { p : 2 } } >
168- < Grid2 spacing = { 2 } size = { 4 } >
186+ < Grid2 size = { 4 } >
169187 < Button
170188 variant = "contained"
171189 fullWidth
@@ -175,7 +193,7 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
175193 { T . translate ( "page_template_list.page_crud.add_info" ) }
176194 </ Button >
177195 </ Grid2 >
178- < Grid2 spacing = { 2 } size = { 4 } >
196+ < Grid2 size = { 4 } >
179197 < Button
180198 variant = "contained"
181199 fullWidth
@@ -185,7 +203,7 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
185203 { T . translate ( "page_template_list.page_crud.add_doc" ) }
186204 </ Button >
187205 </ Grid2 >
188- < Grid2 spacing = { 2 } size = { 4 } >
206+ < Grid2 size = { 4 } >
189207 < Button
190208 variant = "contained"
191209 fullWidth
@@ -196,7 +214,7 @@ const PageTemplatePopup = ({ pageTemplate, open, onClose, onSave }) => {
196214 </ Button >
197215 </ Grid2 >
198216 </ Grid2 >
199- < Divider gutterBottom />
217+ < Divider sx = { { mb : 2 } } />
200218 < Box sx = { { py : 2 } } >
201219 < PageModules name = "modules" />
202220 </ Box >
@@ -219,8 +237,10 @@ PageTemplatePopup.propTypes = {
219237 onSave : PropTypes . func . isRequired
220238} ;
221239
222- const mapStateToProps = ( { currentPageTemplateState } ) => ( {
223- ... currentPageTemplateState
240+ const mapStateToProps = ( { pageTemplateState } ) => ( {
241+ pageTemplate : pageTemplateState . entity
224242} ) ;
225243
226- export default connect ( mapStateToProps , { } ) ( PageTemplatePopup ) ;
244+ export default connect ( mapStateToProps , {
245+ resetPageTemplateForm
246+ } ) ( PageTemplatePopup ) ;
0 commit comments