Skip to content

Commit

Permalink
used utility function for handle alert component issue
Browse files Browse the repository at this point in the history
Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Oct 9, 2024
1 parent ff09824 commit 0fd2c49
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions src/components/User/UserDashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const UserDashBoard = () => {
const [message, setMessage] = useState<string | null>('');
const [ecoMessage, setEcoMessage] = useState<string | null>('');
const [viewButton, setViewButton] = useState<boolean>(false);
const [error, setError] = useState<string | null>('');
const [error, setError] = useState<string >('');
const [currentPage, setCurrentPage] = useState(initialPageState);
const [organizationsList, setOrganizationList] =
useState<Array<Organisation> | null>(null);
Expand Down Expand Up @@ -106,8 +106,8 @@ const UserDashBoard = () => {
total: totalPages,
});
} else {
setError(response as string);
// setError('Failed to fetch invitations');
// setError(response as string);
setError('Failed to fetch invitations');
}
} catch(err) {
setError('An unexpected error occurred');
Expand Down Expand Up @@ -162,8 +162,8 @@ const UserDashBoard = () => {
total: totalPages,
});
} else {
setError(response as string);
// setError('Failed to fetch invitations');
// setError(response as string);
setError('Failed to fetch invitations');
}
}
catch(err){
Expand Down Expand Up @@ -450,41 +450,38 @@ const UserDashBoard = () => {
</div>
);
};
console.log("errror_:::::::::::", typeof error);
console.log("mesaage---:::::::::", typeof message);

return (
<>
<div className="px-4 pt-6">
<div className="cursor-pointer">
{(error !== '' || message !== '') &&
<AlertComponent
message={message || error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={pathRoutes.users.invitations}
onAlertClose={() => {
setMessage('');
setError('');
}}
/>
}
{(error || message) && ( // Check if either error or message exists
<AlertComponent
message={message || error || ''} // Fallback to an empty string
type={message ? 'warning' : 'failure'} // Type based on message presence
viewButton={viewButton}
path={pathRoutes.users.invitations}
onAlertClose={() => {
setMessage(''); // Reset message on close
setError(''); // Reset error on close
}}
/>
)}

</div>
<div className="cursor-pointer">
{(error !== '' || ecoMessage !== '') &&
<AlertComponent
message={ecoMessage || error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={`${envConfig.PUBLIC_ECOSYSTEM_FRONT_END_URL}${pathRoutes.users.dashboard}` }

onAlertClose={() => {
setEcoMessage('');
setError('');
}}
/>
}
{(error || ecoMessage) && ( // Check if either error or ecoMessage exists
<AlertComponent
message={ecoMessage || error || ''} // Fallback to an empty string
type={ecoMessage ? 'warning' : 'failure'} // Type based on ecoMessage presence
viewButton={viewButton}
path={`${envConfig.PUBLIC_ECOSYSTEM_FRONT_END_URL}${pathRoutes.users.dashboard}`}
onAlertClose={() => {
setEcoMessage(''); // Reset ecoMessage on close
setError(''); // Reset error on close
}}
/>
)}
</div>
{walletData && walletData.length > 0 ? (
<></>
Expand Down

0 comments on commit 0fd2c49

Please sign in to comment.