From aeebcf1d63f95323b35f66ce4b3f8bb1940f394d Mon Sep 17 00:00:00 2001 From: swve Date: Sun, 29 Jan 2023 19:28:48 +0100 Subject: [PATCH] fix: navigation bugs --- front/app/_orgs/[orgslug]/collections/new/page.tsx | 9 +++++++++ front/app/_orgs/[orgslug]/collections/page.tsx | 4 ++-- front/app/organizations/page.tsx | 4 ++-- front/services/config.ts | 12 +++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/front/app/_orgs/[orgslug]/collections/new/page.tsx b/front/app/_orgs/[orgslug]/collections/new/page.tsx index 171c25ef..7e766919 100644 --- a/front/app/_orgs/[orgslug]/collections/new/page.tsx +++ b/front/app/_orgs/[orgslug]/collections/new/page.tsx @@ -6,6 +6,7 @@ import { createCollection } from "@services/collections"; import useSWR from "swr"; import { getAPIUrl } from "@services/config"; import { swrFetcher } from "@services/utils/requests"; +import { getOrganizationContextInfo } from "@services/orgs"; function NewCollection(params : any) { const orgslug = params.params.orgslug; @@ -17,6 +18,14 @@ function NewCollection(params : any) { const { data: courses, error: error } = useSWR(`${getAPIUrl()}courses/org_slug/${orgslug}/page/1/limit/10`, swrFetcher); + React.useEffect(() => { + async function getOrg() { + const org = await getOrganizationContextInfo(orgslug); + setOrg(org); + } + getOrg(); + }, []); + const handleNameChange = (event: React.ChangeEvent) => { setName(event.target.value); }; diff --git a/front/app/_orgs/[orgslug]/collections/page.tsx b/front/app/_orgs/[orgslug]/collections/page.tsx index 9c1bfb2b..f2c11b26 100644 --- a/front/app/_orgs/[orgslug]/collections/page.tsx +++ b/front/app/_orgs/[orgslug]/collections/page.tsx @@ -4,7 +4,7 @@ import React from "react"; import styled from "styled-components"; import { Title } from "@components/UI/Elements/Styles/Title"; import { deleteCollection } from "@services/collections"; -import { getAPIUrl, getBackendUrl } from "@services/config"; +import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config"; import { swrFetcher } from "@services/utils/requests"; import useSWR, { mutate } from "swr"; @@ -21,7 +21,7 @@ function Collections(params: any) { <> {orgslug} Collections :{" "} - <Link href={"/collections/new"}> + <Link href={getUriWithOrg(orgslug, "/collections/new")}> <button>+</button> </Link>{" "} diff --git a/front/app/organizations/page.tsx b/front/app/organizations/page.tsx index f48e39be..1d7571d5 100644 --- a/front/app/organizations/page.tsx +++ b/front/app/organizations/page.tsx @@ -17,7 +17,7 @@ const Organizations = () => { } return ( - + <> Your Organizations{" "} <Link href={"/organizations/new"}> @@ -40,7 +40,7 @@ const Organizations = () => { ))} </div> )} - </Layout> + </> ); }; diff --git a/front/services/config.ts b/front/services/config.ts index 11d4f217..dce3e900 100644 --- a/front/services/config.ts +++ b/front/services/config.ts @@ -5,11 +5,17 @@ export const getAPIUrl = () => LEARNHOUSE_API_URL; export const getBackendUrl = () => LEARNHOUSE_BACKEND_URL; -export const getUriWithOrg = ( orgslug: string, path: string) => { +export const getUriWithOrg = (orgslug: string, path: string) => { return `http://localhost:3000/org/${orgslug}${path}`; }; export const getOrgFromUri = (uri: any) => { - let org = uri.match(/\/org\/([\w]+)/)[1]; - return org; + // if url contains /org + if (uri.includes("/org/")) { + let org = uri.match(/\/org\/([\w]+)/)[1]; + return org; + } + else { + return ""; + } };