Skip to content

Commit

Permalink
Merge pull request #607 from credebl/merge-to-qa
Browse files Browse the repository at this point in the history
merge: develop to qa
  • Loading branch information
nishad-ayanworks authored Feb 29, 2024
2 parents 712ed1e + 24ac75b commit d56f5aa
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 89 deletions.
23 changes: 15 additions & 8 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ICheckEcosystem,
checkEcosystem,
getEcosystemId,
getOwnerAdminRole,
} from '../../config/ecosystem';
import { Button, Dropdown } from 'flowbite-react';
import EditPopupModal from '../EditEcosystemOrgModal';
Expand Down Expand Up @@ -198,14 +199,19 @@ const Dashboard = () => {
const navigateToInvitation = () => {
window.location.href = pathRoutes.ecosystem.sentinvitation;
};
const [isAccess, setIsAccess] = useState(false);

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemLead(Boolean(data));
};
const checkEcosystemAccess = async () => {
const data = await getOwnerAdminRole();
setIsAccess(data);
};
useEffect(() => {
getDashboardData();

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemLead(data.isEcosystemLead);
};
checkEcosystemAccess()
checkEcosystemData();
}, []);

Expand Down Expand Up @@ -330,7 +336,8 @@ const Dashboard = () => {
<div className="inline-flex items-center ml-auto absolute top-0 right-0">
<Button
onClick={navigateToInvitation}
className='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"'
className={`${isAccess ? "hover:bg-primary-800 dark:hover:text-primary-700 dark:hover:bg-primary-700" : ""} hover:!bg-primary-800 text-base font-medium text-center text-white bg-primary-700 rounded-lg focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:focus:ring-primary-800 mr-3`}
disabled={loading || !isAccess}
>
<svg
className="pr-2"
Expand All @@ -347,7 +354,7 @@ const Dashboard = () => {
</svg>
Invitations
</Button>
{dropdownOpen ? (
{dropdownOpen && isAccess ? (
<Dropdown
label={'test'}
renderTrigger={() => (
Expand All @@ -373,7 +380,7 @@ const Dashboard = () => {
</Dropdown>
) : (
<svg
className="ml-4 w-4 h-4 text-gray-800 cursor-pointer dark:text-white"
className="ml-4 w-4 h-4 text-gray-800 dark:text-white cursor-not-allowed"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
Expand Down
96 changes: 54 additions & 42 deletions src/components/Ecosystem/Endorsement/EndorsementPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Button, Modal, Spinner } from 'flowbite-react';
import { Button, Modal } from 'flowbite-react';
import { EndorsementStatus, EndorsementType } from '../../../common/enums';
import {
ICheckEcosystem,
checkEcosystem,
getEcosystemId,
getOwnerAdminRole,
} from '../../../config/ecosystem';
import EndorsementCard from './EndorsementCard';
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant';
import { RejectEndorsementRequest, SignEndorsementRequest, SubmitEndorsementRequest } from '../../../api/ecosystem';
import {
RejectEndorsementRequest,
SignEndorsementRequest,
SubmitEndorsementRequest,
} from '../../../api/ecosystem';
import type { AxiosResponse } from 'axios';
import { AlertComponent } from '../../AlertComponent';
import { getFromLocalStorage } from '../../../api/Auth';
Expand All @@ -25,17 +30,24 @@ const EndorsementPopup = (props: {
const [loadingReject, setLoadingReject] = useState<boolean>(false);
const [errMsg, setErrMsg] = useState<string | null>(null);
const [isEcosystemData, setIsEcosystemData] = useState<ICheckEcosystem>();
const [isAccess, setIsAccess] = useState(false);

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemData(data);
};
const checkEcosystemAccess = async () => {
const data = await getOwnerAdminRole();
setIsAccess(data);
};

useEffect(() => {
const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemData(data);
};
checkEcosystemData();
checkEcosystemAccess();
}, [props?.openModal]);

useEffect(() => {
props.setMessage("");
props.setMessage('');
}, [props.onAlertClose]);

const SignEndorsement = async (endorsementId: string) => {
Expand Down Expand Up @@ -66,6 +78,7 @@ const EndorsementPopup = (props: {
const SubmitEndorsement = async (endorsementId: string) => {
try {
setLoading(true);
setLoadingReject(true);
const organizationId = await getFromLocalStorage(storageKeys.ORG_ID);
const ecoId = await getEcosystemId();
const SubmitEndorsementrequest = await SubmitEndorsementRequest(
Expand All @@ -84,6 +97,7 @@ const EndorsementPopup = (props: {
setLoading(false);
} catch (error) {
setLoading(false);
setLoadingReject(false);
console.error('Error while Submit schema:', error);
}
};
Expand Down Expand Up @@ -115,16 +129,29 @@ const EndorsementPopup = (props: {

return (
<Modal
className='h-full'
show={props.openModal} onClose={() => {
props.closeModal()
setErrMsg(null)
}} size="xl">
className="h-full"
show={props.openModal}
onClose={() => {
props.closeModal();
setErrMsg(null);
}}
size="xl"
>
<Modal.Header>
{isEcosystemData?.isEcosystemLead ? (
<div>Requested {props.endorsementData?.type === EndorsementType.credDef ? "Credential Definition" : "Schema" }</div>
<div>
Requested{' '}
{props.endorsementData?.type === EndorsementType.credDef
? 'Credential Definition'
: 'Schema'}
</div>
) : (
<div>View {props.endorsementData?.type === EndorsementType.credDef ? "Credential Definition" : "Schema"}</div>
<div>
View{' '}
{props.endorsementData?.type === EndorsementType.credDef
? 'Credential Definition'
: 'Schema'}
</div>
)}
</Modal.Header>
<div className="mt-3 mx-3 -mb-3">
Expand All @@ -145,23 +172,13 @@ const EndorsementPopup = (props: {
<div className="justify-between">
<div className="flex justify-end">
{isEcosystemData?.isEcosystemLead &&
props.endorsementData?.status === EndorsementStatus.requested ? (
props.endorsementData?.status === EndorsementStatus.requested ? (
<div className="flex gap-3 pt-1 pb-3">
<button
<Button
onClick={() => RejectEndorsement(props.endorsementData.id)}
disabled={loadingReject}
className="hover:bg-secondary-700 !ring-2 dark:text-white text-primary-700 font-medium rounded-lg text-sm dark:hover:text-primary-700 "
disabled={loading || !isAccess || loadingReject}
className={`${isAccess ? "hover:bg-secondary-700 hover:!bg-secondary-700 dark:hover:text-primary-700 dark:hover:bg-secondary-700" : ""} h-12 text-base font-medium text-center !ring-2 dark:text-white text-primary-700 rounded-md bg-white sm:w-auto dark:bg-primary-600 dark:focus:ring-primary-800 mr-3`}
>
<span className='flex items-center rounded-md text-sm px-4 py-2'>
{
loadingReject &&
<Spinner
className='mr-2'
color={'info'}
size={'md'}

/>
}
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
Expand All @@ -179,14 +196,13 @@ const EndorsementPopup = (props: {
/>
</svg>
<span className="ml-2 mr-2">Decline</span>
</span>
</button>
</Button>

<Button
isProcessing={loading}
color="bg-primary-800"
disabled={loading}
className="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 mr-3"
disabled={loading || !isAccess || loadingReject}
className={`${isAccess ? "hover:bg-primary-800 dark:hover:text-primary-700 dark:hover:bg-primary-700" : ""} text-base font-medium text-center text-white bg-primary-700 rounded-lg focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:focus:ring-primary-800 mr-3`}
onClick={() => {
SignEndorsement(props.endorsementData.id);
}}
Expand All @@ -204,16 +220,14 @@ const EndorsementPopup = (props: {
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span className='ml-2 mr-2'>
Endorse
</span>
<span className="ml-2 mr-2">Endorse</span>
</Button>
</div>
) : (
<>
{!isEcosystemData?.isEcosystemLead &&
isEcosystemData?.isEcosystemMember &&
props.endorsementData?.status === EndorsementStatus.signed ? (
isEcosystemData?.isEcosystemMember &&
props.endorsementData?.status === EndorsementStatus.signed ? (
<div className="flex gap-3 pt-1 pb-3">
<Button
isProcessing={loading}
Expand All @@ -237,9 +251,7 @@ const EndorsementPopup = (props: {
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span className='ml-2 mr-2'>
Submit
</span>
<span className="ml-2 mr-2">Submit</span>
</Button>
</div>
) : (
Expand Down Expand Up @@ -273,7 +285,7 @@ const EndorsementPopup = (props: {
)}
</div>
</div>
</Modal >
</Modal>
);
};

Expand Down
14 changes: 12 additions & 2 deletions src/components/EcosystemInvite/SentInvitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import RoleViewButton from '../RoleViewButton';
import SendInvitationModal from '../organization/invitations/SendInvitationModal';
import { getFromLocalStorage } from '../../api/Auth';
import { Features } from '../../utils/enums/features';
import { getOwnerAdminRole } from '../../config/ecosystem';
import { OrganizationRoles } from '../../common/enums';

const initialPageState = {
pageNumber: 1,
Expand All @@ -32,14 +34,20 @@ const SentInvitations = () => {
useState<Array<Invitation> | null>(null);
const [ecosystemId, setEcosystemId] = useState<string>('');
const [openModal, setOpenModal] = useState<boolean>(false);

const [isAccess, setIsAccess] = useState(false);

const onPageChange = (page: number) => {
setCurrentPage({
...currentPage,
pageNumber: page,
});
};

const checkEcosystemAccess = async () => {
const data = await getOwnerAdminRole(OrganizationRoles.organizationOwner);
setIsAccess(data);
};

const getAllSentInvitations = async () => {
const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID);
setEcosystemId(ecosystemId);
Expand Down Expand Up @@ -94,6 +102,7 @@ const SentInvitations = () => {
} else {
getAllSentInvitations();
}
checkEcosystemAccess();
return () => clearTimeout(getData);
}, [searchText, currentPage.pageNumber]);

Expand All @@ -110,7 +119,7 @@ const SentInvitations = () => {
</h1>
<div className="inline-flex items-center ml-auto">
<SendInvitationModal
getAllSentInvitations={getAllSentInvitations}
getAllSentInvitations={getAllSentInvitations}
flag={true}
ecosystemId={ecosystemId}
openModal={openModal}
Expand Down Expand Up @@ -249,6 +258,7 @@ const SentInvitations = () => {
onClick={() => deletInvitations(invitation.id)}
color="bg-white"
className="ml-5 font-normal items-center mt-5 text-xl text-primary-700 border border-blue-700 text-center hover:!bg-primary-800 hover:text-white rounded-lg focus:ring-4 focus:ring-primary-300 sm:w-auto dark:hover:bg-primary-700 dark:text-white dark:bg-primary-700 dark:focus:ring-blue-800"
disabled={!isAccess}
>
<svg
className="w-6 h-6"
Expand Down
Loading

0 comments on commit d56f5aa

Please sign in to comment.