From 2ead2ebf45369abd9fbbb8aea3fa5f90bc015ca5 Mon Sep 17 00:00:00 2001 From: pranalidhanavade Date: Tue, 3 Oct 2023 19:18:21 +0530 Subject: [PATCH] refactor:create and edit ecosystem api Signed-off-by: pranalidhanavade --- src/api/ecosystems.ts | 26 ++ .../Ecosystems/CreateEcosystems.tsx | 8 +- src/components/Ecosystems/Dashboard.tsx | 94 +++---- .../Ecosystems/EcosystemDashboard.tsx | 247 ------------------ src/components/Ecosystems/EditEcosystems.tsx | 84 +----- .../organization/CreateOrgFormModal.tsx | 2 +- src/pages/ecosystems/index.astro | 3 +- 7 files changed, 91 insertions(+), 373 deletions(-) delete mode 100644 src/components/Ecosystems/EcosystemDashboard.tsx diff --git a/src/api/ecosystems.ts b/src/api/ecosystems.ts index c9944b326..d26382d04 100644 --- a/src/api/ecosystems.ts +++ b/src/api/ecosystems.ts @@ -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 + } +} diff --git a/src/components/Ecosystems/CreateEcosystems.tsx b/src/components/Ecosystems/CreateEcosystems.tsx index 3e2f3190f..aa9f1ed2b 100644 --- a/src/components/Ecosystems/CreateEcosystems.tsx +++ b/src/components/Ecosystems/CreateEcosystems.tsx @@ -16,7 +16,6 @@ import { getFromLocalStorage } from "../../api/Auth"; interface Values { name: string; description: string; - } interface ILogoImage { @@ -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 @@ -243,11 +242,11 @@ try{
-
- ) -} -} -export default EcosystemDashbaord; diff --git a/src/components/Ecosystems/EditEcosystems.tsx b/src/components/Ecosystems/EditEcosystems.tsx index ca57592dd..d55bb1226 100644 --- a/src/components/Ecosystems/EditEcosystems.tsx +++ b/src/components/Ecosystems/EditEcosystems.tsx @@ -8,7 +8,7 @@ import { useEffect, useState } from "react"; import { AlertComponent } from "../AlertComponent"; import type { AxiosResponse } from 'axios'; -import { updateOrganization } from "../../api/organization"; +import { updateEcosystem } from "../../api/ecosystems"; import type { Ecosystem } from "./interfaces"; import React from "react"; @@ -44,7 +44,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { const [isImageEmpty, setIsImageEmpty] = useState(true) const [isPublic, setIsPublic] = useState(true) - const [initialOrgData, setOrgData] = useState({ + const [initialEcoData, setEcoData] = useState({ name: props?.EcoData?.name || "", description: props?.EcoData?.description || "", website: props?.EcoData?.website || "", @@ -53,7 +53,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { useEffect(() => { if (props.EcoData) { - setOrgData({ + setEcoData({ name: props.EcoData.name || '', description: props.EcoData.description || '', website: props?.EcoData?.website || "", @@ -74,7 +74,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { useEffect(() => { if (props.openModal === false) { - setOrgData({ + setEcoData({ name: '', description: '', website:'' @@ -162,7 +162,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { } } - const submitUpdateOrganization = async (values: Values) => { + const submitUpdateEcosystem = async (values: Values) => { setLoading(true) @@ -175,7 +175,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { isPublic: isPublic } - const resUpdateOrg = await updateOrganization(EcoData, EcoData.orgId?.toString() as string) + const resUpdateOrg = await updateEcosystem(EcoData, EcoData.orgId?.toString() as string) const { data } = resUpdateOrg as AxiosResponse setLoading(false) @@ -197,7 +197,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { imagePreviewUrl: "", fileName: '' }) - setOrgData(initialOrgData) + setEcoData(initialEcoData) props.setOpenModal(false) } }> @@ -212,7 +212,7 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => { /> { values: Values, { resetForm }: FormikHelpers ) => { - submitUpdateOrganization(values) + submitUpdateEcosystem(values) }} > {(formikHandlers): JSX.Element => ( @@ -280,11 +280,11 @@ const EditEcosystemsModal = (props: EditEcosystemsModalProps) => {
-
- {/*
-
*/} - {/* */} +
- {/*
- -
-
-
- setIsPublic(false)} - id="private" - name="private" - /> - Private - Only the connected organization can see you organization details - -
-
-
-
- setIsPublic(true)} - checked={isPublic === true} - id="public" - name="public" - /> - - Public - Your profile and organization details can be seen by everyone -
-
*/} )} - diff --git a/src/components/organization/CreateOrgFormModal.tsx b/src/components/organization/CreateOrgFormModal.tsx index 2d57380b9..d2d74da56 100644 --- a/src/components/organization/CreateOrgFormModal.tsx +++ b/src/components/organization/CreateOrgFormModal.tsx @@ -10,6 +10,7 @@ import { AlertComponent } from "../AlertComponent"; import type { AxiosResponse } from 'axios'; import { asset } from '../../lib/data.js'; import { createOrganization } from "../../api/organization"; +import React from "react"; interface Values { name: string; @@ -138,7 +139,6 @@ const CreateOrgFormModal = (props: { openModal: boolean; setMessage: (message: s logo: logoImage?.imagePreviewUrl as string || "", website: "" } - const resCreateOrg = await createOrganization(orgData) const { data } = resCreateOrg as AxiosResponse diff --git a/src/pages/ecosystems/index.astro b/src/pages/ecosystems/index.astro index dc759a44e..bb9899381 100644 --- a/src/pages/ecosystems/index.astro +++ b/src/pages/ecosystems/index.astro @@ -3,7 +3,7 @@ import LayoutSidebar from '../../app/LayoutSidebar.astro'; import Dashboard from '../../components/Ecosystems/Dashboard'; import { checkUserSession } from '../../utils/check-session'; import { pathRoutes } from '../../config/pathRoutes'; -import EcosystemDashbaord from '../../components/Ecosystems/EcosystemDashboard'; + const response = await checkUserSession(Astro.cookies); const route: string = pathRoutes.auth.sinIn if (!response) { @@ -13,5 +13,4 @@ if (!response) { - \ No newline at end of file