|  |  |  | 
|---|
|  |  |  | import React from 'react'; | 
|---|
|  |  |  | import React, { useEffect } from 'react'; | 
|---|
|  |  |  | import { useTranslate } from "react-admin"; | 
|---|
|  |  |  | import { useForm, Controller } from 'react-hook-form'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | 
|---|
|  |  |  | const theme = useTheme(); | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { control, handleSubmit, reset, watch } = useForm({ | 
|---|
|  |  |  | const { control, handleSubmit, reset, watch, setValue } = useForm({ | 
|---|
|  |  |  | defaultValues: { | 
|---|
|  |  |  | taskMode: 'MOVE', | 
|---|
|  |  |  | startCode: '', | 
|---|
|  |  |  | 
|---|
|  |  |  | { value: 'STA_TO_STA', label: translate('page.map.insight.control.type.STA_TO_STA') }, | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | reset(); | 
|---|
|  |  |  | }, [curAgvNo, reset]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const onSubmit = (data) => { | 
|---|
|  |  |  | if (curAgvNo) { | 
|---|
|  |  |  | console.log(data); | 
|---|
|  |  |  | handleControlAgv(curAgvNo, data); | 
|---|
|  |  |  | handleControlAgv({ agvNo: curAgvNo, ...data }, () => { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | options: endCodeOptions, | 
|---|
|  |  |  | setInputValue: setEndCodeInputValue, | 
|---|
|  |  |  | resetInput: resetEndCodeInput, | 
|---|
|  |  |  | } = useCoolHook('/code/page', 'data'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | options: startLocOptions, | 
|---|
|  |  |  | setInputValue: setStartLocInputValue, | 
|---|
|  |  |  | resetInput: resetStartLocInput, | 
|---|
|  |  |  | } = useCoolHook('/loc/page', 'locNo'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | options: endLocOptions, | 
|---|
|  |  |  | setInputValue: setEndLocInputValue, | 
|---|
|  |  |  | resetInput: resetEndLocInput, | 
|---|
|  |  |  | } = useCoolHook('/loc/page', 'locNo'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | options: startStaOptions, | 
|---|
|  |  |  | setInputValue: setStartStaInputValue, | 
|---|
|  |  |  | resetInput: resetStartStaInput, | 
|---|
|  |  |  | } = useCoolHook('/sta/page', 'staNo'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { | 
|---|
|  |  |  | options: endStaOptions, | 
|---|
|  |  |  | setInputValue: setEndStaInputValue, | 
|---|
|  |  |  | resetInput: resetEndStaInput, | 
|---|
|  |  |  | } = useCoolHook('/sta/page', 'staNo'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | const fieldsToClear = ['endCode', 'startLocNo', 'endLocNo', 'startStaNo', 'endStaNo']; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | fieldsToClear.forEach(field => { | 
|---|
|  |  |  | if (!showField(field)) { | 
|---|
|  |  |  | setValue(field, ''); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (field) { | 
|---|
|  |  |  | case 'endCode': | 
|---|
|  |  |  | resetEndCodeInput(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'startLocNo': | 
|---|
|  |  |  | resetStartLocInput(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'endLocNo': | 
|---|
|  |  |  | resetEndLocInput(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'startStaNo': | 
|---|
|  |  |  | resetStartStaInput(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'endStaNo': | 
|---|
|  |  |  | resetEndStaInput(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }, [ | 
|---|
|  |  |  | taskMode, | 
|---|
|  |  |  | setValue, | 
|---|
|  |  |  | showField, | 
|---|
|  |  |  | resetEndCodeInput, | 
|---|
|  |  |  | resetStartLocInput, | 
|---|
|  |  |  | resetEndLocInput, | 
|---|
|  |  |  | resetStartStaInput, | 
|---|
|  |  |  | resetEndStaInput | 
|---|
|  |  |  | ]); | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <form onSubmit={handleSubmit(onSubmit)}> | 
|---|