Recipient Eligibility Validation for custom screen

The ineligibleContributionRecipientAlert function verifies whether a selected recipient (either a charity or project) is eligible to receive contributions based on its status. It alerts the user if the recipient is ineligible and invalid contributions are blocked.

Purpose: This function validates the status of the recipient, identified by selectedField, and notifies the user if the recipient is ineligible. It helps enforce eligibility rules for contributions.

fundNumberRecord: Contains recipient details, such as charityStatus, projectStatus, and their corresponding labels.

selectedField: Determines whether the recipient is a charity or a project, with possible values like ‘donatedtocharity’ or ‘donatedtoproject’.

isCharityStatusIneligible and isProjectStatusIneligible: Check if the recipient’s status falls under predefined ineligible conditions.

function ineligibleContributionRecipientAlert(fundNumberRecord, selectedField) {


            let entity;
            let is_ineligible = false;


            console.log("selectedField", selectedField)


            let isCharityStatusIneligible = GLOBAL_DATA_OBJECT.INELIGIBLE_CHARITY_STATUS.includes(Number(fundNumberRecord.charityStatus));
            let isProjectStatusIneligible = PROJECT_PAUSED.includes(Number(fundNumberRecord.projectStatus))


            if (['donatedtocharity', 'donatedtofundnumber_charity'].includes(selectedField)) {
                if (!checkForParameter(fundNumberRecord.charityStatus)) {
                    return false;
                }
                entity = 'charity';
                if (isCharityStatusIneligible) {
                    is_ineligible = true;
                    alert(`The Receiving Charity is ${fundNumberRecord.charityStatusLabel}. Please do the necessary action.`);
                }
            } else if (['donatedtoproject', 'donatedtofundnumber_project'].includes(selectedField)) {


                if (!checkForParameter(fundNumberRecord.projectStatus)) {
                    return false;
                }
                entity = 'project';
                if (isProjectStatusIneligible) {
                    is_ineligible = true;
                    alert(`The Receiving Project is ${fundNumberRecord.projectStatusLabel}. Please do the necessary action.`);
                } else if (isCharityStatusIneligible) {
                    is_ineligible = true;
                    alert(`The Receiving Charity is ${fundNumberRecord.projectCharityStatusLabel}. Please do the necessary action.`);
                }
            }


             // This formState is used to save the eligibility status of a Recipient in order to block the save action of a contribution
             formState["contribution"] = {
                receiver: {
                    entity,
                    is_ineligible,
                    fundNumberRecord
                },
                sender: formState["contribution"].sender
            };
            console.log('FormState Updated', formState);
        }

Leave a comment

Your email address will not be published. Required fields are marked *