| | |
| | | import React, { useEffect } from 'react'; |
| | | import { useForm, Controller } from 'react-hook-form'; |
| | | import { useForm, useWatch, Controller } from 'react-hook-form'; |
| | | import { |
| | | Box, |
| | | Grid, |
| | |
| | | Divider, |
| | | Drawer, |
| | | IconButton, |
| | | LinearProgress, |
| | | Switch, |
| | | FormControlLabel, |
| | | FormLabel, |
| | |
| | | }, |
| | | }); |
| | | |
| | | const autoIncrement = useWatch({ control, name: 'autoIncrement' }); |
| | | const incrementValue = useWatch({ control, name: 'incrementValue' }); |
| | | |
| | | useEffect(() => { |
| | | if (watch('autoIncrement') && incrementOptions && incrementOptions.length > 0) { |
| | | const currentIncrementValue = watch('incrementValue'); |
| | | if (!currentIncrementValue) { |
| | | if (autoIncrement && incrementOptions && incrementOptions.length > 0) { |
| | | if (!incrementValue) { |
| | | setValue('incrementValue', incrementOptions[0].value); |
| | | } |
| | | } else { |
| | | setValue('incrementValue', undefined); |
| | | } |
| | | }, [watch('autoIncrement'), incrementOptions, setValue, watch]); |
| | | }, [autoIncrement, incrementOptions, setValue]); |
| | | |
| | | useEffect(() => { |
| | | if (sprite && value && Object.keys(value).length > 0) { |
| | |
| | | const onFormSubmit = (data) => { |
| | | if (data) { |
| | | console.log(data); |
| | | |
| | | } |
| | | if (handleOnCopy) { |
| | | handleOnCopy(data); |
| | |
| | | /> |
| | | </Grid> |
| | | |
| | | {(!!incrementOptions?.length && watch('autoIncrement')) && ( |
| | | {(!!incrementOptions?.length && autoIncrement) && ( |
| | | <Grid item xs={12}> |
| | | <FormControl fullWidth> |
| | | <FormLabel sx={{ mb: 1 }}> |
| | |
| | | </Grid> |
| | | )} |
| | | |
| | | {watch('autoIncrement') && ( |
| | | {autoIncrement && ( |
| | | <Grid item xs={12}> |
| | | <FormControl fullWidth> |
| | | <FormLabel sx={{ |