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 ca524dc commit f4cd15c
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 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>(null);
const [error, setError] = useState<string >('');
const [currentPage, setCurrentPage] = useState(initialPageState);
const [organizationsList, setOrganizationList] =
useState<Array<Organisation> | null>(null);
Expand Down Expand Up @@ -92,7 +92,6 @@ const UserDashBoard = () => {
currentPage.pageSize,
'',
);
console.log('response', response);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
Expand All @@ -108,7 +107,7 @@ const UserDashBoard = () => {
});
} else {
// setError(response as string);
setError(data?.data?.message as string || 'Failed to fetch invitations');
setError('Failed to fetch invitations');
}
} catch(err) {
setError('An unexpected error occurred');
Expand Down Expand Up @@ -164,7 +163,7 @@ const UserDashBoard = () => {
});
} else {
// setError(response as string);
setError(data?.data?.message as string || 'Failed to fetch invitations');
setError('Failed to fetch invitations');
}
}
catch(err){
Expand Down Expand Up @@ -451,35 +450,39 @@ const UserDashBoard = () => {
</div>
);
};


return (
<>
<div className="px-4 pt-6">
<div className="cursor-pointer">
{error !== '' &&
<AlertComponent
message={message ? message : (error ? error : '')}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={pathRoutes.users.invitations}
onAlertClose={() => {
setMessage('');
setError(null);
}}
/>
message={message || error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={pathRoutes.users.invitations}
onAlertClose={() => {
setMessage('');
setError('');
}}
/>
}

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

onAlertClose={() => {
setEcoMessage('');
setError(null);
setError('');
}}
/>
}
</div>
{walletData && walletData.length > 0 ? (
<></>
Expand Down

0 comments on commit f4cd15c

Please sign in to comment.