Skip to content

Commit

Permalink
refactor:create and edit ecosystem api
Browse files Browse the repository at this point in the history
Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Oct 3, 2023
1 parent bad553f commit 2ead2eb
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 373 deletions.
26 changes: 26 additions & 0 deletions src/api/ecosystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ export const createEcosystems = async (data: object) => {
}
}

export const updateEcosystem = async (data: object, orgId:string) => {

const url = `${apiRoutes.organizations.update}/${orgId}`
const payload = data
const token = await getFromLocalStorage(storageKeys.TOKEN)

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

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



Expand Down
8 changes: 3 additions & 5 deletions src/components/Ecosystems/CreateEcosystems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getFromLocalStorage } from "../../api/Auth";
interface Values {
name: string;
description: string;

}

interface ILogoImage {
Expand Down Expand Up @@ -139,11 +138,11 @@ try{
const ecoData = {
name: values.name,
description: values.description,
logo: logoImage?.imagePreviewUrl as string || "",
tag:"",
orgId: Number(organizationId),
userId:Number(user_data?.id)
}

const resCreateOrg = await createEcosystems(ecoData)

const { data } = resCreateOrg as AxiosResponse
Expand Down Expand Up @@ -243,11 +242,11 @@ try{
<div className="flex items-center space-x-4">

<div>
<label htmlFor="organizationlogo">
<label htmlFor="ecosystemlogo">
<div className="px-4 py-2 bg-primary-700 hover:bg-primary-800 text-white text-center rounded-lg">Choose file</div>
<input type="file" accept="image/*" name="file"
className="hidden"
id="organizationlogo" title=""
id="ecosystemlogo" title=""
onChange={(event): void => handleImageChange(event)} />
{/* <span>{selectedImage || 'No File Chosen'}</span> */}
{imgError ? <div className="text-red-500">{imgError}</div> : <span className="mt-1 text-sm text-gray-500 dark:text-gray-400">{logoImage.fileName || 'No File Chosen'}</span>}
Expand Down Expand Up @@ -327,5 +326,4 @@ try{
</Modal>
)
}

export default CreateEcosystems;
94 changes: 48 additions & 46 deletions src/components/Ecosystems/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,67 @@ const initialPageState = {
};

const Dashboard = () => {
const [openModal, setOpenModal,] = useState<boolean>(false);
const [editEcosystemModal, setEditEcosystemModal] = useState<boolean>(false);
const props = { openModal, setOpenModal, editEcosystemModal, setEditEcosystemModal };

const [openModal, setOpenModal,] = useState<boolean>(false);
const [editEcosystemModal, setEditEcosystemModal] = useState<boolean>(false);
const props = { openModal, setOpenModal, editEcosystemModal, setEditEcosystemModal };

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

const EditEcosystemsModel = () => {
props.setEditEcosystemModal(true); // Open the EditEcosystems modal
};
const createEcosystemModel = () => {
props.setOpenModal(true)
}

const EditEcosystemsModel = () => {
props.setEditEcosystemModal(true); // Open the EditEcosystems modal
};

return (
<div>
<div className="pl-6 mb-4 col-span-full xl:mb-2">
<div className="pl-6 mb-4 col-span-full xl:mb-2">
<button type="button" onClick={EditEcosystemsModel}> {/* Use EditEcosystemsModel */}
<svg aria-hidden="true" className="mr-1 -ml-1 w-5 h-5"
fill="currentColor" viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg" color='#3558A8'>
<path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z"></path>
<path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd"></path>
</svg>
</button>
<BreadCrumbs />
<h1 className="ml-1 text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">
Ecosystems
</h1>
</div>
<div
className="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"
>
<div className="flex items-center justify-center mb-4">
<svg aria-hidden="true" className="mr-1 -ml-1 w-5 h-5"
fill="currentColor" viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg" color='#3558A8'>
<path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z"></path>
<path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd"></path>
</svg>
</button>
<BreadCrumbs />
<h1 className="ml-1 text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">
Ecosystems
</h1>
</div>
<div
className="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"
>
<div className="flex items-center justify-center mb-4">

<EditEcosystems
openModal={props.editEcosystemModal}
// setMessage={(data) => setMessage(data)}
setOpenModal={props.setEditEcosystemModal} setMessage={function (message: string): void {
throw new Error('Function not implemented.');
} } EcoData={null} />
}} EcoData={null} />

<CreateEcosystems
openModal={props.openModal}
// setMessage={(data) => setMessage(data)}
setOpenModal={props.setOpenModal} setMessage={function (message: string): void {
throw new Error('Function not implemented.');
} } />
<CreateEcosystems
openModal={props.openModal}
// setMessage={(data) => setMessage(data)}
setOpenModal={props.setOpenModal} setMessage={function (message: string): void {
throw new Error('Function not implemented.');
}}
// EcoData={null}
/>

<EmptyListMessage
message={'No Ecosystem found'}
description={'Get started by creating an ecosystem'}
buttonContent={'Create Ecosystem'}
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
onClick={createEcosystemModel}
/>
</div>
</div>
<EmptyListMessage
message={'No Ecosystem found'}
description={'Get started by creating an ecosystem'}
buttonContent={'Create Ecosystem'}
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
onClick={createEcosystemModel}
/>
</div>
</div>
</div>
)
}
Expand Down
Loading

0 comments on commit 2ead2eb

Please sign in to comment.