From 1bd99e7961663b6546dd8ddbebdb30f060ddedbc Mon Sep 17 00:00:00 2001 From: Sudeep7353 <103890430+Sudeep7353@users.noreply.github.com> Date: Fri, 10 May 2024 10:47:16 +0530 Subject: [PATCH] MOSIP:32661 - Integration with API - PartnerCertificatesList. (#290) * MOSIP:32661 - Integration with API - PartnerCertificatesList. Signed-off-by: sudeep * MOSIP:32661 - Integration with API - PartnerCertificatesList. Signed-off-by: sudeep * MOSIP:32661 - Integration with API - PartnerCertificatesList. Signed-off-by: sudeep --------- Signed-off-by: sudeep Signed-off-by: Mayura Deshmukh <52281514+mayuradesh@users.noreply.github.com> Co-authored-by: Mayura Deshmukh <52281514+mayuradesh@users.noreply.github.com> --- .../src/pages/PartnerCertificatesList.js | 379 +++++++++++------- 1 file changed, 238 insertions(+), 141 deletions(-) diff --git a/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js b/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js index 9492b7ea4..e38d09c0b 100644 --- a/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js +++ b/pmp-reactjs-ui/src/pages/PartnerCertificatesList.js @@ -1,6 +1,7 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import UploadCertificate from "./UploadCertificate"; +import HttpService from '../services/HttpService'; function PartnerCertificatesList() { @@ -8,30 +9,11 @@ function PartnerCertificatesList() { const navigate = useNavigate(); const [showPopup, setShowPopup] = useState(false); + const [certificatesData, setcertificatesData] = useState([]); + const [errorMsg, setErrorMsg] = useState(""); + const [dataLoaded, setDataLoaded] = useState(false); const [selectedPartnerData, setSelectedPartnerData] = useState(null); - var dateAndMonth = new Date().getDate() + '-' + new Date().getMonth(); - var expiryYear = parseInt(new Date().getFullYear()) + 1; - - const expiryDate = [dateAndMonth, expiryYear].join('-'); - const uploadDate = [expiryDate + ' ' + new Date().toLocaleTimeString('en-GB')]; - - const certificatesData = [ - { - partnerId: 0, - partnerType: "Authentication Partner", - isCertificateAvailable: true, - uploadDt: uploadDate, - expiryDt: expiryDate - }, - { - partnerId: 1, - partnerType: "FTM Chip Provider", - isCertificateAvailable: false, - uploadDt: "-", - expiryDt: "-" - } - ]; - + const clickOnUpload = (partner) => { setShowPopup(!showPopup); setSelectedPartnerData(partner); @@ -46,133 +28,248 @@ function PartnerCertificatesList() { navigate('/partnermanagement') }; + useEffect(() => { + const fetchData = async () => { + try { + const response = await HttpService.get('/api/partners/getAllCertificateDetails'); - return ( -
-
-
- moveToHome()} className="mt-5 cursor-pointer" - xmlns="http://www.w3.org/2000/svg" - width="22.765" height="14.416" viewBox="0 0 22.765 17.416"> - - - -
-

Partner Certificate

-

moveToHome()} className="font-semibold text-blue-500 text-xs cursor-pointer"> - Home

-
-
+ if (response != null) { + const responseData = response.data; + if (responseData.errors && responseData.errors.length > 0) { + const errorMessage = responseData.errors[0].message; + setErrorMsg(errorMessage); + console.error('Error:', errorMessage); + } else { + const resData = responseData.response; + setcertificatesData(resData); + console.log('Response data:', resData); + } + }else{ + setErrorMsg("Response is null"); + } + setDataLoaded(true); + } catch (err) { + console.error('Error fetching data:', err); + setErrorMsg(err); + } + }; + fetchData(); + }, []); -
    - {certificatesData.map((partner, index) => { - return ( -
  • -
    -
    - {partner.isCertificateAvailable - ? - - - : - - - } + const cancelErrorMsg = () => { + setErrorMsg(""); + }; -
    -
    - {partner.isCertificateAvailable ? "Certificate Name Goes Here.CER" : "Please upload partner certificate here"} -
    -

    {partner.isCertificateAvailable ? null : "Only .cer or .pem certificate formats are allowed for upload"}

    -
    -
    - {partner.isCertificateAvailable - ?
    -
    - + return ( +
    + {!dataLoaded && ( +
    - {activeBtn && ( -
    -
    - Original Certificate - - - +
    + +

    Loading

    +
    -
    - + )} + {dataLoaded && ( + <> + {errorMsg && ( +
    +
    +
    +

    + {errorMsg} +

    +
    +
    + + + +
    +
    +
    + )} +
    +
    + moveToHome()} className="mt-5 cursor-pointer" + xmlns="http://www.w3.org/2000/svg" + width="22.765" height="14.416" viewBox="0 0 22.765 17.416"> + + + +
    +

    Partner Certificate

    +

    moveToHome()} className="font-semibold text-blue-500 text-xs cursor-pointer"> + Home

    +
    +
    +
      + {certificatesData.length === 0 ? +
      + + + + + + + + + + + + + + + + + + + + + + + +

      No partner types are mapped to your user id

      +
      : + certificatesData.map((partner, index) => { + return ( +
    • +
      +
      + {partner.isCertificateAvailable + ? + + + : + + + } + +
      +
      + {partner.isCertificateAvailable ? "Certificate Name Goes Here.CER" : "Please upload partner certificate here"} +
      +

      {partner.isCertificateAvailable ? null : "Only .cer or .pem certificate formats are allowed for upload"}

      +
      +
      + {partner.isCertificateAvailable + ?
      +
      +
      -
      )} + + + + {activeBtn && ( +
      +
      + Original Certificate + + + + +
      + +
      )} +
      + +
    + : } + {showPopup && ( + + )} +
    +
    +
    +
    +

    Partner Type

    +

    {partner.partnerType}

    +
    +
    +

    Expiry Date

    +

    {formatDate(partner.certificateExpiryDate, 'date')}

    +
    +
    +

    Time of Upload

    +

    {formatDate(partner.certificateUploadDate, 'dateTime')}

    -
    - : } - {showPopup && ( - - )} -
    -
    -
    -
    -

    Partner Type

    -

    {partner.partnerType}

    -
    -
    -

    Expiry Date

    -

    {partner.expiryDt}

    -
    -
    -

    Time of Upload

    -

    {partner.uploadDt}

    -
    -
    -
  • - ) - } - )} -
-
+ + ) + } + ) + } + +
+ + )} +