| | |
| | | ], |
| | | }; |
| | | |
| | | |
| | | const validateIncrement = (value, deviceType, sprite, translate) => { |
| | | if (!value) { |
| | | return true; |
| | | } |
| | | switch (deviceType) { |
| | | case DEVICE_TYPE.SHELF: |
| | | if (!sprite?.data?.row || !sprite?.data?.bay) { |
| | | return translate('page.map.settings.map.copy.valid.shelf'); |
| | | } |
| | | break; |
| | | default: |
| | | if (!sprite?.data?.no) { |
| | | return translate('page.map.settings.map.copy.valid.common'); |
| | | } |
| | | break; |
| | | } |
| | | return true; |
| | | }; |
| | | |
| | | 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 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', |
| | | }, |
| | | 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) { |
| | |
| | | } |
| | | }, [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(); |
| | | } |
| | | |
| | | const onFormSubmit = (data) => { |
| | | if (data) { |
| | | console.log(data); |
| | | } |
| | | if (handleOnCopy) { |
| | | handleOnCopy(data); |
| | | } |
| | | console.log(data); |
| | | handleOnCopy?.(data); |
| | | notify.info(translate('common.response.success')); |
| | | }; |
| | | |
| | |
| | | <Controller |
| | | name="autoIncrement" |
| | | control={control} |
| | | rules={{ validate: (value) => validateIncrement(value, deviceType, sprite, translate) }} |
| | | render={({ field }) => ( |
| | | <FormControlLabel |
| | | control={ |
| | |
| | | /> |
| | | )} |
| | | /> |
| | | {errors.autoIncrement && ( |
| | | <Typography color="error"> |
| | | {errors.autoIncrement.message} |
| | | </Typography> |
| | | )} |
| | | </Grid> |
| | | |
| | | {(!!incrementOptions?.length && autoIncrement) && ( |
| | |
| | | value={field.value} |
| | | exclusive |
| | | onChange={(event, value) => { |
| | | field.onChange(value); |
| | | if (value !== null) { |
| | | field.onChange(value); |
| | | } |
| | | }} |
| | | fullWidth |
| | | > |
| | |
| | | value={field.value} |
| | | exclusive |
| | | onChange={(event, value) => { |
| | | field.onChange(value); |
| | | if (value !== null) { |
| | | field.onChange(value); |
| | | } |
| | | }} |
| | | fullWidth |
| | | > |