From 72597fcda679966342431190b24c80308e1e09ad Mon Sep 17 00:00:00 2001 From: swve Date: Sun, 14 May 2023 16:54:28 +0000 Subject: [PATCH] fix: improve collection creation page --- .../(withmenu)/collections/new/page.tsx | 90 ++++++++++++------- front/app/organizations/page.tsx | 31 ++++--- 2 files changed, 78 insertions(+), 43 deletions(-) diff --git a/front/app/_orgs/[orgslug]/(withmenu)/collections/new/page.tsx b/front/app/_orgs/[orgslug]/(withmenu)/collections/new/page.tsx index 84421186..28185a44 100644 --- a/front/app/_orgs/[orgslug]/(withmenu)/collections/new/page.tsx +++ b/front/app/_orgs/[orgslug]/(withmenu)/collections/new/page.tsx @@ -8,7 +8,7 @@ import { getAPIUrl, getUriWithOrg } from "@services/config/config"; import { swrFetcher } from "@services/utils/ts/requests"; import { getOrganizationContextInfo } from "@services/organizations/orgs"; -function NewCollection(params : any) { +function NewCollection(params: any) { const orgslug = params.params.orgslug; const [name, setName] = React.useState(""); const [org, setOrg] = React.useState({}) as any; @@ -50,38 +50,64 @@ function NewCollection(params : any) { return ( <> - Add new -
- - {!courses ? ( -

Loading...

- ) : ( -
- {courses.map((course: any) => ( -
- { - if (e.target.checked) { - setSelectedCourses([...selectedCourses, e.target.value]); - } else { - setSelectedCourses(selectedCourses.filter((item: any) => item !== e.target.value)); - } - }} - /> - -
- ))} -
- )} +
+ Add new + + + +{!courses ? ( +

Loading...

+) : ( +
+ {courses.map((course: any) => ( +
+ { + const courseId = e.target.value; + setSelectedCourses((prevSelectedCourses: string[]) => { + if (e.target.checked) { + return [...prevSelectedCourses, courseId]; + } else { + return prevSelectedCourses.filter((selectedCourse) => selectedCourse !== courseId); + } + }); + }} + className="mr-2 focus:outline-none focus:ring-2 focus:ring-blue-500" + /> + +
+ ))} + +
+)} + + + + +
-
- -
- ); } diff --git a/front/app/organizations/page.tsx b/front/app/organizations/page.tsx index 312ec33b..84b3fb64 100644 --- a/front/app/organizations/page.tsx +++ b/front/app/organizations/page.tsx @@ -9,38 +9,47 @@ import { getAPIUrl, getUriWithOrg } from "@services/config/config"; import AuthProvider from "@components/Security/AuthProvider"; const Organizations = () => { - const { data : organizations , error } = useSWR(`${getAPIUrl()}orgs/user/page/1/limit/10`, swrFetcher) + const { data: organizations, error } = useSWR(`${getAPIUrl()}orgs/user/page/1/limit/10`, swrFetcher) async function deleteOrganization(org_id: any) { const response = await deleteOrganizationFromBackend(org_id); - response && mutate(`${getAPIUrl()}orgs/user/page/1/limit/10`, organizations.filter((org: any) => org.org_id !== org_id)); + response && mutate(`${getAPIUrl()}orgs/user/page/1/limit/10`, organizations.filter((org: any) => org.org_id !== org_id)); } return ( <> - + Your Organizations{" "} - <Link href={"/organizations/new"}> - <button>+</button> + <Link href="/organizations/new"> + <button className="bg-blue-500 text-white px-2 py-1 rounded-md hover:bg-blue-600 focus:outline-none"> + + + </button> </Link>
- {error &&

Failed to load

} + + {error &&

Failed to load

} {!organizations ? ( -

Loading...

+

Loading...

) : (
{organizations.map((org: any) => ( -
- -

{org.name}

+
+ +

{org.name}

- +
))}
)} + ); };