mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init collections index + delete
This commit is contained in:
parent
c5bb590b2d
commit
924656ce13
14 changed files with 167 additions and 22 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import type { NextPage } from "next";
|
||||
import { Title } from "../components/ui/styles/title";
|
||||
import Layout from "../components/ui/layout";
|
||||
import { Header } from "../components/ui/header";
|
||||
|
||||
const Home: NextPage = () => {
|
||||
return (
|
||||
<div>
|
||||
<Layout title="Index">
|
||||
<Header></Header>
|
||||
<Title>Home</Title>
|
||||
</Layout>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import React from "react";
|
||||
import { Header } from "../components/ui/header";
|
||||
import Layout from "../components/ui/layout";
|
||||
import { Title } from "../components/ui/styles/title";
|
||||
import { loginAndGetToken } from "../services/auth/auth";
|
||||
|
|
@ -25,6 +26,7 @@ const Login = () => {
|
|||
return (
|
||||
<div>
|
||||
<Layout title="Login">
|
||||
<Header></Header>
|
||||
<Title>Login</Title>
|
||||
|
||||
<form>
|
||||
|
|
|
|||
67
front/pages/organizations/index.tsx
Normal file
67
front/pages/organizations/index.tsx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import Link from "next/link";
|
||||
import React from "react";
|
||||
import Layout from "../../components/ui/layout";
|
||||
import { Title } from "../../components/ui/styles/title";
|
||||
import { deleteOrganizationFromBackend, getUserOrganizations } from "../../services/orgs";
|
||||
|
||||
const Organizations = () => {
|
||||
const [userOrganizations, setUserOrganizations] = React.useState([]);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
|
||||
async function fetchUserOrganizations() {
|
||||
const response = await getUserOrganizations();
|
||||
setUserOrganizations(response);
|
||||
console.log(response);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function deleteOrganization(org_id:any) {
|
||||
const response = await deleteOrganizationFromBackend(org_id);
|
||||
const newOrganizations = userOrganizations.filter((org:any) => org.org_id !== org_id);
|
||||
setUserOrganizations(newOrganizations);
|
||||
}
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
setIsLoading(true);
|
||||
fetchUserOrganizations();
|
||||
setIsLoading(false);
|
||||
}, []);
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<Layout>
|
||||
<Title>
|
||||
Your Organizations{" "}
|
||||
<Link href={"/organizations/new"}>
|
||||
<a>
|
||||
<button>+</button>
|
||||
</a>
|
||||
</Link>
|
||||
</Title>
|
||||
<hr />
|
||||
{isLoading ? (
|
||||
<p>Loading...</p>
|
||||
) : (
|
||||
<div>
|
||||
{userOrganizations.map((org: any) => (
|
||||
<div key={org.org_id}>
|
||||
<Link href={`/organizations/${org.org_id}`}>
|
||||
<a>
|
||||
<h3>{org.name}</h3>
|
||||
</a>
|
||||
</Link>
|
||||
<button onClick={() => deleteOrganization(org.org_id)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Organizations;
|
||||
13
front/pages/organizations/new.tsx
Normal file
13
front/pages/organizations/new.tsx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import React from 'react'
|
||||
import Layout from '../../components/ui/layout'
|
||||
import { Title } from '../../components/ui/styles/title'
|
||||
|
||||
const Organizations = () => {
|
||||
return (
|
||||
<Layout>
|
||||
<Title>New Organization</Title>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export default Organizations
|
||||
0
front/pages/organizations/update.tsx
Normal file
0
front/pages/organizations/update.tsx
Normal file
|
|
@ -1,4 +1,5 @@
|
|||
import React from "react";
|
||||
import { Header } from "../components/ui/header";
|
||||
import Layout from "../components/ui/layout";
|
||||
import { Title } from "../components/ui/styles/title";
|
||||
import { signup } from "../services/auth/auth";
|
||||
|
|
@ -30,6 +31,7 @@ const SignUp = () => {
|
|||
return (
|
||||
<div>
|
||||
<Layout title="Sign up">
|
||||
<Header></Header>
|
||||
<Title>Sign up </Title>
|
||||
|
||||
<form>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue