Skip to content

Commit

Permalink
refactor: orgs filters section
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Mar 12, 2024
1 parent 6930fdc commit 343b1f5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/organizations/@list/client-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use client';

import { ROUTE_SECTIONS } from '~/shared/core/constants';

import { orgFiltersSearchParamsAtom } from '~/orgs/atoms/org-filters-search-params-atom';
import { orgTotalCountAtom } from '~/orgs/atoms/org-total-count-atom';
import { FiltersSection } from '~/filters/components/filters-section';
import { FiltersProvider } from '~/filters/providers/filters-provider';

interface Props {
rawSearchParams: Record<string, string>;
}

export const OrgListClientPage = ({ rawSearchParams }: Props) => {
return (
<FiltersProvider
rawSearchParams={rawSearchParams}
routeSection={ROUTE_SECTIONS.ORGS}
atom={orgFiltersSearchParamsAtom}
>
<FiltersSection
countAtom={orgTotalCountAtom}
searchPlaceholder="Search organizations ..."
/>
</FiltersProvider>
);
};
1 change: 1 addition & 0 deletions app/organizations/@list/default.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './page';
44 changes: 44 additions & 0 deletions app/organizations/@list/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';

import { ROUTE_SECTIONS } from '~/shared/core/constants';
import { getQueryClient } from '~/shared/utils/get-query-client';

import { filterQueryKeys } from '~/filters/core/query-keys';
import { orgQueryKeys } from '~/orgs/core/query-keys';
import { getFilterConfig } from '~/filters/api/get-filter-config';
import { getOrgList } from '~/orgs/api/get-org-list';

import { OrgListClientPage } from './client-page';

interface Props {
searchParams: Record<string, string>;
}

const OrgListPage = async ({ searchParams: rawSearchParams }: Props) => {
const queryClient = getQueryClient();

await Promise.all([
// Prefetch list
queryClient.prefetchInfiniteQuery({
queryKey: orgQueryKeys.list(rawSearchParams),
queryFn: async ({ pageParam }) => getOrgList(pageParam, rawSearchParams),
initialPageParam: 1,
}),
// Prefetch filter config
queryClient.prefetchQuery({
queryKey: filterQueryKeys.list(rawSearchParams, ROUTE_SECTIONS.ORGS),
queryFn: () => getFilterConfig(`/${ROUTE_SECTIONS.ORGS}`),
}),
]);

return (
<HydrationBoundary state={dehydrate(queryClient)}>
<OrgListClientPage rawSearchParams={rawSearchParams} />
</HydrationBoundary>
);
};

export default OrgListPage;

// Force SSR on this page (needed to pick up searchParams)
export const dynamic = 'force-dynamic';
20 changes: 20 additions & 0 deletions app/organizations/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface Props {
children: React.ReactNode;
list: React.ReactNode;
}

const OrgsLayout = ({ children, list }: Props) => {
return (
<div className="min-h-screen w-full md:pl-[212px]">
<div className="w-full lg:w-1/2">
<div className="flex flex-col gap-8 px-2 py-8 pt-24 md:px-8 md:pt-8">
{list}
</div>
</div>

{children}
</div>
);
};

export default OrgsLayout;
5 changes: 5 additions & 0 deletions src/orgs/atoms/org-filters-search-params-atom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { atom } from 'jotai';

export const orgFiltersSearchParamsAtom = atom<URLSearchParams>(
new URLSearchParams(),
);

0 comments on commit 343b1f5

Please sign in to comment.