Skip to content

Commit

Permalink
feat: accept reject and delete invitation for ecosystem
Browse files Browse the repository at this point in the history
Signed-off-by: karan <[email protected]>
  • Loading branch information
16-karan committed Oct 10, 2023
1 parent 357eae6 commit 2754ba6
Show file tree
Hide file tree
Showing 8 changed files with 810 additions and 246 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
}
}
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
113 changes: 95 additions & 18 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@ import checkEcosystem from '../../config/ecosystem';
import RoleViewButton from '../RoleViewButton';
import SendInvitationModal from '../organization/invitations/SendInvitationModal';
import { setToLocalStorage } from '../../api/Auth';
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 [error, setError] = useState<string | null>(null);
const [ecosystemId, setEcosystemId] = useState('');
const [openModal, setOpenModal] = useState<boolean>(false);
const [viewButton, setViewButton] = useState<boolean>(false);
const [currentPage, setCurrentPage] = useState(initialPageState);

const props = { openModal, setOpenModal };

const createEcosystemModel = () => {
Expand All @@ -37,30 +48,63 @@ const Dashboard = () => {
props.setOpenModal(true);
};


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;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const ecosystemData = data?.data[0]
await setToLocalStorage(storageKeys.ECOSYSTEM_ID,ecosystemData?.id)
setEcosystemId(ecosystemData?.id)
setEcosystemDetails({
logoUrl: ecosystemData.logoUrl,
name: ecosystemData.name,
description: ecosystemData.description
})
} else {
setFailure(response as string)
}
setLoading(false)
}
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const ecosystemData = data?.data[0];
await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id);
setEcosystemId(ecosystemData?.id);
setEcosystemDetails({
logoUrl: ecosystemData.logoUrl,
name: ecosystemData.name,
description: ecosystemData.description,
});
} else {
setFailure(response as string);
}
setLoading(false);
};

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

const { isEcosystemLead } = checkEcosystem();
Expand All @@ -70,6 +114,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 @@ -80,6 +152,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
Loading

0 comments on commit 2754ba6

Please sign in to comment.