Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/credebl/studio into edit…
Browse files Browse the repository at this point in the history
…-ecosystem-modal

Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Oct 10, 2023
2 parents 3e534ff + 4e4796c commit 1365df3
Show file tree
Hide file tree
Showing 13 changed files with 810 additions and 411 deletions.
92 changes: 89 additions & 3 deletions src/api/invitations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { axiosGet, axiosPost } from "../services/apiRequests"
import { axiosDelete, axiosGet, axiosPost } from "../services/apiRequests"

import { apiRoutes } from "../config/apiRoutes";
import { getFromLocalStorage } from "./Auth";
Expand Down Expand Up @@ -149,6 +149,34 @@ export const getUserInvitations = async (pageNumber: number, pageSize: number, s
}
}


export const getUserEcosystemInvitations = async (pageNumber: number, pageSize: number, search: string) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID)

const url = `${apiRoutes.Ecosystem.root}/${orgId}${apiRoutes.Ecosystem.usersInvitation}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`

const token = await getFromLocalStorage(storageKeys.TOKEN)

const config = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
const axiosPayload = {
url,
config
}

try {
return await axiosGet(axiosPayload);
}
catch (error) {
const err = error as Error
return err?.message
}
}

// getEcosytemReceivedInvitations
export const getEcosytemReceivedInvitations = async (pageNumber: number, pageSize: number, search = '') => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
Expand Down Expand Up @@ -178,6 +206,7 @@ export const getEcosytemReceivedInvitations = async (pageNumber: number, pageSiz
}
export const getEcosystemInvitations = async (pageNumber: number, pageSize: number, search:string) => {
const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID);

const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}`

Expand All @@ -204,9 +233,9 @@ export const getEcosystemInvitations = async (pageNumber: number, pageSize: numb
}

// Accept/ Reject Invitations
export const acceptRejectInvitations = async (invitationId: number,orgId: number, status: string) => {
export const acceptRejectEcosystemInvitations = async (invitationId: number,orgId: number, status: string) => {

const url = `${apiRoutes.users.invitations}/${invitationId}`
const url = `${apiRoutes.Ecosystem.root}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}`

const payload = {
orgId: Number(orgId),
Expand Down Expand Up @@ -235,4 +264,61 @@ export const acceptRejectInvitations = async (invitationId: number,orgId: number
}
}

export const acceptRejectInvitations = async (invitationId: number,orgId: number, status: string) => {

const url = `${apiRoutes.users.invitations}/${invitationId}`

const payload = {
orgId: Number(orgId),
status
}
const token = await getFromLocalStorage(storageKeys.TOKEN)

const config = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
const axiosPayload = {
url,
payload,
config
}

try {
return await axiosPost(axiosPayload);
}
catch (error) {
const err = error as Error
return err?.message
}
}

export const deleteEcosystemInvitations = async (invitationId: number) => {

const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID);
const orgId = await getFromLocalStorage(storageKeys.ORG_ID)
const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}`

const token = await getFromLocalStorage(storageKeys.TOKEN)

const config = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
const axiosPayload = {
url,
config
}

try {
return await axiosDelete(axiosPayload);
}
catch (error) {
const err = error as Error
return err?.message
}
}
2 changes: 1 addition & 1 deletion src/app/SideBar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import { pathRoutes } from '../config/pathRoutes';
<ul id="dropdown-ecosystems" class="py-2 space-y-2">
<li>
<a
href={pathRoutes.ecosystem.profile}
href={pathRoutes.ecosystem.root}
class="flex items-center p-2 text-base text-gray-900 transition duration-75 rounded-lg pl-11 group hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-700"
>
<svg
Expand Down
1 change: 0 additions & 1 deletion src/components/AlertComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Alert } from 'flowbite-react';
import { pathRoutes } from '../../config/pathRoutes';

export const AlertComponent = ({ message, type, viewButton, onAlertClose, path='' }: { message: string | null, type: string, viewButton?: boolean, path?:string, onAlertClose: () => void }) => {

Expand Down
89 changes: 82 additions & 7 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,29 @@ import SendInvitationModal from '../organization/invitations/SendInvitationModal
import { setToLocalStorage } from '../../api/Auth';
import { Dropdown } from 'flowbite-react';
import EditPopupModal from '../EditEcosystemOrgModal';
import { getEcosytemReceivedInvitations } from '../../api/invitations';
import { pathRoutes } from '../../config/pathRoutes';

const initialPageState = {
pageNumber: 1,
pageSize: 10,
total: 0,
};

const Dashboard = () => {
const [ecosystemDetails, setEcosystemDetails] = useState<IEcosystem | null>();

const [success, setSuccess] = useState<string | null>(null);
const [failure, setFailure] = useState<string | null>(null);
const [message, setMessage] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean | null>(true);
const [ecosystemId, setEcosystemId] = useState('')
const [openModal, setOpenModal] = useState<boolean>(false);
const [editOpenModal, setEditOpenModal] = useState<boolean>(false);
const [dropdownOpen, setDropdownOpen] = useState(false);

const [error, setError] = useState<string | null>(null);
const [openModal, setOpenModal] = useState<boolean>(false);
const [viewButton, setViewButton] = useState<boolean>(false);
const [currentPage, setCurrentPage] = useState(initialPageState);

const createEcosystemModel = () => {
setOpenModal(true);
};
Expand All @@ -49,8 +59,41 @@ const Dashboard = () => {
setDropdownOpen(false); // Close the dropdown when the edit modal is closed
};

const fetchEcosystemDetails = async () => {
const getAllEcosystemInvitations = async () => {
setLoading(true);
const response = await getEcosytemReceivedInvitations(
currentPage.pageNumber,
currentPage.pageSize,
''
);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const totalPages = data?.data?.totalPages;

const invitationList = data?.data;
const ecoSystemName = invitationList.map((invitations: { name: string; })=>{
return invitations.name
})
const invitationPendingList = data?.data?.invitations.filter((invitation: { status: string; })=>{
return invitation.status === 'pending'
})

if (invitationPendingList.length > 0) {
setMessage(`You have received invitation to join ${ecoSystemName} ecosystem `)
setViewButton(true);
}
setCurrentPage({
...currentPage,
total: totalPages,
});
} else {
setError(response as string);
}
setLoading(false);
};

const fetchEcosystemDetails = async () => {
setLoading(true);
const response = await getEcosystem();
const { data } = response as AxiosResponse;
Expand All @@ -72,6 +115,7 @@ const Dashboard = () => {

useEffect(() => {
fetchEcosystemDetails();
getAllEcosystemInvitations();
}, []);

const { isEcosystemLead } = checkEcosystem();
Expand All @@ -81,6 +125,34 @@ const Dashboard = () => {
<div className="mb-4 col-span-full xl:mb-2">
<BreadCrumbs />
</div>

{
error ? <> {(success || failure) && (
<AlertComponent
message={success ?? failure}
type={success ? 'success' : 'failure'}
onAlertClose={() => {
setSuccess(null);
setFailure(null);
}}
/>
)}
</>
:
<>
<div className="cursor-pointer">
{<AlertComponent
message={message ? message : error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={pathRoutes.ecosystem.invitation}
onAlertClose={() => {
setMessage(null);
setError(null);
}}
/>}
</div>

{(success || failure) && (
<AlertComponent
message={success ?? failure}
Expand All @@ -91,6 +163,11 @@ const Dashboard = () => {
}}
/>
)}


</>
}

{ecosystemDetails ? (
<div>
<div className="mt-4 flex flex-wrap items-center justify-between p-4 bg-white border border-gray-200 rounded-lg shadow-sm sm:flex dark:border-gray-700 sm:p-6 dark:bg-gray-800">
Expand Down Expand Up @@ -148,7 +225,7 @@ const Dashboard = () => {
/>
<Dropdown
label={"test"}
open={dropdownOpen} // Pass the open state here
open={dropdownOpen}
onToggle={() => setDropdownOpen(!dropdownOpen)}
renderTrigger={() => <svg
className="ml-4 w-4 h-4 text-gray-800 cursor-pointer dark:text-white"
Expand Down Expand Up @@ -224,8 +301,6 @@ const Dashboard = () => {
setOpenModal={setEditOpenModal}
setMessage={(value) => {
setSuccess(value);
// setDropdownOpen(false);

}}
isOrganization={false}
onEditSuccess={handleEditModalClose}
Expand Down
81 changes: 81 additions & 0 deletions src/components/EcosystemInvite/EcoInvitationList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

import React from 'react';

interface InvitationProps{
invitationId:string;
invitationEmail:string
ecosytem:[]
}

const EcoInvitationList = (props: InvitationProps ) => {

const {invitationId, invitationEmail,ecosytem} = props

return (
<>
<div className="flex space-x-4">
<svg
width="60"
height="60"
viewBox="0 0 398 398"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clip-path="url(#clip0_3892_5729)">
<path
d="M350.828 117.051V166.651L382.328 143.251L350.828 117.051Z"
fill="#6B7280"
/>
<path
d="M217.922 6.9502C206.822 -2.2498 190.722 -2.3498 179.622 6.8502L166.922 17.6502H230.822L217.922 6.9502Z"
fill="#6B7280"
/>
<path
d="M228.629 282.451C220.029 288.851 209.629 292.351 198.929 292.251C188.229 292.251 177.729 288.851 169.129 282.451L9.82869 163.551V367.451C9.72869 383.951 23.0287 397.451 39.5287 397.551H358.029C374.529 397.451 387.829 383.951 387.729 367.451V163.551L228.629 282.451Z"
fill="#6B7280"
/>
<path
d="M15.3281 143.249L45.8281 165.949V117.949L15.3281 143.249Z"
fill="#6B7280"
/>
<path
d="M65.8281 37.6484V180.848L180.828 266.448C191.528 274.248 206.228 274.248 216.928 266.448L330.828 181.548V37.6484H65.8281ZM136.828 117.648H190.828C196.328 117.648 200.828 122.148 200.828 127.648C200.828 133.148 196.328 137.648 190.828 137.648H136.828C131.328 137.648 126.828 133.148 126.828 127.648C126.828 122.148 131.328 117.648 136.828 117.648ZM260.828 187.648H136.828C131.328 187.648 126.828 183.148 126.828 177.648C126.828 172.148 131.328 167.648 136.828 167.648H260.828C266.328 167.648 270.828 172.148 270.828 177.648C270.828 183.148 266.328 187.648 260.828 187.648Z"
fill="#6B7280"
/>
</g>
<defs>
<clipPath id="clip0_3892_5729">
<rect width="397.55" height="397.55" fill="white" />
</clipPath>
</defs>
</svg>

<div className="flex-1 min-w-0">
<p className="text-base font-semibold text-gray-900 leading-none truncate mb-0.5 dark:text-white">
{invitationEmail}
</p>

<div className="flow-root h-auto">
<ul className="divide-y divide-gray-200 dark:divide-gray-700">
<li className="pt-3 sm:pt-3 overflow-auto">
<div className="items-center space-x-4">
<div className="inline-flex items-center text-base font-normal text-gray-900 dark:text-white">
Roles:
<span
key={invitationId}
className="m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300"
>
Ecosystem Member
</span>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</>
);
};

export default EcoInvitationList;
Loading

0 comments on commit 1365df3

Please sign in to comment.