feat: use swr for activity

This commit is contained in:
swve 2023-01-24 22:21:37 +01:00
parent cad10078ae
commit 007ed6c8ea
6 changed files with 56 additions and 54 deletions

View file

@ -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>