mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: use swr for activity
This commit is contained in:
parent
cad10078ae
commit
007ed6c8ea
6 changed files with 56 additions and 54 deletions
|
|
@ -3,17 +3,17 @@ import Link from "next/link";
|
|||
import React from "react";
|
||||
import Layout from "../../components/UI/Layout";
|
||||
import { Title } from "../../components/UI/Elements/Styles/Title";
|
||||
import { deleteOrganizationFromBackend } from "../../services/orgs";
|
||||
import { deleteOrganizationFromBackend } from "@services/orgs";
|
||||
import useSWR, { mutate } from "swr";
|
||||
import { swrFetcher } from "@services/utils/requests";
|
||||
import { getAPIUrl } from "@services/config";
|
||||
|
||||
const Organizations = () => {
|
||||
const { data, 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`, data.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 (
|
||||
|
|
@ -26,11 +26,11 @@ const Organizations = () => {
|
|||
</Title>
|
||||
<hr />
|
||||
{error && <p>Failed to load</p>}
|
||||
{!data ? (
|
||||
{!organizations ? (
|
||||
<p>Loading...</p>
|
||||
) : (
|
||||
<div>
|
||||
{data.map((org: any) => (
|
||||
{organizations.map((org: any) => (
|
||||
<div key={org.org_id}>
|
||||
<Link href={`/org/${org.slug}`}>
|
||||
<h3>{org.name}</h3>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue