|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const CopyDrawer = (props) => { | 
|---|
|  |  |  | const { open, onCancel, sprite, value, width = PAGE_DRAWER_WIDTH, handleOnCopy } = props; | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | open, | 
|---|
|  |  |  | onCancel, | 
|---|
|  |  |  | sprite, | 
|---|
|  |  |  | value, | 
|---|
|  |  |  | width = PAGE_DRAWER_WIDTH, | 
|---|
|  |  |  | handleOnCopy, | 
|---|
|  |  |  | setLastCopiedSprites, | 
|---|
|  |  |  | setSpriteSettings, | 
|---|
|  |  |  | } = props; | 
|---|
|  |  |  | const notify = useNotification(); | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const theme = useTheme(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const onFormSubmit = (data) => { | 
|---|
|  |  |  | console.log(data); | 
|---|
|  |  |  | if (!sprite || !data || Object.keys(data).length === 0) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { copyCount, copyDirect, gap, autoIncrement, incrementMode, incrementValue } = data; | 
|---|
|  |  |  | const copiedSprites = []; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const adjustPosition = (sprite, direction, gap, index) => { | 
|---|
|  |  |  | const factor = index + 1; | 
|---|
|  |  |  | switch (direction) { | 
|---|
|  |  |  | case 'left': | 
|---|
|  |  |  | sprite.position.x -= factor * (gap + sprite.width); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'right': | 
|---|
|  |  |  | sprite.position.x += factor * (gap + sprite.width); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'up': | 
|---|
|  |  |  | sprite.position.y -= factor * (gap + sprite.height); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'down': | 
|---|
|  |  |  | sprite.position.y += factor * (gap + sprite.height); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const incrementSpriteData = (copiedSprite, index) => { | 
|---|
|  |  |  | const incrementAmount = incrementMode === 'descending' ? -(index + 1) : index + 1; | 
|---|
|  |  |  | switch (deviceType) { | 
|---|
|  |  |  | case DEVICE_TYPE.SHELF: | 
|---|
|  |  |  | if (incrementValue === 'row') { | 
|---|
|  |  |  | copiedSprite.data.row = sprite.data.row + incrementAmount; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (incrementValue === 'bay') { | 
|---|
|  |  |  | copiedSprite.data.bay = sprite.data.bay + incrementAmount; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (copiedSprite.data.row && copiedSprite.data.bay) { | 
|---|
|  |  |  | copiedSprite.data.no = `${copiedSprite.data.row}-${copiedSprite.data.bay}`; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | if (incrementValue === 'no') { | 
|---|
|  |  |  | copiedSprite.data.no = Tool.incrementSpriteNo(sprite.data.no, incrementAmount); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (let i = 0; i < copyCount; i++) { | 
|---|
|  |  |  | const copiedSprite = Tool.copySprite(sprite); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | adjustPosition(copiedSprite, copyDirect, gap, i); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // auto-increment-value | 
|---|
|  |  |  | if (autoIncrement && deviceType) { | 
|---|
|  |  |  | incrementSpriteData(copiedSprite, i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Tool.getMapContainer().addChild(copiedSprite); | 
|---|
|  |  |  | Tool.beSettings(copiedSprite, setSpriteSettings); | 
|---|
|  |  |  | copiedSprites.push(copiedSprite); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | setLastCopiedSprites(copiedSprites); | 
|---|
|  |  |  | onCancel(); | 
|---|
|  |  |  | handleOnCopy?.(data); | 
|---|
|  |  |  | notify.info(translate('common.response.success')); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | 
|---|
|  |  |  | sx={{ width: '50%' }} | 
|---|
|  |  |  | fullWidth | 
|---|
|  |  |  | inputProps={{ | 
|---|
|  |  |  | min: 0, | 
|---|
|  |  |  | // min: 0, | 
|---|
|  |  |  | step: 1, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | onChange={(e) => { | 
|---|
|  |  |  | field.onChange(e.target.value === '' ? '' : Number(e.target.value)); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | /> | 
|---|