“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,
}
]
}