Skip to content

Commit

Permalink
feat:added edit ecosystem modal component
Browse files Browse the repository at this point in the history
Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Oct 10, 2023
1 parent 357eae6 commit 3e534ff
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 34 deletions.
11 changes: 7 additions & 4 deletions src/api/ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface DataPayload {
name: string
description: string
logo: string
tags: string
tags?: string
userId: number
}

Expand Down Expand Up @@ -41,10 +41,12 @@ export const createEcosystems = async (dataPayload: DataPayload) => {
}
}

export const updateEcosystem = async (data: object) => {
export const updateEcosystem = async (dataPayload: DataPayload) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Ecosystem.root}/${orgId}`
const payload = data
const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID);

const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}`
const payload = dataPayload
const token = await getFromLocalStorage(storageKeys.TOKEN)
const config = {
headers: {
Expand All @@ -67,6 +69,7 @@ export const updateEcosystem = async (data: object) => {
}
}


export const getEcosystem = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Ecosystem.root}/${orgId}`
Expand Down
103 changes: 75 additions & 28 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import checkEcosystem from '../../config/ecosystem';
import RoleViewButton from '../RoleViewButton';
import SendInvitationModal from '../organization/invitations/SendInvitationModal';
import { setToLocalStorage } from '../../api/Auth';
import { Dropdown } from 'flowbite-react';
import EditPopupModal from '../EditEcosystemOrgModal';

const Dashboard = () => {
const [ecosystemDetails, setEcosystemDetails] = useState<IEcosystem | null>();
Expand All @@ -25,39 +27,48 @@ const Dashboard = () => {
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 [ecosystemId, setEcosystemId] = useState('')
const [openModal, setOpenModal] = useState<boolean>(false);
const props = { openModal, setOpenModal };
const [editOpenModal, setEditOpenModal] = useState<boolean>(false);
const [dropdownOpen, setDropdownOpen] = useState(false);

const createEcosystemModel = () => {
props.setOpenModal(true);
setOpenModal(true);
};

const createInvitationsModel = () => {
props.setOpenModal(true);
setOpenModal(true);
};


const EditEcosystemOrgModal = () => {
setEditOpenModal(true);
};

const handleEditModalClose = () => {
setEditOpenModal(false);
setDropdownOpen(false); // Close the dropdown when the edit modal is closed
};

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();
Expand Down Expand Up @@ -111,9 +122,9 @@ const Dashboard = () => {
<SendInvitationModal
ecosystemId={ecosystemId}
flag={true}
openModal={props.openModal}
openModal={openModal}
setMessage={(data) => setMessage(data)}
setOpenModal={props.setOpenModal}
setOpenModal={setOpenModal}
/>
<RoleViewButton
buttonTitle="Invite"
Expand All @@ -135,17 +146,39 @@ const Dashboard = () => {
}
onClickEvent={createInvitationsModel}
/>
<div className="ml-4">
<svg
className="w-6 h-6 text-gray-800 cursor-pointer dark:text-white"
<Dropdown
label={"test"}
open={dropdownOpen} // Pass the open state here
onToggle={() => setDropdownOpen(!dropdownOpen)}
renderTrigger={() => <svg
className="ml-4 w-4 h-4 text-gray-800 cursor-pointer dark:text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 4 15"

>
<path d="M3.5 1.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm0 6.041a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm0 5.959a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z" />
</svg>
</div>
</svg>}
>
<Dropdown.Item onClick={EditEcosystemOrgModal}>
<div>
Edit Ecosystem
</div>
</Dropdown.Item>
<Dropdown.Item>
<div>
Enable/Disable Ecosystem
</div>
</Dropdown.Item>
<Dropdown.Item>
<div>
Manual Registration
</div>
</Dropdown.Item>


</Dropdown>
</div>
)}
</div>
Expand Down Expand Up @@ -186,6 +219,18 @@ const Dashboard = () => {
<div className="mt-4 p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<MemberList />
</div>
<EditPopupModal
openModal={editOpenModal}
setOpenModal={setEditOpenModal}
setMessage={(value) => {
setSuccess(value);
// setDropdownOpen(false);

}}
isOrganization={false}
onEditSuccess={handleEditModalClose}
entityData={ecosystemDetails}
/>
</>
)}
</div>
Expand All @@ -200,13 +245,14 @@ const Dashboard = () => {
<div className="flex items-center justify-center mb-4">
<CreateEcosystemOrgModal
openModal={openModal}
setOpenModal={props.setOpenModal}
setOpenModal={setOpenModal}
setMessage={(value) => {
setSuccess(value);
fetchEcosystemDetails();
}}
isorgModal={false}
/>

<EmptyListMessage
message={'No Ecosystem found'}
description={'Get started by creating an ecosystem'}
Expand All @@ -233,6 +279,7 @@ const Dashboard = () => {
)}
</div>
)}

</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Ecosystem/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface Ecosystem {
logoUrl: string
website: string
roles: string[]
logoFile:string
}
Loading

0 comments on commit 3e534ff

Please sign in to comment.