diff --git a/pmp-reactjs-ui/src/pages/UploadCertificate.js b/pmp-reactjs-ui/src/pages/UploadCertificate.js index d7e46f562..31d9716a1 100644 --- a/pmp-reactjs-ui/src/pages/UploadCertificate.js +++ b/pmp-reactjs-ui/src/pages/UploadCertificate.js @@ -11,6 +11,7 @@ function UploadCertificate({ closePopup, partnerData }) { const [certificateData, setCertificateData] = useState(""); const [formattedDate, setFormattedDate] = useState(""); const [rotation, setRotation] = useState(0); + const [dataLoaded, setDataLoaded] = useState(true); const openDropdown = () => { setIsDropdownOpen(!isDropdownOpen); @@ -22,6 +23,7 @@ function UploadCertificate({ closePopup, partnerData }) { if (uploadSuccess) { closePopup(); } else { + setDataLoaded(false); let request = { request: { partnerId: partnerData.partnerId, @@ -31,15 +33,20 @@ function UploadCertificate({ closePopup, partnerData }) { } try { const response = await HttpService.post('/api/partners/certificate/upload', request) - const resData = response.data.response; - 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"); + if (response !== null) { + const resData = response.data.response; + 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); + } } else { - setUploadSuccess(true); + setErrorMsg("There is some error in uploading the certificate. Try again later!"); } + setDataLoaded(true); } catch (err) { setErrorMsg(err); console.log("Unable to upload partner certificate: ", err); @@ -131,185 +138,202 @@ function UploadCertificate({ closePopup, partnerData }) { return (
-
-

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

-

Please select the fields and upload certificate.

-
-
-
-
-
- - + {!dataLoaded && ( +
+ +
+ +

Loading

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

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

+

Please select the fields and upload certificate.

+
+
+
+ +
+ + +
+
+ +
+ + {isDropdownOpen && ( + + )} +
+
+ +
+ {uploading && ( +
+ + + + +
+ We're uploading your certificate... +
+

+ Cancel +

+
+ )} + {!uploading && fileName === '' && ( +
+ + +
+ )} + {!uploading && fileName && ( +
+ +
+ {fileName} +
+

+ Remove +

)}
+ {partnerData.isCertificateAvailable && ( +

Last certificate was uploaded on {formattedDate}

+ )}
- -
- {uploading && ( -
- - - - -
- We're uploading your certificate... -
-

- Cancel -

-
- )} - {!uploading && fileName === '' && ( -
- - -
- )} - {!uploading && fileName && ( -
- -
- {fileName} -
-

- Remove -

-
- )} -
- {partnerData.isCertificateAvailable && ( -

Last certificate was uploaded on {formattedDate}

- )} -
-
-
- - {(!uploading && fileName) ? ( - - ) : ( - - )} - {uploadSuccess && ( -
-
-

- Partner certificate for partnerType is uploaded successfully. -

- setUploadSuccess(false)} - > - - -
-
+
+
+ + {(!uploading && fileName) ? ( + + ) : ( + + )} + {uploadSuccess && ( +
+
+

+ Partner certificate for {partnerData.partnerType} is uploaded successfully. +

+ setUploadSuccess(false)} + > + + +
+
- )} - {!uploadSuccess && errorMsg && ( -
-
-

- {errorMsg} -

- - - -
+ )} + {!uploadSuccess && errorMsg && ( +
+
+

+ {errorMsg} +

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