Skip to content

Commit

Permalink
MOSIP:37899 - APi review comment changes (#1056)
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Dec 20, 2024
1 parent e615f30 commit 6da76a7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getUserProfile } from '../../../services/UserProfileService';
import {
getPartnerManagerUrl, handleServiceErrors, getPartnerTypeDescription, createRequest,
moveToOidcClientsList, getGrantTypes, getApprovedAuthPartners,
isLangRTL, createDropdownData, validateUrl, getAuthPartnerPolicies,
isLangRTL, createDropdownData, validateUrl, getPartnerPolicyRequests,
onPressEnterKey, trimAndReplace
} from '../../../utils/AppUtils';
import { HttpService } from '../../../services/HttpService';
Expand Down Expand Up @@ -36,7 +36,8 @@ function CreateOidcClient() {
const [partnerType, setPartnerType] = useState("");
const [policyGroupName, setPolicyGroupName] = useState("");
const [partnerData, setPartnerData] = useState([]);
const [policiesData, setPoliciesData] = useState([]);
const [activePoliciesData, setActivePoliciesData] = useState([]);
const [policyRequestsData, setPolicyRequestsData] = useState([]);
const [redirectUrls, setRedirectUrls] = useState(['']);
const [grantTypes, setGrantTypes] = useState("authorization_code");
const [grantTypesList, setGrantTypesList] = useState(['']);
Expand Down Expand Up @@ -161,6 +162,23 @@ function CreateOidcClient() {
setDataLoaded(true);
}
};
const fetchPolicyRequestsData = async () => {
try {
setDataLoaded(false);
const resData = await getPartnerPolicyRequests(HttpService, setErrorCode, setErrorMsg, t);
if (resData) {
setPolicyRequestsData(resData);
} else {
setErrorMsg(t('commons.errorInResponse'));
}
} catch (err) {
console.error('Error fetching data:', err);
} finally {
setDataLoaded(true);
}
};

fetchPolicyRequestsData();
fetchData();
}, []);

Expand All @@ -169,23 +187,22 @@ function CreateOidcClient() {
setPolicyName("");
setPolicyGroupName("");
setPoliciesDropdownData([]);
setPoliciesData([]);
setPartnerType("");
// Find the selected partner data
const selectedPartner = partnerData.find(item => item.partnerId === selectedValue);
if (selectedPartner) {
const resData = await getAuthPartnerPolicies(selectedValue, HttpService, setErrorCode, setErrorMsg, t);
if (resData) {
setPoliciesData(resData);
setPartnerType(getPartnerTypeDescription("AUTH_PARTNER", t));
setPolicyGroupName(selectedPartner.policyGroupName);
setPoliciesDropdownData(createDropdownData('policyName', 'policyDescription', false, resData, t));
}
const activePolicies = policyRequestsData.filter(
item => item.partnerId === selectedValue && item.status === 'approved'
);
setActivePoliciesData(activePolicies);
setPartnerType(getPartnerTypeDescription("AUTH_PARTNER", t));
setPolicyGroupName(selectedPartner.policyGroupName);
setPoliciesDropdownData(createDropdownData('policyName', 'policyDescription', false, activePolicies, t));
}
};

const onChangePolicyName = (fieldName, selectedValue) => {
const selectedPolicy = policiesData.find(item => item.policyName === selectedValue);
const selectedPolicy = activePoliciesData.find(item => item.policyName === selectedValue);
if (selectedPolicy) {
setPolicyName(selectedValue);
setPolicyId(selectedPolicy.policyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LoadingIcon from "../../common/LoadingIcon";
import ErrorMessage from "../../common/ErrorMessage";
import {
getPartnerManagerUrl, handleServiceErrors, getPartnerTypeDescription, isLangRTL, moveToApiKeysList,
createRequest, getAuthPartnerPolicies, createDropdownData, trimAndReplace, getApprovedAuthPartners
createRequest, getPartnerPolicyRequests, createDropdownData, trimAndReplace, getApprovedAuthPartners
} from "../../../utils/AppUtils";
import { HttpService } from '../../../services/HttpService';
import DropdownWithSearchComponent from "../../common/fields/DropdownWithSearchComponent";
Expand All @@ -23,6 +23,7 @@ function GenerateApiKey() {
const [errorCode, setErrorCode] = useState("");
const [errorMsg, setErrorMsg] = useState("");
const [partnerData, setPartnerData] = useState([]);
const [policyRequestsData, setPolicyRequestsData] = useState([]);
const [showPopup, setShowPopup] = useState(false);
const [partnerIdDropdownData, setPartnerIdDropdownData] = useState([]);
const [policiesDropdownData, setPoliciesDropdownData] = useState([]);
Expand Down Expand Up @@ -88,12 +89,12 @@ function GenerateApiKey() {
// Find the selected partner data
const selectedPartner = partnerData.find(item => item.partnerId === selectedValue);
if (selectedPartner) {
const resData = await getAuthPartnerPolicies(selectedValue, HttpService, setErrorCode, setErrorMsg, t);
if (resData) {
setPartnerType(getPartnerTypeDescription("AUTH_PARTNER", t));
setPolicyGroupName(selectedPartner.policyGroupName);
setPoliciesDropdownData(createDropdownData('policyName', 'policyDescription', false, resData, t));
}
const activePolicies = policyRequestsData.filter(
item => item.partnerId === selectedValue && item.status === 'approved'
);
setPartnerType(getPartnerTypeDescription("AUTH_PARTNER", t));
setPolicyGroupName(selectedPartner.policyGroupName);
setPoliciesDropdownData(createDropdownData('policyName', 'policyDescription', false, activePolicies, t));
}
};

Expand Down Expand Up @@ -122,6 +123,23 @@ function GenerateApiKey() {
setDataLoaded(true);
}
};
const fetchPolicyRequestsData = async () => {
try {
setDataLoaded(false);
const resData = await getPartnerPolicyRequests(HttpService, setErrorCode, setErrorMsg, t);
if (resData) {
setPolicyRequestsData(resData);
} else {
setErrorMsg(t('commons.errorInResponse'));
}
} catch (err) {
console.error('Error fetching data:', err);
} finally {
setDataLoaded(true);
}
};

fetchPolicyRequestsData();
fetchData();
}, []);

Expand Down
14 changes: 4 additions & 10 deletions pmp-revamp-ui/src/pages/partner/policies/PoliciesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useTranslation } from 'react-i18next';
import { getUserProfile } from '../../../services/UserProfileService';
import { isLangRTL, onPressEnterKey } from '../../../utils/AppUtils';
import {
getPartnerManagerUrl, formatDate, handleServiceErrors, getPartnerTypeDescription, getStatusCode, handleMouseClickForDropdown,
toggleSortAscOrder, toggleSortDescOrder, bgOfStatus
formatDate, getPartnerTypeDescription, getStatusCode, handleMouseClickForDropdown,
toggleSortAscOrder, toggleSortDescOrder, bgOfStatus, getPartnerPolicyRequests
} from '../../../utils/AppUtils';
import { HttpService } from '../../../services/HttpService';
import PoliciesFilter from './PoliciesFilter';
Expand Down Expand Up @@ -60,17 +60,11 @@ function PoliciesList() {
const fetchData = async () => {
try {
setDataLoaded(false);
const response = await HttpService.get(getPartnerManagerUrl('/partners/policy-requests', process.env.NODE_ENV));
const response = await getPartnerPolicyRequests(HttpService, setErrorCode, setErrorMsg, t);
if (response) {
const responseData = response.data;
if (responseData && responseData.response) {
const resData = responseData.response;
const sortedData = resData.sort((a, b) => new Date(b.createdDateTime) - new Date(a.createdDateTime));
const sortedData = response.sort((a, b) => new Date(b.createdDateTime) - new Date(a.createdDateTime));
setPoliciesList(sortedData);
setFilteredPoliciesList(sortedData);
} else {
handleServiceErrors(responseData, setErrorCode, setErrorMsg);
}
} else {
setErrorMsg(t('policies.errorInPoliciesList'));
}
Expand Down
6 changes: 3 additions & 3 deletions pmp-revamp-ui/src/utils/AppUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ export const createDropdownData = (fieldName, fieldDesc, isBlankEntryRequired, d
return dataArr;
}

export const getAuthPartnerPolicies = async (partnerId, HttpService, setErrorCode, setErrorMsg, t) => {
export const getPartnerPolicyRequests = async (HttpService, setErrorCode, setErrorMsg, t) => {
try {
const response = await HttpService.get(getPartnerManagerUrl(`/partners/${partnerId}/policies`, process.env.NODE_ENV));
const response = await HttpService.get(getPartnerManagerUrl(`/partners/policy-requests`, process.env.NODE_ENV));
if (response && response.data) {
const responseData = response.data;
if (responseData.response) {
Expand All @@ -362,7 +362,7 @@ export const getAuthPartnerPolicies = async (partnerId, HttpService, setErrorCod
return null;
}
} catch (error) {
console.error('Error in getAuthPartnerPolicies:', error);
console.error('Error in getPartnerPolicyRequests:', error);
return null;
}
};
Expand Down

0 comments on commit 6da76a7

Please sign in to comment.