import { useContext, useState } from 'react'; import { Table, TableBody, TableCell, TableHead, TableRow, Typography, } from '@material-ui/core'; import AccessContext from 'contexts/AccessContext'; import usePagination from 'hooks/usePagination'; import { CREATE_SEGMENT, UPDATE_SEGMENT, } from 'component/providers/AccessProvider/permissions'; import PaginateUI from 'component/common/PaginateUI/PaginateUI'; import { SegmentListItem } from './SegmentListItem/SegmentListItem'; import { ISegment } from 'interfaces/segment'; import { useStyles } from './SegmentList.styles'; import { useSegments } from 'hooks/api/getters/useSegments/useSegments'; import { useSegmentsApi } from 'hooks/api/actions/useSegmentsApi/useSegmentsApi'; import useToast from 'hooks/useToast'; import { formatUnknownError } from 'utils/formatUnknownError'; import { Link, useHistory } from 'react-router-dom'; import ConditionallyRender from 'component/common/ConditionallyRender'; import HeaderTitle from 'component/common/HeaderTitle'; import PageContent from 'component/common/PageContent'; import PermissionButton from 'component/common/PermissionButton/PermissionButton'; import { SegmentDelete } from '../SegmentDelete/SegmentDelete'; import { SegmentDocsWarning } from 'component/segments/SegmentDocs/SegmentDocs'; export const SegmentsList = () => { const history = useHistory(); const { hasAccess } = useContext(AccessContext); const { segments = [], refetchSegments } = useSegments(); const { deleteSegment } = useSegmentsApi(); const { page, pages, nextPage, prevPage, setPageIndex, pageIndex } = usePagination(segments, 10); const [currentSegment, setCurrentSegment] = useState(); const [delDialog, setDelDialog] = useState(false); const { setToastData, setToastApiError } = useToast(); const styles = useStyles(); const onDeleteSegment = async () => { if (!currentSegment?.id) return; try { await deleteSegment(currentSegment?.id); await refetchSegments(); setToastData({ type: 'success', title: 'Successfully deleted segment', }); } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } setDelDialog(false); }; const renderSegments = () => { return page.map((segment: ISegment) => { return ( ); }); }; const renderNoSegments = () => { return (
No segments yet!

Segment makes it easy for you to define who should be exposed to your feature. The segment is often a collection of constraints and can be reused.

Create your first segment
); }; return ( history.push('/segments/create')} permission={CREATE_SEGMENT} > New Segment } /> } >
Name Description Created on Created By {hasAccess(UPDATE_SEGMENT) ? 'Actions' : ''} 0} show={renderSegments()} />
( )} />
); };