@campxdev/shared 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -17,9 +17,9 @@ interface FormProps extends Omit<RenderFormProps, 'control'> {
17
17
  previousData?: any
18
18
  onCancel?: () => void
19
19
  postFunction: (body: any) => Promise<AxiosResponse>
20
- onPostSuccess: (response: any) => void
21
- onPostError: (error: any) => void
22
- onFormError: (error: any) => void
20
+ onPostSuccess?: (response: any) => void
21
+ onPostError?: (error: any) => void
22
+ onFormError?: (error: any) => void
23
23
  }
24
24
 
25
25
  export default function Form({
@@ -43,7 +43,11 @@ export default function Form({
43
43
  const [error, setError] = useState<any>(null)
44
44
  const { control, watch, handleSubmit } = useForm({
45
45
  defaultValues: previousData ? previousData : null,
46
- resolver: yupResolver(generateYupSchema([fields])),
46
+ resolver: yupResolver(
47
+ generateYupSchema({
48
+ fieldGroups: fields as any,
49
+ }),
50
+ ),
47
51
  })
48
52
 
49
53
  const { mutate, isLoading: posting } = useMutation(postFunction, {
@@ -9,11 +9,12 @@ import {
9
9
  FormTextField,
10
10
  } from '../HookForm'
11
11
 
12
- export const generateYupSchema = (
13
- normalFieldGroups: any[][],
14
- fieldArrayGroups?: any[],
15
- ) => {
16
- const flatArray = normalFieldGroups.flat()
12
+ export const generateYupSchema = (options: {
13
+ fieldGroups: any[][]
14
+ fieldArrayGroups?: any[]
15
+ extraValidations?: any
16
+ }) => {
17
+ const flatArray = options.fieldGroups.flat()
17
18
 
18
19
  const validations = flatArray
19
20
  ?.filter(
@@ -28,7 +29,7 @@ export const generateYupSchema = (
28
29
  }
29
30
  }, {})
30
31
 
31
- return yup.object().shape(validations)
32
+ return yup.object().shape({ ...validations, ...options.extraValidations })
32
33
  }
33
34
 
34
35
  type FormTypes =