fix: navigation bugs

This commit is contained in:
swve 2023-01-29 19:28:48 +01:00
parent 898928759d
commit aeebcf1d63
4 changed files with 22 additions and 7 deletions

View file

@ -6,6 +6,7 @@ import { createCollection } from "@services/collections";
import useSWR from "swr"; import useSWR from "swr";
import { getAPIUrl } from "@services/config"; import { getAPIUrl } from "@services/config";
import { swrFetcher } from "@services/utils/requests"; import { swrFetcher } from "@services/utils/requests";
import { getOrganizationContextInfo } from "@services/orgs";
function NewCollection(params : any) { function NewCollection(params : any) {
const orgslug = params.params.orgslug; 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); 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<HTMLInputElement>) => { const handleNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setName(event.target.value); setName(event.target.value);
}; };

View file

@ -4,7 +4,7 @@ import React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { Title } from "@components/UI/Elements/Styles/Title"; import { Title } from "@components/UI/Elements/Styles/Title";
import { deleteCollection } from "@services/collections"; 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 { swrFetcher } from "@services/utils/requests";
import useSWR, { mutate } from "swr"; import useSWR, { mutate } from "swr";
@ -21,7 +21,7 @@ function Collections(params: any) {
<> <>
<Title> <Title>
{orgslug} Collections :{" "} {orgslug} Collections :{" "}
<Link href={"/collections/new"}> <Link href={getUriWithOrg(orgslug, "/collections/new")}>
<button>+</button> <button>+</button>
</Link>{" "} </Link>{" "}
</Title> </Title>

View file

@ -17,7 +17,7 @@ const Organizations = () => {
} }
return ( return (
<Layout> <>
<Title> <Title>
Your Organizations{" "} Your Organizations{" "}
<Link href={"/organizations/new"}> <Link href={"/organizations/new"}>
@ -40,7 +40,7 @@ const Organizations = () => {
))} ))}
</div> </div>
)} )}
</Layout> </>
); );
}; };

View file

@ -5,11 +5,17 @@ export const getAPIUrl = () => LEARNHOUSE_API_URL;
export const getBackendUrl = () => LEARNHOUSE_BACKEND_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}`; return `http://localhost:3000/org/${orgslug}${path}`;
}; };
export const getOrgFromUri = (uri: any) => { export const getOrgFromUri = (uri: any) => {
let org = uri.match(/\/org\/([\w]+)/)[1]; // if url contains /org
return org; if (uri.includes("/org/")) {
let org = uri.match(/\/org\/([\w]+)/)[1];
return org;
}
else {
return "";
}
}; };