diff --git a/front/pages/organizations/new.tsx b/front/pages/organizations/new.tsx index 0fbf48f3..a31ce0ac 100644 --- a/front/pages/organizations/new.tsx +++ b/front/pages/organizations/new.tsx @@ -1,13 +1,45 @@ -import React from 'react' -import Layout from '../../components/ui/layout' -import { Title } from '../../components/ui/styles/title' +import React from "react"; +import Layout from "../../components/ui/layout"; +import { Title } from "../../components/ui/styles/title"; +import { createNewOrganization } from "../../services/orgs"; const Organizations = () => { + const [name, setName] = React.useState(""); + const [description, setDescription] = React.useState(""); + const [email, setEmail] = React.useState(""); + + const handleNameChange = (e: any) => { + setName(e.target.value); + }; + + const handleDescriptionChange = (e: any) => { + setDescription(e.target.value); + }; + + const handleEmailChange = (e: any) => { + setEmail(e.target.value); + }; + + const handleSubmit = async (e: any) => { + e.preventDefault(); + console.log({ name, description, email }); + const status = await createNewOrganization({ name, description, email }); + alert(JSON.stringify(status)); + + }; + return ( - New Organization + New Organization + Name: +
+ Description: +
+ Email Address: +
+
- ) -} + ); +}; -export default Organizations \ No newline at end of file +export default Organizations; diff --git a/front/services/orgs.ts b/front/services/orgs.ts index e1d3ea44..62ec3049 100644 --- a/front/services/orgs.ts +++ b/front/services/orgs.ts @@ -15,11 +15,25 @@ export async function getUserOrganizations() { .catch((error) => console.log("error", error)); } -// export async function createNewOrganization(user_id) {} +export async function createNewOrganization(body: any) { + const HeadersConfig = new Headers({ "Content-Type": "application/json" }); + + const requestOptions: any = { + method: "POST", + headers: HeadersConfig, + redirect: "follow", + credentials: "include", + body: JSON.stringify(body), + }; + + return fetch(`${getAPIUrl()}orgs/`, requestOptions) + .then((result) => result.json()) + .catch((error) => console.log("error", error)); +} // export async function getOrganizationData(org_id) {} -export async function deleteOrganizationFromBackend(org_id:any) { +export async function deleteOrganizationFromBackend(org_id: any) { const HeadersConfig = new Headers({ "Content-Type": "application/json" }); const requestOptions: any = {