|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 = ['startCode', 'endCode', 'startLocNo', 'endLocNo', 'startStaNo', 'endStaNo']; | 
|---|
|  |  |  | 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]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }, [ | 
|---|
|  |  |  | taskMode, | 
|---|
|  |  |  | setValue, | 
|---|
|  |  |  | showField, | 
|---|
|  |  |  | resetEndCodeInput, | 
|---|
|  |  |  | resetStartLocInput, | 
|---|
|  |  |  | resetEndLocInput, | 
|---|
|  |  |  | resetStartStaInput, | 
|---|
|  |  |  | resetEndStaInput | 
|---|
|  |  |  | ]); | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <form onSubmit={handleSubmit(onSubmit)}> | 
|---|
|  |  |  | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | {showField('endLocNo') && ( | 
|---|
|  |  |  | <Grid item xs={12}> | 
|---|
|  |  |  | <Controller | 
|---|
|  |  |  | name="endLocNo" | 
|---|
|  |  |  | control={control} | 
|---|
|  |  |  | rules={{ required: translate('ra.validation.required') }} | 
|---|
|  |  |  | render={({ field, fieldState }) => { | 
|---|
|  |  |  | const selectedOption = endLocOptions.find(option => option.id === field.value) || null; | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Autocomplete | 
|---|
|  |  |  | options={endLocOptions} | 
|---|
|  |  |  | getOptionLabel={(option) => option.label} | 
|---|
|  |  |  | isOptionEqualToValue={(option, value) => option.id === value.id} | 
|---|
|  |  |  | value={selectedOption} | 
|---|
|  |  |  | onInputChange={(event, value) => { | 
|---|
|  |  |  | setEndLocInputValue(value); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | onChange={(event, value) => { | 
|---|
|  |  |  | field.onChange(value ? value.id : null); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | renderInput={(params) => ( | 
|---|
|  |  |  | <TextField | 
|---|
|  |  |  | {...params} | 
|---|
|  |  |  | label={translate('page.map.insight.control.endLoc')} | 
|---|
|  |  |  | error={!!fieldState.error} | 
|---|
|  |  |  | helperText={fieldState.error?.message} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | {showField('startStaNo') && ( | 
|---|
|  |  |  | <Grid item xs={12}> | 
|---|
|  |  |  | <Controller | 
|---|
|  |  |  | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | {showField('endLocNo') && ( | 
|---|
|  |  |  | <Grid item xs={12}> | 
|---|
|  |  |  | <Controller | 
|---|
|  |  |  | name="endLocNo" | 
|---|
|  |  |  | control={control} | 
|---|
|  |  |  | rules={{ required: translate('ra.validation.required') }} | 
|---|
|  |  |  | render={({ field, fieldState }) => { | 
|---|
|  |  |  | const selectedOption = endLocOptions.find(option => option.id === field.value) || null; | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Autocomplete | 
|---|
|  |  |  | options={endLocOptions} | 
|---|
|  |  |  | getOptionLabel={(option) => option.label} | 
|---|
|  |  |  | isOptionEqualToValue={(option, value) => option.id === value.id} | 
|---|
|  |  |  | value={selectedOption} | 
|---|
|  |  |  | onInputChange={(event, value) => { | 
|---|
|  |  |  | setEndLocInputValue(value); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | onChange={(event, value) => { | 
|---|
|  |  |  | field.onChange(value ? value.id : null); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | renderInput={(params) => ( | 
|---|
|  |  |  | <TextField | 
|---|
|  |  |  | {...params} | 
|---|
|  |  |  | label={translate('page.map.insight.control.endLoc')} | 
|---|
|  |  |  | error={!!fieldState.error} | 
|---|
|  |  |  | helperText={fieldState.error?.message} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | {showField('endStaNo') && ( | 
|---|
|  |  |  | <Grid item xs={12}> | 
|---|
|  |  |  | <Controller | 
|---|