Skip to content

Commit

Permalink
Add empty state for records
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed May 30, 2024
1 parent ebb1aa0 commit 9464b1d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useNavigate } from 'react-router-dom';
import { IconPlus, IconSettings } from 'twenty-ui';

import { Button } from '@/ui/input/button/components/Button';
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
import {
AnimatedPlaceholderEmptyContainer,
AnimatedPlaceholderEmptySubTitle,
AnimatedPlaceholderEmptyTextContainer,
AnimatedPlaceholderEmptyTitle,
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';

type RecordTableEmptyStateProps = {
objectLabel: string;
createRecord: () => void;
isRemote: boolean;
};

export const RecordTableEmptyState = ({
objectLabel,
createRecord,
isRemote,
}: RecordTableEmptyStateProps) => {
const navigate = useNavigate();

const [title, subTitle, Icon, onClick, buttonTitle] = isRemote
? [
'No Data Available for Remote Table',
'If this is unexpected, please verify your settings.',
IconSettings,
() => navigate('/settings/integrations'),
'Go to Settings',
]
: [
`Add your first ${objectLabel}`,
`Use our API or add your first ${objectLabel} manually`,
IconPlus,
createRecord,
`Add a ${objectLabel}`,
];

return (
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="noRecord" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>{title}</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
{subTitle}
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={Icon}
title={buttonTitle}
variant={'secondary'}
onClick={onClick}
/>
</AnimatedPlaceholderEmptyContainer>
);
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { useRef } from 'react';
import styled from '@emotion/styled';
import { useRecoilCallback, useRecoilValue } from 'recoil';
import { IconPlus } from 'twenty-ui';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { RecordTable } from '@/object-record/record-table/components/RecordTable';
import { RecordTableEmptyState } from '@/object-record/record-table/components/RecordTableEmptyState';
import { EntityDeleteContext } from '@/object-record/record-table/contexts/EntityDeleteHookContext';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
import { Button } from '@/ui/input/button/components/Button';
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
import {
AnimatedPlaceholderEmptyContainer,
AnimatedPlaceholderEmptySubTitle,
AnimatedPlaceholderEmptyTextContainer,
AnimatedPlaceholderEmptyTitle,
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import { useSaveCurrentViewFields } from '@/views/hooks/useSaveCurrentViewFields';
Expand Down Expand Up @@ -115,27 +107,13 @@ export const RecordTableWithWrappers = ({
recordTableId={recordTableId}
tableBodyRef={tableBodyRef}
/>
{!isRecordTableInitialLoading &&
numberOfTableRows === 0 &&
!isRemote && (
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="noRecord" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>
Add your first {objectLabel}
</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
Use our API or add your first {objectLabel} manually
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={IconPlus}
title={`Add a ${objectLabel}`}
variant={'secondary'}
onClick={createRecord}
/>
</AnimatedPlaceholderEmptyContainer>
)}
{!isRecordTableInitialLoading && numberOfTableRows === 0 && (
<RecordTableEmptyState
objectLabel={objectLabel}
createRecord={createRecord}
isRemote={isRemote}
/>
)}
</StyledTableContainer>
</StyledTableWithHeader>
</RecordUpdateContext.Provider>
Expand Down

0 comments on commit 9464b1d

Please sign in to comment.