tempsave 수정본

삼겹살·2023년 8월 4일

  //임시저장 상태
  const [tempSaved, setTempSaved] = React.useState([]);
  
//임시저장버튼
  const btnTempSaveClickHandler = async (e) => {
    try {
      //선택된 ROWS
      const selectedRowDatas = materialMoveLineGrid.current.instance.getSelectedRowsData();
      // 임시저장 조건 1. ROW를 하나도 선택하지 않고 임시저장 버튼을 눌렀을시, ERROR 메시지 출력
      if(selectedRowDatas.length == 0){
        notify('선택된 행이 존재하지 않습니다', 'error', 3000);
        return;
      }
      // 임시저장 조건 2. Destlocationid 또는 TransferDescription에 입력값이 없을시 Error 출력 
      for(var row of selectedRowDatas){
        if(row.destlocationid == "" || row.transferdescription == ""){
          notify('필수 입력값이 비어있습니다.', 'error', 3000)
          setTempSaved((tmp)=>[...tmp, 'error'])
          console.log(tempSaved)
          return;
        }
        // 임시저장 조건 3. Destlocationid가 Sourcelocation과 일치한다면 Error
        if(row.destlocationid == row.sourcelocationid){
          notify('반출위치가 반입위치와 동일합니다.', 'error', 3000)
          setTempSaved((tmp)=>[...tmp, 'error'])
          console.log(tempSaved)
          return;
        }
        // 임시저장 조건 4. destlocationid(입력값)이 GetDestLocationList(쿼리)에 존재하지 않는 destlocationid면 Error 출력
        if(row.destlocationid){
          const param ={
            destlocationid: row.destlocationid
          }
          const reqMsg = {
            Header: {
              MessageCategory: 'QueryService',
              MessageName: 'ExecuteDataTable',
              FactoryID: loginUser.factoryId,
              Language: loginUser.languageId ?? 'ko',
              SendUser: loginUser.userId,
            },
            Body: {
              STOREDQUERYCLASSID: 'POM-WEB',
              STOREDQUERYID: 'GetCheckedDestLocationId',
              STOREDQUERYVERSION: '001',
              PARAMETERS: param,
            },
          }
          const result = await getQueryResult(reqMsg);
          if( !result || result.length == 0){
            notify('변경할 반출위치 기준정보가 존재하지 않습니다', 'error', 3000);
            setTempSaved((tmp)=>[...tmp, 'error'])
            console.log(tempSaved);
            return;
          }
        }
        setTempSaved((tmp)=>[...tmp, 'ok'])
        console.log(tempSaved)
        return;
      }
    } catch (err) {
      console.error(err);
    }
  };

문제1.
useState의 비동기문제..
첫번째 tempSave 버튼을 눌렀을떄, 결과값이 error라면 두번째 버튼 눌렀을떄 결과값이 ok 여야함에도 불구하고 error를 반환하고 세번째 부터 이전값인 ok를 반환한다. 즉 한번 밀려서 반환한다.

문제2.
문제는 내가 1,2,3번 Row를 임시저장한 후에 row selection을 변경하면? 예를들어 임시저장한건 1,2,3번 row이지만 임시저장값 ok를 부여받고난 다음 row selection 체크해제하고 4,5번 row를 체크하고 저장버튼을 누른다면?

profile
PorkbellyWeb

1개의 댓글

comment-user-thumbnail
2023년 8월 4일

많은 것을 배웠습니다, 감사합니다.

답글 달기