| | |
| | | ], |
| | | }; |
| | | |
| | | const getDefaultFormValues = (value = {}) => ({ |
| | | copyDirect: value.copyDirect || '', |
| | | copyCount: value.copyCount || '', |
| | | gap: 0.0, |
| | | autoIncrement: false, |
| | | incrementMode: 'ascending', |
| | | incrementValue: undefined, |
| | | }); |
| | | |
| | | const CopyDrawer = (props) => { |
| | | const { open, onCancel, sprite, value, width = PAGE_DRAWER_WIDTH, handleOnCopy } = props; |
| | | const notify = useNotification(); |
| | |
| | | const deviceType = sprite?.data?.type; |
| | | const incrementOptions = incrementOptionsMap[deviceType] |
| | | |
| | | const { control, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm({ |
| | | defaultValues: { |
| | | copyDirect: value?.copyDirect || '', |
| | | copyCount: value?.copyCount || '', |
| | | gap: 0.0, |
| | | autoIncrement: false, |
| | | incrementMode: 'ascending', |
| | | }, |
| | | const { control, handleSubmit, reset, watch, setValue } = useForm({ |
| | | defaultValues: getDefaultFormValues(value), |
| | | }); |
| | | |
| | | const autoIncrement = useWatch({ control, name: 'autoIncrement' }); |
| | | const incrementValue = useWatch({ control, name: 'incrementValue' }); |
| | | |
| | | useEffect(() => { |
| | | if (sprite && value && Object.keys(value).length > 0) { |
| | | reset(getDefaultFormValues(value)); |
| | | } |
| | | }, [sprite, value, reset, incrementOptions, setValue]); |
| | | |
| | | useEffect(() => { |
| | | if (autoIncrement && incrementOptions && incrementOptions.length > 0) { |
| | |
| | | setValue('incrementValue', undefined); |
| | | } |
| | | }, [autoIncrement, incrementOptions, setValue]); |
| | | |
| | | useEffect(() => { |
| | | if (sprite && value && Object.keys(value).length > 0) { |
| | | reset({ |
| | | copyDirect: value.copyDirect || '', |
| | | copyCount: value.copyCount || '', |
| | | gap: 0.0, |
| | | autoIncrement: false, |
| | | incrementMode: 'ascending', |
| | | incrementValue: undefined, |
| | | }); |
| | | } |
| | | }, [sprite, value, reset, incrementOptions, setValue]); |
| | | |
| | | const handleClose = () => { |
| | | onCancel(); |