Skip to content

Commit

Permalink
refactor:create 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 c005dbe commit bad553f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/api/ecosystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { storageKeys } from "../config/CommonConstant";

export const createEcosystems = async (data: object) => {

const url = apiRoutes.organizations.create
const url = apiRoutes.ecosystem.create
const payload = data
const token = await getFromLocalStorage(storageKeys.TOKEN)

Expand Down
25 changes: 18 additions & 7 deletions src/components/Ecosystems/CreateEcosystems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as yup from "yup"

import { Avatar, Button, Label, Modal } from 'flowbite-react';
import { Field, Form, Formik, FormikHelpers } from 'formik';
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, apiStatusCodes, imageSizeAccepted } from '../../config/CommonConstant'
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, apiStatusCodes, imageSizeAccepted, storageKeys } from '../../config/CommonConstant'
import { calculateSize, dataURItoBlob } from "../../utils/CompressImage";
import { useEffect, useRef, useState } from "react";

Expand All @@ -11,10 +11,12 @@ import type { AxiosResponse } from 'axios';
import { asset } from '../../lib/data.js';
import { createEcosystems } from "../../api/ecosystems";
import React from "react";
import { getFromLocalStorage } from "../../api/Auth";

interface Values {
name: string;
description: string;

}

interface ILogoImage {
Expand Down Expand Up @@ -129,16 +131,19 @@ const CreateEcosystems = (props: { openModal: boolean; setMessage: (message: str
}
}

const sumitCreateOrganization = async (values: Values) => {
const submitCreateEcosystem = async (values: Values) => {
try{
setLoading(true)

const user_data = JSON.parse(await getFromLocalStorage(storageKeys.USER_PROFILE))
const organizationId = await getFromLocalStorage(storageKeys.ORG_ID);
const ecoData = {
name: values.name,
description: values.description,
logo: logoImage?.imagePreviewUrl as string || "",
website: ""
tag:"",
orgId: Number(organizationId),
userId:Number(user_data?.id)
}

const resCreateOrg = await createEcosystems(ecoData)

const { data } = resCreateOrg as AxiosResponse
Expand All @@ -152,6 +157,12 @@ const CreateEcosystems = (props: { openModal: boolean; setMessage: (message: str
setErrMsg(resCreateOrg as string)
}
}
catch (error)
{
console.error("An error occurred:", error);
setLoading(false);
}
}
return (
<Modal show={props.openModal} onClose={() => {
setLogoImage({
Expand Down Expand Up @@ -196,7 +207,7 @@ const CreateEcosystems = (props: { openModal: boolean; setMessage: (message: str
{ resetForm }: FormikHelpers<Values>
) => {

sumitCreateOrganization(values)
submitCreateEcosystem(values)
}}
>
{(formikHandlers): JSX.Element => (
Expand Down
6 changes: 5 additions & 1 deletion src/config/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const apiRoutes = {
orgRoles: '/orgs/roles',
editUserROle: '/user-roles'
},

connection: {
create: '/connections',
},
Expand Down Expand Up @@ -69,5 +70,8 @@ export const apiRoutes = {
public:{
organizations: '/organization/public-profiles',
users:'/users/public-profiles',
}
},
ecosystem:{
create:'/ecosystem'
}
}

0 comments on commit bad553f

Please sign in to comment.