Skip to content

Commit

Permalink
MOSIP-36115: Integration with API Upload Certificate by Partner Admin
Browse files Browse the repository at this point in the history
Signed-off-by: Anil_Kumar_Majji <[email protected]>
  • Loading branch information
Anil-kumar-Majji committed Oct 10, 2024
1 parent 84ea238 commit 39a2bf1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 24 deletions.
3 changes: 2 additions & 1 deletion pmp-reactjs-ui/public/i18n/ara.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@
"uploadRootofTrustCertificate": {
"uploadRootofTrustCertificate": "تحميل شهادة جذر الثقة",
"partnerDomain": "مجال الشريك",
"dropdownPlaceholder": "حدد مجال الشريك"
"dropdownPlaceholder": "حدد مجال الشريك",
"successMsg": "تم تحميل شهادة جذر الثقة لـ {{partnerDomain}} بنجاح"
},
"viewRootOfTrustCertificate": {
"viewRootOfTrustCertificate": "عرض شهادة جذر الثقة",
Expand Down
3 changes: 2 additions & 1 deletion pmp-reactjs-ui/public/i18n/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@
"uploadRootofTrustCertificate": {
"uploadRootofTrustCertificate":"Upload Root of Trust Certificate",
"partnerDomain": "Partner Domain",
"dropdownPlaceholder": "Select partner domain"
"dropdownPlaceholder": "Select partner domain",
"successMsg": "Root of Trust Certificate for {{partnerDomain}} is uploaded successfully"
},
"viewRootOfTrustCertificate": {
"viewRootOfTrustCertificate": "View Root of Trust Certificate",
Expand Down
3 changes: 2 additions & 1 deletion pmp-reactjs-ui/public/i18n/fra.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@
"uploadRootofTrustCertificate": {
"uploadRootofTrustCertificate": "Télécharger le certificat racine de confiance",
"partnerDomain": "Domaine partenaire",
"dropdownPlaceholder": "Sélectionnez un domaine partenaire"
"dropdownPlaceholder": "Sélectionnez un domaine partenaire",
"successMsg": "Le certificat racine de confiance pour {{partnerDomain}} a été téléchargé avec succès"
},
"viewRootOfTrustCertificate": {
"viewRootOfTrustCertificate": "Afficher le certificat racine de confiance",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { useTranslation } from "react-i18next";
import { getUserProfile } from "../../../services/UserProfileService";
import { isLangRTL, onPressEnterKey } from "../../../utils/AppUtils";
import {
formatDate,
getStatusCode,
handleMouseClickForDropdown,
toggleSortAscOrder,
toggleSortDescOrder,
bgOfStatus,
} from "../../../utils/AppUtils";
import { formatDate, getStatusCode, handleMouseClickForDropdown, toggleSortAscOrder, toggleSortDescOrder, bgOfStatus,} from "../../../utils/AppUtils";
import LoadingIcon from "../../common/LoadingIcon";
import ErrorMessage from "../../common/ErrorMessage";
import Title from "../../common/Title";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { createDropdownData, isLangRTL, onPressEnterKey } from "../../../utils/AppUtils";
import { createDropdownData, createRequest, getPartnerManagerUrl, isLangRTL, onPressEnterKey } from "../../../utils/AppUtils";
import { getUserProfile } from '../../../services/UserProfileService';
import Title from '../../common/Title'; import DropdownComponent from "../../common/fields/DropdownComponent";
import file from '../../../svg/file_icon.svg';
Expand All @@ -10,6 +10,7 @@ import fileDescription from '../../../svg/file_description.svg';
import SuccessMessage from "../../common/SuccessMessage";
import file_uploaded_successful from '../../../svg/file_uploaded_successful_icon.svg';
import ErrorMessage from '../../common/ErrorMessage';
import { HttpService } from '../../../services/HttpService';

function UploadRootTrustCertificate() {
const { t } = useTranslation();
Expand All @@ -20,7 +21,7 @@ function UploadRootTrustCertificate() {
const [successMsg, setSuccessMsg] = useState("");
const [uploading, setUploading] = useState(false);
const [selectedDomain, setSelectedDomain] = useState('');
const [certificateData, setCertificateData] = useState([]);
const [certificateData, setCertificateData] = useState('');
const [removeLastUploadData, setRemoveLastUploadData] = useState(false);
const [fileName, setFileName] = useState('');
const [uploadSuccess, setUploadSuccess] = useState(false);
Expand All @@ -29,9 +30,10 @@ function UploadRootTrustCertificate() {
const cancelUpload = () => {
setFileName("");
setUploading(false);
setSelectedDomain('');
};

const goBack = () => {
const submit = () => {
setFileName("");
setUploading(false);
navigate('/partnermanagement/admin/certificates/rootTrustCertificateList')
Expand All @@ -51,6 +53,42 @@ function UploadRootTrustCertificate() {
setSuccessMsg("");
};

const certificateSubmit = async (certificateData, selectedDomain) => {
setSuccessMsg("");
setErrorCode("");
const uploadRequest = createRequest({
certificateData: certificateData,
partnerDomain: selectedDomain
});
try {
let response;
response = await HttpService.post(getPartnerManagerUrl('/partners/certificate/ca/upload', process.env.NODE_ENV), uploadRequest)
if (response !== null) {
const resData = response.data.response;
if (response.data.errors && response.data.errors.length > 0) {
const errorCode = response.data.errors[0].errorCode;
const errorMessage = response.data.errors[0].message;
setUploadFailure(true);
setErrorCode(errorCode)
setErrorMsg(errorMessage);
} else if (resData === null) {
setUploadFailure(true);
setErrorMsg(t('uploadCertificate.unableToUploadCertificate'));
} else {
setUploadSuccess(true);
setSuccessMsg({partnerDomain: selectedDomain}, 'uploadRootofTrustCertificate.successMsg');
}
} else {
setUploadFailure(true);
setErrorMsg(t('uploadCertificate.errorWhileUploadingCertificate'));
}
} catch (err) {
setUploadFailure(true);
setErrorMsg(err);
console.log("Unable to upload partner certificate: ", err);
}
};

const handleFileChange = (event) => {
setErrorMsg("");
setErrorCode("");
Expand All @@ -71,14 +109,15 @@ function UploadRootTrustCertificate() {
}, 2000);
}
reader.readAsText(file);
certificateSubmit(certificateData, selectedDomain);
} else {
setUploadFailure(true);
setErrorMsg(t('uploadCertificate.fileUploadError'));
}
}
};

const onDomainChangeEvent = (value) => {
const onDomainChangeEvent = (fieldName, value) => {
setSelectedDomain(value);
};

Expand Down Expand Up @@ -110,8 +149,8 @@ function UploadRootTrustCertificate() {
<div className="m-[1%] shadow-md rounded-lg">
<div className={`flex items-center shadow-lg rounded-lg justify-between`}>
<div className="flex-col items-center w-full">
<div className={`flex items-center ${!uploading && fileName ? "bg-[#F4FAF4]" : "bg-[#edf2fc]"} p-[0.5rem]`}>
{!uploading && fileName
<div className={`flex items-center ${uploadSuccess && fileName ? "bg-[#F4FAF4]" : "bg-[#edf2fc]"} p-[0.5rem]`}>
{uploadSuccess && fileName
? <img src={file_uploaded_successful} className="h-8" alt="" />
: <img src={file} className="h-8" alt="" />
}
Expand All @@ -126,15 +165,15 @@ function UploadRootTrustCertificate() {
<div className="flex items-center p-3 bg-white rounded-lg gap-x-10">
<div className="flex-col">
<p className="font-semibold text-xs text-dim-gray">{t('uploadRootofTrustCertificate.partnerDomain')}</p>
<p className="font-bold text-sm text-charcoal-gray">-</p>
<p className="font-semibold text-xs text-charcoal-gray">{!uploadSuccess && selectedDomain}</p>
</div>
<div className={`flex-col ${isLoginLanguageRTL ? "mr-[5%]" : "ml-[5%]"}`}>
<p className="font-semibold text-xs text-dim-gray">{t('partnerCertificatesList.expiryDate')}</p>
<p className="font-semibold text-sm text-charcoal-gray">-</p>
<p className="font-semibold text-xs text-charcoal-gray">-</p>
</div>
<div className={`flex-col ${isLoginLanguageRTL ? "mr-[10%]" : "ml-[10%]"}`}>
<p className="font-semibold text-xs text-dim-gray">{t('partnerCertificatesList.timeOfUpload')}</p>
<p className="font-semibold text-sm text-charcoal-gray">-</p>
<p className="font-semibold text-xs text-charcoal-gray">-</p>
</div>
</div>
<div className="relative">
Expand All @@ -147,7 +186,7 @@ function UploadRootTrustCertificate() {
</div>
</div>
</div>
<div className={`flex-col pt-[0.5rem] justify-center w-[47rem] ${isLoginLanguageRTL ? 'pr-[31%]' : 'pl-[31%]'}`}>
<div className={`flex-col pt-[0.5rem] justify-center w-[47.5rem] ${isLoginLanguageRTL ? 'pr-[31%]' : 'pl-[31%]'}`}>
<DropdownComponent
fieldName='partnerDomain'
fieldNameKey='uploadRootofTrustCertificate.partnerDomain'
Expand All @@ -157,9 +196,8 @@ function UploadRootTrustCertificate() {
{ fieldValue: 'DEVICE', fieldCode: 'DEVICE' },
{ fieldValue: 'AUTH', fieldCode: 'AUTH' }
]}
placeHolderKey='uploadRootofTrustCertificate.dropdownPlaceholder'
placeHolderKey={selectedDomain ? selectedDomain : 'uploadRootofTrustCertificate.dropdownPlaceholder'}
isPlaceHolderPresent={true}
selectedDropdownValue={selectedDomain}
styleSet={uploadCertificateDropdownStyle}
id='partnerDomain_selector_dropdown'
/>
Expand Down Expand Up @@ -210,7 +248,7 @@ function UploadRootTrustCertificate() {
<hr className="border bg-medium-gray mt-[2rem]" />
<div className={`flex flex-row max-[450px]:flex-col space-x-3 max-[450px]:space-x-0 max-[450px]:space-y-2 w-full md:w-auto justify-end p-[1.5rem]`}>
<button id="upload_admin_certificate_cancel_btn" onClick={cancelUpload} className={`${isLoginLanguageRTL ? "ml-2" : "mr-2"} w-/12 md:w-24 h-10 border-[#1447B2] border rounded-md bg-white text-tory-blue text-sm font-semibold`}>{t('commons.cancel')}</button>
<button id="upload_admin_certificate_btn" onClick={goBack} className={`${isLoginLanguageRTL ? "ml-2" : "mr-2"} w-8/12 md:w-24 h-10 border-[#1447B2] border rounded-md text-sm bg-tory-blue text-white font-semibold`}>{t('commons.goBack')}</button>
<button disabled={!fileName} id="upload_admin_certificate_btn" onClick={submit} className={`${isLoginLanguageRTL ? "ml-2" : "mr-2"} w-8/12 md:w-24 h-10 ${!fileName ? 'bg-[]#cfd1d4] border-[#cfd1d4] text-[#65676b]' : 'border-[#1447B2] bg-tory-blue text-white'} border rounded-md text-sm font-semibold`}>{t('commons.submit')}</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 39a2bf1

Please sign in to comment.