From ef05cb7b07d7e4ef43e3aa8af79dd1a842f7898c Mon Sep 17 00:00:00 2001 From: John Ballesteros <89079900+johnshift@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:14:15 +0800 Subject: [PATCH] refactor: init org card component (#113) --- src/orgs/atoms/init-org-atom.ts | 4 +-- src/orgs/components/init-org-card.tsx | 44 +++++++++++++++++++++++++++ src/orgs/components/org-list.tsx | 9 +++--- 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/orgs/components/init-org-card.tsx diff --git a/src/orgs/atoms/init-org-atom.ts b/src/orgs/atoms/init-org-atom.ts index cacba7f87..953df8094 100644 --- a/src/orgs/atoms/init-org-atom.ts +++ b/src/orgs/atoms/init-org-atom.ts @@ -1,5 +1,5 @@ import { atom } from 'jotai'; -import { OrgDetails } from '~/orgs/core/schemas'; +import { OrgListItem } from '~/orgs/core/schemas'; -export const initOrgAtom = atom(null); +export const initOrgAtom = atom(null); diff --git a/src/orgs/components/init-org-card.tsx b/src/orgs/components/init-org-card.tsx new file mode 100644 index 000000000..b20bb5136 --- /dev/null +++ b/src/orgs/components/init-org-card.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { usePathname } from 'next/navigation'; + +import { useAtomValue } from 'jotai'; + +import { HREFS } from '~/shared/core/constants'; +import { initPathAtom } from '~/shared/atoms/init-path-atom'; + +import { JobCardSkeleton } from '~/jobs/components/job-card/skeleton'; + +import { initOrgAtom } from '../atoms/init-org-atom'; + +import { OrgCard } from './org-card'; + +interface Props { + filterParamsString: string; +} + +export const InitOrgCard = ({ filterParamsString }: Props) => { + const pathname = usePathname(); + + const initPath = useAtomValue(initPathAtom); + const initOrg = useAtomValue(initOrgAtom); + + // Do not render if initially in /jobs + if (initPath === HREFS.ORGS_PAGE) return null; + + // Do not render if on /jobs page and no initOrg + if (!initOrg && pathname === HREFS.ORGS_PAGE) return null; + + // Render initOrg if set + if (initOrg) + return ( + + ); + + // Defaults to a skeleton (job card skeleton for now) + return ; +}; diff --git a/src/orgs/components/org-list.tsx b/src/orgs/components/org-list.tsx index 5792c0988..a5d789777 100644 --- a/src/orgs/components/org-list.tsx +++ b/src/orgs/components/org-list.tsx @@ -4,8 +4,10 @@ import { InternalErrorResult } from '~/shared/components/internal-error-result'; import { VirtualWrapper } from '~/shared/components/virtual-wrapper'; import { useOrgList } from '~/orgs/hooks/use-org-list'; +import { JobCardSkeleton } from '~/jobs/components/job-card/skeleton'; import { useFiltersContext } from '~/filters/providers/filters-provider/context'; +import { InitOrgCard } from './init-org-card'; import { OrgCard } from './org-card'; export const OrgList = () => { @@ -31,14 +33,13 @@ export const OrgList = () => { {error && } {isPending ? ( -

Card Skeleton

+ ) : ( isSuccess && (hasOrgs ? ( <>
-

Init org card

-

{JSON.stringify({ filterParamsString })}

+
@@ -54,7 +55,7 @@ export const OrgList = () => { {hasNextPage ? (
-

Card Skeleton

+
) : (

TODO: No more orgs UI