Skip to content

Commit

Permalink
Merge branch 'dev' into omri-levy/fix/docs-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Omri-Levy authored Aug 15, 2024
2 parents 59d28b1 + c4ea42e commit ec33782
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const PaginationLast: FunctionComponent<
<PaginationLink
aria-label="Go to last page"
size="default"
className={ctw('gap-1 pr-2.5', className)}
className={ctw(
'gap-1 pr-2.5 aria-disabled:pointer-events-none aria-disabled:opacity-50',
className,
)}
{...props}
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PaginationItem } from '@/common/components/molecules/Pagination/Paginat
import { PaginationFirst } from '@/common/components/molecules/Pagination/Pagination.First';
import { PaginationPrevious } from '@/common/components/molecules/Pagination/Pagination.Previous';
import { PaginationNext } from '@/common/components/molecules/Pagination/Pagination.Next';
import { PaginationLast } from '@/common/components/molecules/Pagination/Pagination.Last';

export const UrlPagination: FunctionComponent<{
page: number;
Expand All @@ -13,9 +14,19 @@ export const UrlPagination: FunctionComponent<{
*/
onPrevPage: () => string;
onNextPage: () => string;
onLastPage: () => string;
onPaginate: (page: number) => string;
isLastPageEnabled?: boolean;
isLastPage: boolean;
}> = ({ page, onPrevPage, onNextPage, onPaginate, isLastPage }) => {
}> = ({
page,
onPrevPage,
onNextPage,
onLastPage,
onPaginate,
isLastPage,
isLastPageEnabled = true,
}) => {
return (
<Pagination className={`justify-start`}>
<PaginationContent>
Expand Down Expand Up @@ -46,6 +57,17 @@ export const UrlPagination: FunctionComponent<{
aria-disabled={isLastPage}
/>
</PaginationItem>
{isLastPageEnabled && (
<PaginationItem>
<PaginationLast
to={{
search: onLastPage(),
}}
iconOnly
aria-disabled={isLastPage}
/>
</PaginationItem>
)}
</PaginationContent>
</Pagination>
);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useCallback } from 'react';
import { useSerializedSearchParams } from '@/common/hooks/useSerializedSearchParams/useSerializedSearchParams';
import { defaultSerializer } from '@/common/hooks/useZodSearchParams/utils/default-serializer';

export const usePagination = () => {
export const usePagination = ({ totalPages }: { totalPages: number }) => {
const [searchParams] = useSerializedSearchParams();

const isLastPage = Number(searchParams.page) === totalPages || totalPages === 0;

const onPaginate = useCallback(
(page: number) => {
return defaultSerializer({
Expand All @@ -15,6 +17,13 @@ export const usePagination = () => {
[searchParams],
);

const onLastPage = useCallback(() => {
return defaultSerializer({
...searchParams,
page: totalPages.toString(),
});
}, [searchParams, totalPages]);

const onNextPage = useCallback(() => {
const pageNumber = Number(searchParams.page);
const nextPage = pageNumber + 1;
Expand All @@ -38,7 +47,9 @@ export const usePagination = () => {
return {
page: searchParams.page,
pageSize: searchParams.pageSize,
isLastPage,
onPaginate,
onLastPage,
onNextPage,
onPrevPage,
};
Expand Down
7 changes: 3 additions & 4 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { Method } from '@/common/enums';
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
import { TBusinessReportType } from '@/domains/business-reports/types';
import qs from 'qs';
import { Severities } from '@ballerine/common';
import { ObjectValues, Severities } from '@ballerine/common';
import { toast } from 'sonner';
import { t } from 'i18next';
import { ObjectValues } from '@ballerine/common';

export const BusinessReportStatus = {
NEW: 'new',
Expand Down Expand Up @@ -83,13 +82,13 @@ export const fetchLatestBusinessReport = async ({
businessId: string;
reportType: TBusinessReportType;
}) => {
const [filter, error] = await apiClient({
const [data, error] = await apiClient({
endpoint: `business-reports/latest?businessId=${businessId}&type=${reportType}`,
method: Method.GET,
schema: BusinessReportSchema,
});

return handleZodError(error, filter);
return handleZodError(error, data);
};

export const fetchBusinessReports = async ({
Expand Down
45 changes: 24 additions & 21 deletions apps/backoffice-v2/src/pages/Entities/Entities.page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { CaseCreation } from '@/pages/Entities/components/CaseCreation';
import { ctw } from '@ballerine/ui';
import { FunctionComponent } from 'react';
import { ctw, Skeleton } from '@ballerine/ui';
import React, { FunctionComponent } from 'react';
import { Outlet } from 'react-router-dom';
import { TAssignee } from '../../common/components/atoms/AssignDropdown/AssignDropdown';
import { MotionScrollArea } from '../../common/components/molecules/MotionScrollArea/MotionScrollArea';
import { Pagination } from '../../common/components/organisms/Pagination/Pagination';
import { Case } from '../Entity/components/Case/Case';
import { Cases } from './components/Cases/Cases';
import { useEntities } from './hooks/useEntities/useEntities';
import { NoCases } from '@/pages/Entities/components/NoCases/NoCases';
import { UrlPagination } from '@/common/components/molecules/UrlPagination/UrlPagination';

export const Entities: FunctionComponent = () => {
const {
onPaginate,
onPrevPage,
onNextPage,
onLastPage,
isLastPage,
onSearch,
onFilter,
onSortBy,
Expand All @@ -25,6 +28,7 @@ export const Entities: FunctionComponent = () => {
caseCount,
skeletonEntities,
isManualCaseCreationEnabled,
isNoCases,
} = useEntities();

return (
Expand Down Expand Up @@ -71,26 +75,25 @@ export const Entities: FunctionComponent = () => {
</MotionScrollArea>
<div className={`divider my-0 px-4`}></div>
<div className="flex flex-col gap-5 px-4">
<Pagination onPaginate={onPaginate} page={page} totalPages={totalPages} />
<div className={`flex items-center gap-x-2`}>
<div className={`d-full flex items-center text-sm`}>
{!isLoading && `Page ${page} of ${totalPages || 1}`}
{isLoading && <Skeleton className={`h-5 w-full`} />}
</div>
<UrlPagination
page={page}
onPrevPage={onPrevPage}
onNextPage={onNextPage}
onLastPage={onLastPage}
onPaginate={onPaginate}
isLastPage={isLastPage}
/>
</div>
{isManualCaseCreationEnabled && <CaseCreation />}
</div>
</Cases>
{/* Display skeleton individual when loading the entities list */}
{isLoading && (
<Case>
{/* Reject and approve header */}
<Case.Actions id={''} fullName={''} avatarUrl={''} />

<Case.Content>
<div>
<Case.FaceMatch faceAUrl={''} faceBUrl={''} isLoading />
<Case.Info info={{}} isLoading whitelist={[]} />
</div>
<Case.Documents documents={[]} isLoading />
</Case.Content>
</Case>
)}
{Array.isArray(cases) && !cases.length && !isLoading ? <NoCases /> : <Outlet />}
{isNoCases && <NoCases />}
{!isNoCases && <Outlet />}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSearchParamsByEntity } from '../../../../common/hooks/useSearchParam
import { createArrayOfNumbers } from '../../../../common/utils/create-array-of-numbers/create-array-of-numbers';
import { useSelectEntityOnMount } from '../../../../domains/entities/hooks/useSelectEntityOnMount/useSelectEntityOnMount';
import { useWorkflowsQuery } from '../../../../domains/workflows/hooks/queries/useWorkflowsQuery/useWorkflowsQuery';
import { usePagination } from '@/common/hooks/usePagination/usePagination';

export const useEntities = () => {
const [{ filterId, filter, sortBy, sortDir, page, pageSize, search }, setSearchParams] =
Expand All @@ -20,11 +21,8 @@ export const useEntities = () => {
pageSize,
search,
});

const {
meta: { totalPages },
data: workflows,
} = data || { meta: { totalPages: 0 }, data: [] };
const cases = data?.data;
const totalPages = data?.meta?.totalPages ?? 0;
const entity = useEntityType();
const { onSearch, search: searchValue } = useSearch();

Expand Down Expand Up @@ -58,15 +56,9 @@ export const useEntities = () => {
[filter, setSearchParams],
);

const onPaginate = useCallback(
(page: number) => () => {
setSearchParams({
page,
pageSize,
});
},
[pageSize, setSearchParams],
);
const { onPaginate, onPrevPage, onNextPage, onLastPage, isLastPage } = usePagination({
totalPages: data?.meta?.totalPages ?? 0,
});

const onSearchChange: ChangeEventHandler<HTMLInputElement> = useCallback(
event => {
Expand All @@ -86,20 +78,27 @@ export const useEntities = () => {

const { workflowDefinition } = useCaseCreationWorkflowDefinition();

const isNoCases = !isLoading && Array.isArray(cases) && !cases.length;

return {
onPaginate,
onPrevPage,
onNextPage,
onLastPage,
isLastPage,
onSearch: onSearchChange,
onFilter: onFilterChange,
onSortBy: onSortByChange,
onSortDirToggle,
search: searchValue,
cases: data?.data,
cases,
caseCount: data?.meta?.totalItems || 0,
isLoading,
page,
totalPages,
skeletonEntities,
entity,
isManualCaseCreationEnabled: workflowDefinition?.config?.enableManualCreation,
isNoCases,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { buttonVariants } from '@/common/components/atoms/Button/Button';
import { Plus } from 'lucide-react';
import { Link } from 'react-router-dom';
import { Search } from '@/common/components/molecules/Search';
import { Skeleton } from '@ballerine/ui';

export const MerchantMonitoring: FunctionComponent = () => {
const {
Expand All @@ -19,6 +20,7 @@ export const MerchantMonitoring: FunctionComponent = () => {
page,
onPrevPage,
onNextPage,
onLastPage,
onPaginate,
isLastPage,
locale,
Expand Down Expand Up @@ -50,18 +52,20 @@ export const MerchantMonitoring: FunctionComponent = () => {
{Array.isArray(businessReports) && !businessReports.length && !isLoadingBusinessReports && (
<NoBusinessReports />
)}
{!!totalPages && (
<div className={`mt-auto flex items-center gap-x-2`}>
<div className={`flex w-[12ch] text-sm`}>{`Page ${page} of ${totalPages}`}</div>
<UrlPagination
page={page}
onPrevPage={onPrevPage}
onNextPage={onNextPage}
onPaginate={onPaginate}
isLastPage={isLastPage}
/>
<div className={`mt-auto flex items-center gap-x-2`}>
<div className={`flex h-full w-[12ch] items-center text-sm`}>
{!isLoadingBusinessReports && `Page ${page} of ${totalPages || 1}`}
{isLoadingBusinessReports && <Skeleton className={`h-5 w-full`} />}
</div>
)}
<UrlPagination
page={page}
onPrevPage={onPrevPage}
onNextPage={onNextPage}
onLastPage={onLastPage}
onPaginate={onPaginate}
isLastPage={isLastPage}
/>
</div>
</div>
</div>
);
Expand Down
Loading

0 comments on commit ec33782

Please sign in to comment.