From e0568be0c291cd4d9cdba5b229af574bfa1dd671 Mon Sep 17 00:00:00 2001 From: SwethaKrish4 <110164892+SwethaKrish4@users.noreply.github.com> Date: Fri, 10 May 2024 10:35:17 +0530 Subject: [PATCH] MOSIP-32662: Added certificate re-upload flow (#291) Signed-off-by: SwethaKrish4 <110164892+SwethaKrish4@users.noreply.github.com> --- .../src/pages/PartnerCertificatesList.js | 12 ++--- pmp-reactjs-ui/src/pages/UploadCertificate.js | 54 ++++++++++++++----- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js b/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js index 16fefcbd7..9492b7ea4 100644 --- a/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js +++ b/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js @@ -8,7 +8,7 @@ function PartnerCertificatesList() { const navigate = useNavigate(); const [showPopup, setShowPopup] = useState(false); - + const [selectedPartnerData, setSelectedPartnerData] = useState(null); var dateAndMonth = new Date().getDate() + '-' + new Date().getMonth(); var expiryYear = parseInt(new Date().getFullYear()) + 1; @@ -32,12 +32,12 @@ function PartnerCertificatesList() { } ]; - const uploadCertificate = () => { + const clickOnUpload = (partner) => { setShowPopup(!showPopup); + setSelectedPartnerData(partner); }; const closePopup = () => { - console.log("Popup closed"); setShowPopup(false); window.location.reload(); }; @@ -141,15 +141,15 @@ function PartnerCertificatesList() { )} - - : } {showPopup && ( - + )}
diff --git a/pmp-reactjs-ui/src/pages/UploadCertificate.js b/pmp-reactjs-ui/src/pages/UploadCertificate.js index a72bdeee0..eb756da61 100644 --- a/pmp-reactjs-ui/src/pages/UploadCertificate.js +++ b/pmp-reactjs-ui/src/pages/UploadCertificate.js @@ -1,7 +1,7 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import HttpService from '../services/HttpService'; -function UploadCertificate({closePopup}) { +function UploadCertificate({closePopup, partnerData}) { const [isDropdownOpen, setIsDropdownOpen] = useState(false); const [selectedDomainType, setSelectedDomainType] = useState(""); const [uploading, setUploading] = useState(false); @@ -9,12 +9,12 @@ function UploadCertificate({closePopup}) { const [uploadSuccess, setUploadSuccess] = useState(false); const [errorMsg, setErrorMsg] = useState(""); const [certificateData, setCertificateData] = useState(""); + const [formattedDate, setFormattedDate] = useState(""); const openDropdown = () => { setIsDropdownOpen(!isDropdownOpen); }; const clickOnCancel = () => { - console.log("Cancel button clicked"); closePopup(); }; const clickOnSubmit = async () => { @@ -23,7 +23,7 @@ function UploadCertificate({closePopup}) { } else { let request = { request: { - partnerId: "abc", + partnerId: partnerData.partnerId, certificateData: certificateData, partnerDomain: selectedDomainType, }, @@ -34,12 +34,14 @@ function UploadCertificate({closePopup}) { if (response.data.errors && response.data.errors.length > 0) { const errorMessage = response.data.errors[0].message; setErrorMsg(errorMessage); + } else if (resData === null) { + setErrorMsg("Unable to upload partner certificate"); } else { setUploadSuccess(true); } } catch (err) { setErrorMsg(err); - console.log("upload certificate error: ",err); + console.log("Unable to upload partner certificate: ",err); } } }; @@ -47,15 +49,22 @@ function UploadCertificate({closePopup}) { setSelectedDomainType(option); openDropdown(); }; + const getDefaultDomainType = () => { + if (partnerData.partnerType === "Device Provider") { + return "DEVICE"; + } else if (partnerData.partnerType === "FTM Chip Provider") { + return "FTM"; + } else { + return "AUTH"; + } + }; const cancelUpload = () => { setFileName(""); setUploading(false); - console.log(`Selected file: ${fileName}`) }; const removeUpload = () => { setFileName(""); setUploading(false); - console.log(`Selected file: ${fileName}`) }; const cancelErrorMsg = () => { setErrorMsg(""); @@ -73,7 +82,6 @@ function UploadCertificate({closePopup}) { setUploading(true); setFileName(fileName); setCertificateData(fileData); - console.log(`Certificate data: ${fileData}`) setTimeout(() => { setUploading(false); }, 3000); @@ -84,11 +92,26 @@ function UploadCertificate({closePopup}) { } } }; + + useEffect(() => { + if (partnerData.isCertificateAvailable) { + const dateString = partnerData.uploadDt.toString(); + const formatted = formatUploadDate(dateString); + setFormattedDate(formatted); + } + }, [partnerData.uploadDt]); + + const formatUploadDate = (dateString) => { + const [datePart, timePart] = dateString.split(' '); + const [day, month, year] = datePart.split('-'); + return `${day}/${month}/${year}`; + }; + return(
-
+
-

Upload Partner Certificate

+

{partnerData.isCertificateAvailable ? "Re-Upload Partner Certificate" : "Upload Partner Certificate"}

Please select the fields and upload certificate.

@@ -97,14 +120,14 @@ function UploadCertificate({closePopup}) {
+ value={partnerData.partnerType} disabled />
@@ -206,11 +229,14 @@ function UploadCertificate({closePopup}) {
)}
+ {partnerData.isCertificateAvailable && ( +

Last certificate was uploaded on {formattedDate}

+ )}
- {(!uploading && fileName && selectedDomainType !== "") ? ( + {(!uploading && fileName) ? ( ) : (