diff --git a/pmp-reactjs-ui/public/i18n/ara.json b/pmp-reactjs-ui/public/i18n/ara.json index 70647a1a..06b2a03a 100644 --- a/pmp-reactjs-ui/public/i18n/ara.json +++ b/pmp-reactjs-ui/public/i18n/ara.json @@ -651,7 +651,10 @@ "policyData": "بيانات السياسة (json فقط)", "policyDataDesc": "لصق الكود أو تحميل الملف", "upload": "رفع", - "remove": "يزيل" + "remove": "يزيل", + "CreatePolicySuccessHeader":"تم إنشاء السياسة بنجاح!", + "uploadFileError": "حدث خطأ غير متوقع أثناء تحميل الملف. يرجى المحاولة مرة أخرى.", + "jsonParseError": "يرجى تقديم بيانات JSON صالحة" }, "consentPopup": { "title": "الأحكام والشروط", @@ -779,7 +782,7 @@ "PMS_POL_006": "نوع المصادقة غير المدعوم في ملف النهج", "PMS_POL_007": "سمة eKYC مفقودة في ملف السياسة", "PMS_POL_008": "معرف السياسة غير موجود", - "PMS_POL_009": "توجد سياسة المصادقة بالاسم:", + "PMS_POL_009": "توجد سياسة بهذا الاسم بالفعل", "PMS_COR_002": "معلمة إدخال غير صالحة -", "PMS_COR_003": "لا يمكن معالجة الطلب", "PMS_POL_010": "لم يتم تحديد سياسات المصادقة مقابل السياسة", diff --git a/pmp-reactjs-ui/public/i18n/eng.json b/pmp-reactjs-ui/public/i18n/eng.json index 0fb6874d..2246569c 100644 --- a/pmp-reactjs-ui/public/i18n/eng.json +++ b/pmp-reactjs-ui/public/i18n/eng.json @@ -647,7 +647,10 @@ "policyData": "Policy Data(only json)", "policyDataDesc": "Paste code or upload a file", "upload": "Upload", - "remove": "Remove" + "remove": "Remove", + "CreatePolicySuccessHeader":"Policy Created Successfully!", + "uploadFileError": "There was an unexpected error during the file upload. Please try again.", + "jsonParseError": "Please provide valid JSON data" }, "consentPopup": { "title": "Terms and Conditions", @@ -776,7 +779,7 @@ "PMS_POL_006": "Unsupported Authentication Type in the Policy File", "PMS_POL_007": "eKYC attribute missing in the policy file", "PMS_POL_008": "Policy ID does not exist", - "PMS_POL_009": "Auth policy exists with name : ", + "PMS_POL_009": "A policy with this name already exists", "PMS_COR_002": "Invalid Input Parameter _ ", "PMS_COR_003": "Could not process the request", "PMS_POL_010": " Auth Policies are not defined against to policy", diff --git a/pmp-reactjs-ui/public/i18n/fra.json b/pmp-reactjs-ui/public/i18n/fra.json index 47de4da4..5de284ca 100644 --- a/pmp-reactjs-ui/public/i18n/fra.json +++ b/pmp-reactjs-ui/public/i18n/fra.json @@ -650,7 +650,10 @@ "policyData": "Données de politique (uniquement json)", "policyDataDesc": "Collez le code ou téléchargez un fichier", "upload": "Télécharger", - "remove": "Retirer" + "remove": "Retirer", + "CreatePolicySuccessHeader":"Politique créée avec succès !", + "uploadFileError": "Une erreur inattendue s'est produite lors du téléchargement du fichier. Veuillez réessayer.", + "jsonParseError": "Veuillez fournir des données JSON valides" }, "consentPopup": { "title": "Termes et conditions", @@ -779,7 +782,7 @@ "PMS_POL_006": "Type d'authentification non pris en charge dans le fichier de stratégie", "PMS_POL_007": "Attribut eKYC manquant dans le fichier de stratégie", "PMS_POL_008": "L'ID de stratégie n'existe pas", - "PMS_POL_009": "La politique d'authentification existe avec le nom :", + "PMS_POL_009": "Une stratégie portant ce nom existe déjà", "PMS_COR_002": "Paramètre d'entrée non valide -", "PMS_COR_003": "Impossible de traiter la demande", "PMS_POL_010": " Les politiques d'authentification ne sont pas définies par rapport à la politique", diff --git a/pmp-reactjs-ui/src/pages/admin/partners/PartnersListFilter.js b/pmp-reactjs-ui/src/pages/admin/partners/PartnersListFilter.js index 6aebea74..8ff0bed3 100644 --- a/pmp-reactjs-ui/src/pages/admin/partners/PartnersListFilter.js +++ b/pmp-reactjs-ui/src/pages/admin/partners/PartnersListFilter.js @@ -104,7 +104,8 @@ function PartnerListFilter({ onApplyFilter, setErrorCode, setErrorMsg }) { const styleSet = { inputField: "min-w-64 h-9", - inputLabel: "mb-2" + inputLabel: "mb-2", + outerDiv: "ml-4" }; return ( diff --git a/pmp-reactjs-ui/src/pages/admin/policyManager/AuthPoliciesList.js b/pmp-reactjs-ui/src/pages/admin/policyManager/AuthPoliciesList.js index be71fe8b..c12552d5 100644 --- a/pmp-reactjs-ui/src/pages/admin/policyManager/AuthPoliciesList.js +++ b/pmp-reactjs-ui/src/pages/admin/policyManager/AuthPoliciesList.js @@ -28,6 +28,7 @@ function AuthPoliciesList() { }; const createAuthPolicy = () => { + localStorage.setItem('policyType', 'Auth'); navigate('/partnermanagement/admin/policy-manager/create-auth-policy'); }; diff --git a/pmp-reactjs-ui/src/pages/admin/policyManager/CreatePolicy.js b/pmp-reactjs-ui/src/pages/admin/policyManager/CreatePolicy.js index 7af142e7..7454aa71 100644 --- a/pmp-reactjs-ui/src/pages/admin/policyManager/CreatePolicy.js +++ b/pmp-reactjs-ui/src/pages/admin/policyManager/CreatePolicy.js @@ -1,4 +1,4 @@ -import { useState, useEffect, useRef } from "react"; +import { useState, useEffect, useRef, version } from "react"; import { useNavigate, useBlocker } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { getUserProfile } from "../../../services/UserProfileService"; @@ -7,7 +7,6 @@ import { getPartnerManagerUrl, getPolicyManagerUrl, handleServiceErrors, moveToP import { HttpService } from '../../../services/HttpService'; import LoadingIcon from "../../common/LoadingIcon"; import ErrorMessage from "../../common/ErrorMessage"; -import DropdownComponent from "../../common/fields/DropdownComponent"; import DropdownWithSearchComponent from "../../common/fields/DropdownWithSearchComponent"; import BlockerPrompt from "../../common/BlockerPrompt"; import Title from "../../common/Title"; @@ -30,12 +29,44 @@ function CreatePolicy() { const [createPolicySuccess, setCreatePolicySuccess] = useState(false); const [confirmationData, setConfirmationData] = useState({}); const [isSubmitClicked, setIsSubmitClicked] = useState(false); + const [policyType, setPolicyType] = useState(null); let isCancelledClicked = false; const cancelErrorMsg = () => { setErrorMsg(""); }; + const blocker = useBlocker(({ currentLocation, nextLocation }) => { + if (isSubmitClicked || isCancelledClicked || createPolicySuccess) { + setIsSubmitClicked(false); + isCancelledClicked = false; + return false; + } + + return ( + (policyGroup || policyName || policyDescription || policyData) && + currentLocation.pathname !== nextLocation.pathname + ); + }); + + useEffect(() => { + const shouldWarnBeforeUnload = () => + policyGroup || policyName || policyDescription || policyData; + + const handleBeforeUnload = (event) => { + if (shouldWarnBeforeUnload() && !isSubmitClicked) { + event.preventDefault(); + event.returnValue = ''; + } + }; + + window.addEventListener('beforeunload', handleBeforeUnload); + + return () => { + window.removeEventListener('beforeunload', handleBeforeUnload); + }; + }, [policyGroup, policyName, policyDescription, policyData, isSubmitClicked]); + const onChangePolicyGroup = async (fieldName, selectedValue) => { setPolicyGroup(selectedValue); @@ -53,11 +84,88 @@ function CreatePolicy() { navigate('/partnermanagement/admin/policy-manager/auth-policies-list') } + useEffect(() => { + const fetchData = async () => { + try { + setDataLoaded(false); + const storedPolicyType = localStorage.getItem('policyType'); + if (!storedPolicyType) { + console.err('policy Type not found'); + navigate('/partnermanagement/admin/policy-manager/policy-group-list') + } + setPolicyType(storedPolicyType); + const response = await HttpService.get(getPolicyManagerUrl('/policies/policy-groups', process.env.NODE_ENV)); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const resData = responseData.response; + setPolicyGroupDropdownData(createDropdownData('name', '', false, resData, t)); + } else { + handleServiceErrors(responseData, setErrorCode, setErrorMsg); + } + } else { + setErrorMsg(t('commons.errorInResponse')); + } + setDataLoaded(true); + } catch (err) { + console.error('Error fetching data:', err); + setErrorMsg(err); + } + }; + fetchData(); + }, []); + const clickOnSubmit = async () => { + setIsSubmitClicked(true); + setErrorCode(""); + setErrorMsg(""); + setDataLoaded(false); + + // Convert policyData from string to JSON + let parsedPolicyData; + try { + parsedPolicyData = JSON.parse(policyData); + } catch (error) { + setErrorMsg(t('createPolicy.jsonParseError')); + setIsSubmitClicked(false); + setDataLoaded(true); + return; + } + let request = createRequest({ + name: policyName, + policyGroupName: policyGroup, + policyType: policyType, + desc: policyDescription, + policies: parsedPolicyData, + version: "1.1" + }); + try { + const response = await HttpService.post(getPolicyManagerUrl(`/policies`, process.env.NODE_ENV), request); + if (response) { + const responseData = response.data; + if (responseData && responseData.response) { + const requiredData = { + backUrl: "/partnermanagement/admin/policy-manager/auth-policies-list", + header: "createPolicy.CreatePolicySuccessHeader", + } + setConfirmationData(requiredData); + setCreatePolicySuccess(true); + } else { + handleServiceErrors(responseData, setErrorCode, setErrorMsg); + } + } else { + setErrorMsg(t('requestPolicy.errorInMapPolicy')); + } + } catch (err) { + setErrorMsg(err); + console.log("Error fetching data: ", err); + } + setDataLoaded(true); + setIsSubmitClicked(false); } const isFormValid = () => { - return policyGroup && policyName && policyDescription.trim(); + return policyGroup && policyName && policyDescription.trim() && policyData.trim(); }; const handlePolicyDescriptionChange = (e) => { @@ -94,7 +202,6 @@ function CreatePolicy() { const styleSet = { inputField: "min-w-64 w-full min-h-10", - outerDiv: "mx-4" }; const handleFileChange = (event) => { @@ -127,7 +234,7 @@ function CreatePolicy() { } return ( -
+
{!dataLoaded && ( )} @@ -136,28 +243,31 @@ function CreatePolicy() { {errorMsg && ( )} -
- +
+
+ +
{!createPolicySuccess ?

{t('requestPolicy.mandatoryFieldsMsg1')} * {t('requestPolicy.mandatoryFieldsMsg2')}

-
+
- - +
-
+

{t('createPolicy.remove')}

@@ -255,6 +365,7 @@ function CreatePolicy() {
)} +
) } diff --git a/pmp-reactjs-ui/src/pages/common/fields/TextInputComponent.js b/pmp-reactjs-ui/src/pages/common/fields/TextInputComponent.js index a7fe2813..b2a54b99 100644 --- a/pmp-reactjs-ui/src/pages/common/fields/TextInputComponent.js +++ b/pmp-reactjs-ui/src/pages/common/fields/TextInputComponent.js @@ -29,7 +29,7 @@ function TextInputComponent({ fieldName, fieldNameKey, placeHolderKey, textBoxVa fieldNameKey = containsAsterisk ? fieldNameKey.replace('*', '') : fieldNameKey; return ( -
+
diff --git a/pmp-reactjs-ui/src/pages/partner/policies/RequestPolicy.js b/pmp-reactjs-ui/src/pages/partner/policies/RequestPolicy.js index d2a73d55..5b06559b 100644 --- a/pmp-reactjs-ui/src/pages/partner/policies/RequestPolicy.js +++ b/pmp-reactjs-ui/src/pages/partner/policies/RequestPolicy.js @@ -176,14 +176,14 @@ function RequestPolicy() { const responseData = response.data; if (responseData && responseData.response) { const resData = responseData.response; - const requireDataData = { + const requiredData = { title: "requestPolicy.requestPolicy", backUrl: "/partnermanagement/policies/policies-list", header: "requestPolicy.policySuccessHeader", description: "requestPolicy.policySuccessMsg", subNavigation: "requestPolicy.policies", } - setConfirmationData(requireDataData); + setConfirmationData(requiredData); setRequestPolicySuccess(true); console.log(`Response data: ${resData.length}`); } else {