Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

"questionnaireRegionStatus": [ { "questionnaireId": 216, "regionCode": 1, "status":…

  1. User

    "questionnaireRegionStatus": [ { "questionnaireId": 216, "regionCode": 1, "status": "PENDING" }, { "questionnaireId": 216, "regionCode": 2, "status": "PENDING" }, { "questionnaireId": 216, "regionCode": 3, "status": "PENDING" }, { "questionnaireId": 216, "regionCode": 4, "status": "PENDING" }, the above is the a sample response for a user role director when fetching questionnaires. A director can doesnt have an associated regionCode but sees all other regions data. And below is the sample responce for a statstician who only see questionnaires associated with their region code "parentQuestionnaireId": 183, "updatedAt": "2023-06-07T11:49:13.092Z", "createdAt": "2023-06-07T11:49:13.083Z", "questionnaireRegionStatus": [ { "questionnaireId": 216, "regionCode": 2, "status": "PENDING" } ], now based on this i want to modify my render function so that it accomadates for both situations. Here are my render functions { title: "Status", dataIndex: "status", width: "15%", key: "status", render: (_, data) => { if (isUserDetailsSuccess) { const status = getQuestionnaireStatusData(data, userDetails.data.regionCode); return renderQuestionnaireStatus(status); } else { return renderQuestionnaireStatus('-'); }

      },
    },  const getQuestionnaireStatusData = (data, userRegionCode) => {
    let status = '';
    // console.log('data: ', data.questionnaireRegionStatus);
    if (data.questionnaireRegionStatus.length !== 0) {
      // console.log('questionnaireRegionStatus: ', data.questionnaireRegionStatus);
      // console.log('userDetails region: ', userDetails.data.regionCode);
    
      const qRegStatus = data.questionnaireRegionStatus.find(qRegStatus => qRegStatus?.regionCode === userRegionCode);
      if (qRegStatus !== undefined) {
        // console.log('qRegStatus: ', qRegStatus);
        status = qRegStatus.status;
      }
    
    }
    
    return status;
    

    } items={ [ { key: '1', label: 'View Cleaned', disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record, userDetails.data.regionCode) === "PENDING" || getQuestionnaireStatusData(record, userDetails.data.regionCode) === "INTERPOLATED") ? true : false, }, { key: '4', label: 'View Branch approved', }, { key: '2', label: 'Interpolate', // disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record, userDetails.data.regionCode) === "CLEANED" || getQuestionnaireStatusData(record, userDetails.data.regionCode) === "INTERPOLATED" || getQuestionnaireStatusData(record, userDetails.data.regionCode) === "COMPUTED") ? true : false, disabled: isUserDetailsSuccess && getQuestionnaireStatusData(record, userDetails.data.regionCode) !== 'PENDING' ? true : false, }, { key: '3', label: 'Create clean copy', disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record, userDetails.data.regionCode) !== "INTERPOLATED") ? true : false, } ] }

  2. Assistant

    To accommodate for both situations, you can add a check to see if the current user is a director or not and modify the render function accordingly. Here's an example of how you can do it:

    {
      title: "Status",
      dataIndex: "status",
      width: "15%",
      key: "status",
      render: (_, data) => {
        if (isUserDetailsSuccess) {
          if (userRole === "director") { // Check if user is a director
            const status = getQuestionnaireStatusData(data);
            return renderQuestionnaireStatus(status);
          } else { // Otherwise, assume user is a statistician with a region code
            const status = getQuestionnaireStatusData(data, userDetails.data.regionCode);
            return renderQuestionnaireStatus(status);
          }
        } else {
          return renderQuestionnaireStatus('-');
        }
      }
    }
    

    Notice how the getQuestionnaireStatusData function has been modified to take in just the data parameter for directors, whereas for statisticians with a region code, it takes in both data and userRegionCode parameters as before. The userRole variable is assumed to be set elsewhere in your code depending on the user's role.

    With this change, you can now render the items array without worrying about whether the user is a director or a statistician, as the getQuestionnaireStatusData function will handle both cases:

    items={[
      {
        key: '1',
        label: 'View Cleaned',
        disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record) === "PENDING" || getQuestionnaireStatusData(record) === "INTERPOLATED") ? true : false,
      },
      {
        key: '4',
        label: 'View Branch approved',
      },
      {
        key: '2',
        label: 'Interpolate',
        disabled: isUserDetailsSuccess && getQuestionnaireStatusData(record) !== 'PENDING' ? true : false,
      },
      {
        key: '3',
        label: 'Create clean copy',
        disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record) !== "INTERPOLATED") ? true : false,
      }
    ]}
    

    This assumes that the getQuestionnaireStatusData function returns the correct status for directors as well as statisticians with a region code. If this is not the case, you may need to modify the function further to handle both cases.

  3. User

    getQuestionnaireStatusData shouldnt return the same status for directors only statuses of data with INTERPOLATED CLEANED COMPUTED CPI_CALCULATED INFLATION_CALCULATED NATIONAL_CALCULATED PUBLISHED for all regions

  4. Assistant

    To modify the getQuestionnaireStatusData function to only return certain statuses for directors, you can add an additional check to see if the current user is a director, and modify the logic accordingly. Here's an example:

    const getQuestionnaireStatusData = (data, userRegionCode) => {
      let status = '';
      
      if (data.questionnaireRegionStatus.length !== 0) {
        // Check if user is a director
        if (userRole === 'director') {
          // Find the minimum status for all regions
          const minStatus = Math.min(...data.questionnaireRegionStatus.map(qrs => qrs.status_value));
          
          switch (minStatus) {
            case 1:
              status = 'INTERPOLATED';
              break;
            case 2:
              status = 'CLEANED';
              break;
            case 3:
              status = 'COMPUTED';
              break;
            case 4:
              status = 'CPI_CALCULATED';
              break;
            case 5:
              status = 'INFLATION_CALCULATED';
              break;
            case 6:
              status = 'NATIONAL_CALCULATED';
              break;
            case 7:
              status = 'PUBLISHED';
              break;
            default:
              status = '';
          }
        } else {
          // Find the status for the current user's region
          const qRegStatus = data.questionnaireRegionStatus.find(qrs => qrs.regionCode === userRegionCode);
          if (qRegStatus !== undefined) {
            status = qRegStatus.status;
          }
        }
      }
    
      return status;
    };
    

    In this modified function, if the current user is a director, the function finds the minimum status for all regions from the questionnaireRegionStatus array, and sets the status variable to one of the selected statuses (INTERPOLATED, CLEANED, etc.) based on the minimum value. If the current user is not a director, the function finds the status for the current user's region as before.

    With this modification, the render function can remain the same as before:

    render: (_, data) => {
      if (isUserDetailsSuccess) {
        if (userRole === "director") {
          const status = getQuestionnaireStatusData(data);
          return renderQuestionnaireStatus(status);
        } else {
          const status = getQuestionnaireStatusData(data, userDetails.data.regionCode);
          return renderQuestionnaireStatus(status);
        }
      } else {
        return renderQuestionnaireStatus('-');
      }
    }
    

    And the items array can be modified to reflect the new statuses:

    items={[
      {
        key: '1',
        label: 'View Cleaned',
        disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record) === "PENDING" || getQuestionnaireStatusData(record) === "INTERPOLATED") ? true : false,
      },
      {
        key: '4',
        label: 'View Branch approved',
      },
      {
        key: '2',
        label: 'Interpolate',
        disabled: isUserDetailsSuccess && getQuestionnaireStatusData(record) !== 'INTERPOLATED' ? true : false,
      },
      {
        key: '3',
        label: 'Create clean copy',
        disabled: isUserDetailsSuccess && (getQuestionnaireStatusData(record) !== "CLEANED" && getQuestionnaireStatusData(record) !== "INTERPOLATED") ? true : false,
      }
    ]}
    

    Note that the items array now checks for the updated status values.