"use client"; import React, { useState } from "react"; import OrganizationCard from "./organization-card"; import { useQuery } from "@tanstack/react-query"; import organizationApi from "@/shared/services/organization"; import { Button } from "@/shared/components/button/button"; import { ErrorState } from "@/shared/components/error-state"; export function OrganizationSection() { const [showAll, setShowAll] = useState(false); const { data: organizations, isLoading, isError, error, isSuccess, refetch, isFetching, } = useQuery({ queryKey: ["organizations-list", showAll], queryFn: () => organizationApi .getOrganizations( { ...(showAll ? {} : { limit: 8 }), filter: ["is_active=true"], }, { skipAuth: true }, ) .then((res) => res.items), staleTime: 5000, retry: 1, }); const showSkeleton = isLoading || (isFetching && !isSuccess); return ( <>

Data Geospasial Lintas OPD

{!showAll ? ( ) : ( )}

Organisasi Perangkat Daerah yang berkontribusi dalam penyediaan data

{(() => { if (showSkeleton) { return (
{[...Array(8)].map((_, i) => (
))}
); } if (isError) { return ; } const visibleOrgs = (organizations ?? []).filter((o) => (o?.count_mapset ?? 0) > 0); if (isSuccess && visibleOrgs.length === 0) { return (
Belum ada data geospasial lintas OPD untuk ditampilkan.
); } if (isSuccess && visibleOrgs.length > 0) { return (
{visibleOrgs.map((org) => ( ))}
); } })()}
); }