Skip to content

Commit

Permalink
Merge pull request #447 from credebl/fix-error-message
Browse files Browse the repository at this point in the history
fix: alert and error message
  • Loading branch information
nishad-ayanworks authored Dec 29, 2023
2 parents 7670bc5 + 0f28e53 commit 3f0a366
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/common/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export enum BulkIssuanceHistoryData {
completed = 'Process Completed',
interrupted= 'Process Interrupted',
retry= 'Process Reinitiated',
partially_completed= "Process Failed"
partially_completed= "Partially Completed",
}

export enum BulkIssuanceStatus {
Expand Down
6 changes: 3 additions & 3 deletions src/components/AlertComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import type { IAlertComponent } from "./interface";
import React from 'react';
import type { IAlertComponent } from './interface';

export const AlertComponent = ({
message,
type,
viewButton,
onAlertClose,
path = '',
}:IAlertComponent) => {
}: IAlertComponent) => {
const getAlertClass = () => {
switch (type) {
case 'warning':
Expand Down
58 changes: 40 additions & 18 deletions src/components/Issuance/BulkIssuance.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Card, Pagination } from 'flowbite-react';
import React, { Attributes, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import Select from 'react-select';
import {
DownloadCsvTemplate, getSchemaCredDef, getCsvFileData,
Expand Down Expand Up @@ -29,7 +29,6 @@ const BulkIssuance = () => {
const [uploadedFileName, setUploadedFileName] = useState('');
const [uploadedFile, setUploadedFile] = useState(null);
const [openModal, setOpenModal] = useState<boolean>(false);
const [message, setMessage] = useState('');
const [searchText, setSearchText] = useState('');
const [uploadMessage, setUploadMessage] = useState<IUploadMessage | null>(null)
const [success, setSuccess] = useState<string | null>(null);
Expand Down Expand Up @@ -112,19 +111,31 @@ const BulkIssuance = () => {
if (fileUrl) {
downloadFile(fileUrl, 'downloadedFile.csv');
setSuccess('File downloaded successfully');
setTimeout(()=>{
setSuccess(null)
},5000)
setProcess(false);
} else {
setUploadMessage({message: 'File URL is missing in the response', type: "failure"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
setSuccess(null)
setFailure(null)
}
} else {
setUploadMessage({message: 'API request was not successful', type: "failure"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
setSuccess(null)
setFailure(null)
}
} catch (error) {
setUploadMessage({message: error as string, type: "failure"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
setSuccess(null)
setFailure(null)
}
Expand Down Expand Up @@ -160,6 +171,7 @@ const BulkIssuance = () => {
useEffect(() => {
SOCKET.emit('bulk-connection')
SOCKET.on('bulk-issuance-process-completed', () => {
setSuccess(null)
console.log(`bulk-issuance-process-completed`);
toast.success('Issuance process completed', {
position: 'top-right',
Expand All @@ -171,10 +183,10 @@ const BulkIssuance = () => {
progress: undefined,
theme: 'colored',
});
setSuccess("Issuance process completed")
});

SOCKET.on('error-in-bulk-issuance-process', () => {
setFailure(null)
console.log(`error-in-bulk-issuance-process-initiated`);
toast.error('Issuance process failed. Please retry', {
position: 'top-right',
Expand All @@ -186,7 +198,6 @@ const BulkIssuance = () => {
progress: undefined,
theme: 'colored',
});
setFailure("Issuance process failed, please retry")
});

}, [])
Expand All @@ -196,6 +207,9 @@ const BulkIssuance = () => {

if (file.type !== 'text/csv') {
setUploadMessage({message:'Invalid file type. Please select only CSV files.', type: "failure"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
setSuccess(null)
setFailure(null)
return;
Expand Down Expand Up @@ -225,9 +239,15 @@ const BulkIssuance = () => {
setRequestId(data?.data);
setIsFileUploaded(true);
setUploadMessage({message: data?.message, type: "success"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
await handleCsvFileData(data?.data);
} else {
setUploadMessage({message: response as string, type: "failure"});
setTimeout(()=>{
setUploadMessage(null)
},5000)
setSuccess(null)
setFailure(null)
}
Expand Down Expand Up @@ -346,14 +366,17 @@ const BulkIssuance = () => {
handleResetForConfirm()
} else {
setFailure(response as string);
setTimeout(()=>{
setFailure(null)
},5000)
setLoading(false);
}
} else {
setLoading(false);
setFailure(response as string);
setTimeout(() => {
setFailure(null);
}, 4000);
}, 5000);
}
};

Expand All @@ -375,18 +398,6 @@ const BulkIssuance = () => {
</div>
<div>
<ToastContainer />
{(success || failure) && (
<AlertComponent
message={success ?? failure}
type={success ? 'success' : 'failure'}
onAlertClose={() => {
setSuccess(null);
setFailure(null);
}}
viewButton={Boolean((success && success === "Issuance process completed") || (failure && failure === "Issuance process failed, please retry"))}
path={pathRoutes.organizations.Issuance.history}
/>
)}
<div className="flex justify-between mb-4 items-center ml-1">
<div>
<p className="text-2xl font-semibold dark:text-white">
Expand Down Expand Up @@ -423,6 +434,18 @@ const BulkIssuance = () => {
View History
</Button>
</div>
{(success || failure) && (
<AlertComponent
message={success ?? failure}
type={success ? 'success' : 'failure'}
onAlertClose={() => {
setSuccess(null);
setFailure(null);
}}
viewButton={Boolean((success && success === "Issuance process completed") || (failure && failure === "Issuance process failed, please retry"))}
path={pathRoutes.organizations.Issuance.history}
/>
)}
<div className="flex flex-col justify-between min-h-100/21rem">
<Card>
<div>
Expand Down Expand Up @@ -755,7 +778,6 @@ const BulkIssuance = () => {
</Button>
<Button
onClick={handleReset}
disabled={!isFileUploaded}
type="reset"
color="bg-primary-800"
className="float-right bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-4 ml-auto dark:text-white dark:hover:text-black dark:hover:bg-primary-50"
Expand Down
41 changes: 15 additions & 26 deletions src/components/Issuance/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BulkIssuanceHistoryData,
} from '../../common/enums';
import { ToastContainer, toast } from 'react-toastify';
import React from 'react';

const HistoryBulkIssuance = () => {
const initialPageState = {
Expand Down Expand Up @@ -74,6 +75,7 @@ const HistoryBulkIssuance = () => {
useEffect(() => {
SOCKET.emit('bulk-connection');
SOCKET.on('bulk-issuance-process-retry-completed', () => {
setSuccess(null);
console.log(`bulk-issuance-process-retry-completed`);
toast.success('Issuance process completed', {
position: 'top-right',
Expand All @@ -85,10 +87,11 @@ const HistoryBulkIssuance = () => {
progress: undefined,
theme: 'colored',
});
setSuccess('Issuance process completed');
getConnections();
});

SOCKET.on('error-in-bulk-issuance-retry-process', () => {
setFailure(null);
console.log(`error-in-bulk-issuance-retry-process-initiated`);
toast.error('Issuance process failed. Please retry', {
position: 'top-right',
Expand All @@ -100,7 +103,7 @@ const HistoryBulkIssuance = () => {
progress: undefined,
theme: 'colored',
});
setError('Issuance process failed, please retry');
getConnections();
});

let getData: NodeJS.Timeout;
Expand Down Expand Up @@ -156,7 +159,6 @@ const HistoryBulkIssuance = () => {
return {
data: [
{ data: userName },

{
data: (
<DateTooltip date={createdOn} id="issuance_connection_list">
Expand All @@ -168,31 +170,18 @@ const HistoryBulkIssuance = () => {
{ data: totalRecords },
{ data: successfulRecords },
{ data: failedRecords },

{
data: (
<p
className={`${status === BulkIssuanceHistory.started
? 'bg-primary-100 text-primary-800 dark:bg-gray-700 dark:text-primary-400 border border-primary-100 dark:border-primary-500'
: status === BulkIssuanceHistory.completed ||
status === BulkIssuanceHistory.retry
? 'bg-green-100 text-green-800 dark:bg-gray-700 dark:text-green-400 border border-green-100 dark:border-green-500'
: status === BulkIssuanceHistory.interrupted
? 'bg-orange-100 text-orange-800 dark:bg-gray-700 dark:text-orange-400 border border-orange-100 dark:border-orange-400'
: status === BulkIssuanceHistory.partially_completed
? 'bg-red-100 text-red-800 dark:bg-gray-700 dark:text-red-400 border border-red-100 dark:border-red-500'
: 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-400 border border-gray-100 dark:border-gray-500'
} text-sm font-medium mr-0.5 px-0.5 py-0.5 rounded-md flex justify-center items-center w-fit px-2`}
className={`${
failedRecords > 0
? 'bg-orange-100 text-orange-800 dark:bg-gray-700 dark:text-orange-400 border border-orange-100 dark:border-orange-400'
: 'bg-green-100 text-green-800 dark:bg-gray-700 dark:text-green-400 border border-green-100 dark:border-green-500'
}text-sm font-medium mr-0.5 py-0.5 rounded-md flex justify-center items-center w-fit px-2`}
>
{status === BulkIssuanceHistory.started
? BulkIssuanceHistoryData.started
: status === BulkIssuanceHistory.completed
? BulkIssuanceHistoryData.completed
: status === BulkIssuanceHistory.interrupted
? BulkIssuanceHistoryData.interrupted
: status === BulkIssuanceHistory.partially_completed
? BulkIssuanceHistoryData.partially_completed
: BulkIssuanceHistoryData.retry}
{failedRecords > 0
? BulkIssuanceHistoryData.interrupted
: BulkIssuanceHistoryData.completed}
</p>
),
},
Expand Down Expand Up @@ -271,7 +260,7 @@ const HistoryBulkIssuance = () => {
total: totalPages,
});
} else {
if (response?.toString()?.toLowerCase() !== "history not found") {
if (response?.toString()?.toLowerCase() !== 'history not found') {
setFailure(response as string);
}
}
Expand Down Expand Up @@ -302,7 +291,7 @@ const HistoryBulkIssuance = () => {
height="40"
viewBox="0 0 24 24"
fill="none"
className='mr-3'
className="mr-3"
>
<path
d="M12 20C9.76667 20 7.875 19.225 6.325 17.675C4.775 16.125 4 14.2333 4 12C4 9.76667 4.775 7.875 6.325 6.325C7.875 4.775 9.76667 4 12 4C13.15 4 14.25 4.2375 15.3 4.7125C16.35 5.1875 17.25 5.86667 18 6.75V4H20V11H13V9H17.2C16.6667 8.06667 15.9375 7.33333 15.0125 6.8C14.0875 6.26667 13.0833 6 12 6C10.3333 6 8.91667 6.58333 7.75 7.75C6.58333 8.91667 6 10.3333 6 12C6 13.6667 6.58333 15.0833 7.75 16.25C8.91667 17.4167 10.3333 18 12 18C13.2833 18 14.4417 17.6333 15.475 16.9C16.5083 16.1667 17.2333 15.2 17.65 14H19.75C19.2833 15.7667 18.3333 17.2083 16.9 18.325C15.4667 19.4417 13.8333 20 12 20Z"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Issuance/HistoryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const HistoryDetails = ({ requestId }: IProps) => {
},
{
data: history?.error
? history?.error.replace(/[[\]"{},]/g, ' ')
? history?.error === 'Http Exception' ? 'Credential Issuance failed due to error in Wallet Agent' : history?.error?.replace(/[[\]"{},]/g, ' ')
: '-',
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/components/organization/WalletSpinup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const SharedAgentForm = ({ orgName, seeds, isCopied, loading, copyTextVal, submi
<Button
isProcessing={loading}
type="submit"
className='mt-4 float-right text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"'
className='mt-4 float-right text-base font-medium text-center text-white bg-primary-700 hover:!bg-primary-800 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800'
>
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
Expand Down Expand Up @@ -904,4 +904,4 @@ const WalletSteps = (props: { steps: number; agentSpinupCall: boolean }) => {
);
};

export default WalletSpinup;
export default WalletSpinup;

0 comments on commit 3f0a366

Please sign in to comment.