Merge pull request #1887 from automatisch/AUT-982
feat: implement propTypes for FlowSubstep and FlowSubstepTitle
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | import PropTypes from 'prop-types'; | ||||||
| import * as React from 'react'; | import * as React from 'react'; | ||||||
| import { v4 as uuidv4 } from 'uuid'; | import { v4 as uuidv4 } from 'uuid'; | ||||||
| import { useFormContext, useWatch } from 'react-hook-form'; | import { useFormContext, useWatch } from 'react-hook-form'; | ||||||
| @@ -11,15 +12,18 @@ import AddIcon from '@mui/icons-material/Add'; | |||||||
| import useFormatMessage from 'hooks/useFormatMessage'; | import useFormatMessage from 'hooks/useFormatMessage'; | ||||||
| import InputCreator from 'components/InputCreator'; | import InputCreator from 'components/InputCreator'; | ||||||
| import { EditorContext } from 'contexts/Editor'; | import { EditorContext } from 'contexts/Editor'; | ||||||
|  |  | ||||||
| const createGroupItem = () => ({ | const createGroupItem = () => ({ | ||||||
|   key: '', |   key: '', | ||||||
|   operator: operators[0].value, |   operator: operators[0].value, | ||||||
|   value: '', |   value: '', | ||||||
|   id: uuidv4(), |   id: uuidv4(), | ||||||
| }); | }); | ||||||
|  |  | ||||||
| const createGroup = () => ({ | const createGroup = () => ({ | ||||||
|   and: [createGroupItem()], |   and: [createGroupItem()], | ||||||
| }); | }); | ||||||
|  |  | ||||||
| const operators = [ | const operators = [ | ||||||
|   { |   { | ||||||
|     label: 'Equal', |     label: 'Equal', | ||||||
| @@ -54,6 +58,7 @@ const operators = [ | |||||||
|     value: 'not_contains', |     value: 'not_contains', | ||||||
|   }, |   }, | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
| const createStringArgument = (argumentOptions) => { | const createStringArgument = (argumentOptions) => { | ||||||
|   return { |   return { | ||||||
|     ...argumentOptions, |     ...argumentOptions, | ||||||
| @@ -62,6 +67,7 @@ const createStringArgument = (argumentOptions) => { | |||||||
|     variables: true, |     variables: true, | ||||||
|   }; |   }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const createDropdownArgument = (argumentOptions) => { | const createDropdownArgument = (argumentOptions) => { | ||||||
|   return { |   return { | ||||||
|     ...argumentOptions, |     ...argumentOptions, | ||||||
| @@ -69,28 +75,35 @@ const createDropdownArgument = (argumentOptions) => { | |||||||
|     type: 'dropdown', |     type: 'dropdown', | ||||||
|   }; |   }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function FilterConditions(props) { | function FilterConditions(props) { | ||||||
|   const { stepId } = props; |   const { stepId } = props; | ||||||
|   const formatMessage = useFormatMessage(); |   const formatMessage = useFormatMessage(); | ||||||
|   const { control, setValue, getValues } = useFormContext(); |   const { control, setValue, getValues } = useFormContext(); | ||||||
|   const groups = useWatch({ control, name: 'parameters.or' }); |   const groups = useWatch({ control, name: 'parameters.or' }); | ||||||
|   const editorContext = React.useContext(EditorContext); |   const editorContext = React.useContext(EditorContext); | ||||||
|  |  | ||||||
|   React.useEffect(function addInitialGroupWhenEmpty() { |   React.useEffect(function addInitialGroupWhenEmpty() { | ||||||
|     const groups = getValues('parameters.or'); |     const groups = getValues('parameters.or'); | ||||||
|  |  | ||||||
|     if (!groups) { |     if (!groups) { | ||||||
|       setValue('parameters.or', [createGroup()]); |       setValue('parameters.or', [createGroup()]); | ||||||
|     } |     } | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
|   const appendGroup = React.useCallback(() => { |   const appendGroup = React.useCallback(() => { | ||||||
|     const values = getValues('parameters.or'); |     const values = getValues('parameters.or'); | ||||||
|     setValue('parameters.or', values.concat(createGroup())); |     setValue('parameters.or', values.concat(createGroup())); | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
|   const appendGroupItem = React.useCallback((index) => { |   const appendGroupItem = React.useCallback((index) => { | ||||||
|     const group = getValues(`parameters.or.${index}.and`); |     const group = getValues(`parameters.or.${index}.and`); | ||||||
|     setValue(`parameters.or.${index}.and`, group.concat(createGroupItem())); |     setValue(`parameters.or.${index}.and`, group.concat(createGroupItem())); | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
|   const removeGroupItem = React.useCallback((groupIndex, groupItemIndex) => { |   const removeGroupItem = React.useCallback((groupIndex, groupItemIndex) => { | ||||||
|     const group = getValues(`parameters.or.${groupIndex}.and`); |     const group = getValues(`parameters.or.${groupIndex}.and`); | ||||||
|  |  | ||||||
|     if (group.length === 1) { |     if (group.length === 1) { | ||||||
|       const groups = getValues('parameters.or'); |       const groups = getValues('parameters.or'); | ||||||
|       setValue( |       setValue( | ||||||
| @@ -104,6 +117,7 @@ function FilterConditions(props) { | |||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|   }, []); |   }, []); | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <React.Fragment> |     <React.Fragment> | ||||||
|       <Stack sx={{ width: '100%' }} direction="column" spacing={2} mt={2}> |       <Stack sx={{ width: '100%' }} direction="column" spacing={2} mt={2}> | ||||||
| @@ -219,4 +233,9 @@ function FilterConditions(props) { | |||||||
|     </React.Fragment> |     </React.Fragment> | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FilterConditions.propTypes = { | ||||||
|  |   stepId: PropTypes.string.isRequired, | ||||||
|  | }; | ||||||
|  |  | ||||||
| export default FilterConditions; | export default FilterConditions; | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | import PropTypes from 'prop-types'; | ||||||
| import * as React from 'react'; | import * as React from 'react'; | ||||||
| import { useFormContext } from 'react-hook-form'; | import { useFormContext } from 'react-hook-form'; | ||||||
| import Collapse from '@mui/material/Collapse'; | import Collapse from '@mui/material/Collapse'; | ||||||
| @@ -8,6 +9,8 @@ import { EditorContext } from 'contexts/Editor'; | |||||||
| import FlowSubstepTitle from 'components/FlowSubstepTitle'; | import FlowSubstepTitle from 'components/FlowSubstepTitle'; | ||||||
| import InputCreator from 'components/InputCreator'; | import InputCreator from 'components/InputCreator'; | ||||||
| import FilterConditions from './FilterConditions'; | import FilterConditions from './FilterConditions'; | ||||||
|  | import { StepPropType, SubstepPropType } from 'propTypes/propTypes'; | ||||||
|  |  | ||||||
| function FlowSubstep(props) { | function FlowSubstep(props) { | ||||||
|   const { |   const { | ||||||
|     substep, |     substep, | ||||||
| @@ -22,6 +25,7 @@ function FlowSubstep(props) { | |||||||
|   const formContext = useFormContext(); |   const formContext = useFormContext(); | ||||||
|   const validationStatus = formContext.formState.isValid; |   const validationStatus = formContext.formState.isValid; | ||||||
|   const onToggle = expanded ? onCollapse : onExpand; |   const onToggle = expanded ? onCollapse : onExpand; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <React.Fragment> |     <React.Fragment> | ||||||
|       <FlowSubstepTitle |       <FlowSubstepTitle | ||||||
| @@ -73,4 +77,14 @@ function FlowSubstep(props) { | |||||||
|     </React.Fragment> |     </React.Fragment> | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FlowSubstep.propTypes = { | ||||||
|  |   substep: SubstepPropType.isRequired, | ||||||
|  |   expanded: PropTypes.bool, | ||||||
|  |   onExpand: PropTypes.func.isRequired, | ||||||
|  |   onCollapse: PropTypes.func.isRequired, | ||||||
|  |   onSubmit: PropTypes.func.isRequired, | ||||||
|  |   step: StepPropType.isRequired, | ||||||
|  | }; | ||||||
|  |  | ||||||
| export default FlowSubstep; | export default FlowSubstep; | ||||||
|   | |||||||
| @@ -1,15 +1,20 @@ | |||||||
|  | import PropTypes from 'prop-types'; | ||||||
| import * as React from 'react'; | import * as React from 'react'; | ||||||
| import ExpandLessIcon from '@mui/icons-material/ExpandLess'; | import ExpandLessIcon from '@mui/icons-material/ExpandLess'; | ||||||
| import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||||||
| import ErrorIcon from '@mui/icons-material/Error'; | import ErrorIcon from '@mui/icons-material/Error'; | ||||||
| import CheckCircleIcon from '@mui/icons-material/CheckCircle'; | import CheckCircleIcon from '@mui/icons-material/CheckCircle'; | ||||||
| import { ListItemButton, Typography } from './style'; | import { ListItemButton, Typography } from './style'; | ||||||
|  |  | ||||||
| const validIcon = <CheckCircleIcon color="success" />; | const validIcon = <CheckCircleIcon color="success" />; | ||||||
|  |  | ||||||
| const errorIcon = <ErrorIcon color="error" />; | const errorIcon = <ErrorIcon color="error" />; | ||||||
|  |  | ||||||
| function FlowSubstepTitle(props) { | function FlowSubstepTitle(props) { | ||||||
|   const { expanded = false, onClick = () => null, valid = null, title } = props; |   const { expanded = false, onClick = () => null, valid = null, title } = props; | ||||||
|   const hasValidation = valid !== null; |   const hasValidation = valid !== null; | ||||||
|   const validationStatusIcon = valid ? validIcon : errorIcon; |   const validationStatusIcon = valid ? validIcon : errorIcon; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <ListItemButton onClick={onClick} selected={expanded} divider> |     <ListItemButton onClick={onClick} selected={expanded} divider> | ||||||
|       <Typography variant="body2"> |       <Typography variant="body2"> | ||||||
| @@ -21,4 +26,12 @@ function FlowSubstepTitle(props) { | |||||||
|     </ListItemButton> |     </ListItemButton> | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FlowSubstepTitle.propTypes = { | ||||||
|  |   expanded: PropTypes.bool, | ||||||
|  |   onClick: PropTypes.func.isRequired, | ||||||
|  |   valid: PropTypes.bool, | ||||||
|  |   title: PropTypes.string.isRequired, | ||||||
|  | }; | ||||||
|  |  | ||||||
| export default FlowSubstepTitle; | export default FlowSubstepTitle; | ||||||
|   | |||||||
| @@ -7,9 +7,11 @@ import { FORGOT_PASSWORD } from 'graphql/mutations/forgot-password.ee'; | |||||||
| import Form from 'components/Form'; | import Form from 'components/Form'; | ||||||
| import TextField from 'components/TextField'; | import TextField from 'components/TextField'; | ||||||
| import useFormatMessage from 'hooks/useFormatMessage'; | import useFormatMessage from 'hooks/useFormatMessage'; | ||||||
|  |  | ||||||
| export default function ForgotPasswordForm() { | export default function ForgotPasswordForm() { | ||||||
|   const formatMessage = useFormatMessage(); |   const formatMessage = useFormatMessage(); | ||||||
|   const [forgotPassword, { data, loading }] = useMutation(FORGOT_PASSWORD); |   const [forgotPassword, { data, loading }] = useMutation(FORGOT_PASSWORD); | ||||||
|  |  | ||||||
|   const handleSubmit = async (values) => { |   const handleSubmit = async (values) => { | ||||||
|     await forgotPassword({ |     await forgotPassword({ | ||||||
|       variables: { |       variables: { | ||||||
| @@ -17,6 +19,7 @@ export default function ForgotPasswordForm() { | |||||||
|       }, |       }, | ||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <Paper sx={{ px: 2, py: 4 }}> |     <Paper sx={{ px: 2, py: 4 }}> | ||||||
|       <Typography |       <Typography | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ali BARIN
					Ali BARIN