Skip to content

Commit

Permalink
Refactor to extrapolate layout
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Jun 5, 2024
1 parent b467cc2 commit 2e797cd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
22 changes: 3 additions & 19 deletions src/components/Organizations/OrganizationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Box, Flex, Heading, Text } from '@chakra-ui/react'
import { useTranslation } from 'react-i18next'
import { InputSearch } from '~src/layout/Inputs'
import { useOrganizationCount, useOrganizationList } from '~queries/organizations'
import { debounce } from '~utils/debounce'
Expand All @@ -9,15 +7,13 @@ import { Loading } from '~src/router/SuspenseLoader'
import OrganizationCard from '~components/Organizations/Card'
import { RoutedPagination } from '~components/Pagination/Pagination'
import LoadingError from '~src/layout/LoadingError'
import { useTranslation } from 'react-i18next'

export const OrganizationsListHeader = () => {
export const OrganizationsFilter = () => {
const { t } = useTranslation()
const { data: orgsCount, isLoading, error: countError } = useOrganizationCount()
const { page, orgId }: { page?: number; orgId?: string } = useParams()
const navigate = useNavigate()

const count = orgsCount?.count || 0

const debouncedSearch = debounce((value) => {
const getPath = () => {
// If previous state has not org id, ensure to look at the first page
Expand All @@ -33,19 +29,7 @@ export const OrganizationsListHeader = () => {
debouncedSearch(event.target.value)
}

return (
<Flex direction={{ base: 'column', md: 'row' }} justify={'space-between'}>
<Flex direction={'column'}>
<Heading isTruncated wordBreak='break-word'>
{t('organizations.organizations_list')}
</Heading>
{!isLoading && <Text color={'lighterText'}>{t('organizations.organizations_count', { count: count })}</Text>}
</Flex>
<Box>
<InputSearch maxW={'300px'} placeholder={t('organizations.search_by_org_id')} onChange={searchOnChange} />
</Box>
</Flex>
)
return <InputSearch maxW={'300px'} placeholder={t('organizations.search_by_org_id')} onChange={searchOnChange} />
}

export const OrganizationsList = () => {
Expand Down
30 changes: 30 additions & 0 deletions src/layout/ListPageLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Box, Flex, Heading, Text } from '@chakra-ui/react'
import { PropsWithChildren, ReactNode } from 'react'

const ListPageLayout = ({
title,
subtitle,
rightComponent,
children,
}: {
title: string
subtitle?: string
rightComponent?: ReactNode
} & PropsWithChildren) => {
return (
<Flex direction={'column'} mt={'40px'} gap={6}>
<Flex direction={{ base: 'column', md: 'row' }} justify={'space-between'}>
<Flex direction={'column'}>
<Heading isTruncated wordBreak='break-word'>
{title}
</Heading>
{subtitle && <Text color={'lighterText'}>{subtitle}</Text>}
</Flex>
{rightComponent && <Box>{rightComponent}</Box>}
</Flex>
{children}
</Flex>
)
}

export default ListPageLayout
20 changes: 15 additions & 5 deletions src/pages/Organization/List.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { Flex } from '@chakra-ui/react'
import { OrganizationsList, OrganizationsListHeader } from '~components/Organizations/OrganizationsList'
import { OrganizationsFilter, OrganizationsList } from '~components/Organizations/OrganizationsList'
import ListPageLayout from '~src/layout/ListPageLayout'
import { useOrganizationCount } from '~queries/organizations'
import { useTranslation } from 'react-i18next'

const OrganizationList = () => {
const { t } = useTranslation()
const { data: orgsCount, isLoading, error: countError } = useOrganizationCount()

const subtitle = !isLoading ? t('organizations.organizations_count', { count: orgsCount?.count || 0 }) : ''

return (
<Flex direction={'column'} mt={'40px'} gap={6}>
<OrganizationsListHeader />
<ListPageLayout
title={t('organizations.organizations_list')}
subtitle={subtitle}
rightComponent={<OrganizationsFilter />}
>
<OrganizationsList />
</Flex>
</ListPageLayout>
)
}

Expand Down

0 comments on commit 2e797cd

Please sign in to comment.