import type { IImporterSelectionContact } from '@rocket.chat/core-typings'; import { CheckBox, Table, Pagination, TableHead, TableRow, TableCell, TableBody } from '@rocket.chat/fuselage'; import { usePagination } from '@rocket.chat/ui-client'; import type { Dispatch, SetStateAction, ChangeEvent } from 'react'; import { useTranslation } from 'react-i18next'; export type PrepareContactsProps = { contactsCount: number; contacts: IImporterSelectionContact[]; setContacts: Dispatch>; }; const PrepareContacts = ({ contactsCount, contacts, setContacts }: PrepareContactsProps) => { const { t } = useTranslation(); const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination(); return ( <> 0} indeterminate={contactsCount > 0 && contactsCount !== contacts.length} onChange={(): void => { setContacts((contacts) => { const isChecking = contactsCount === 0; return contacts.map((contact) => ({ ...contact, do_import: isChecking })); }); }} /> {t('Name')} {t('Emails')} {t('Phones')} {contacts.slice(current, current + itemsPerPage).map((contact) => ( ): void => { const { checked } = event.currentTarget; setContacts((contacts) => contacts.map((_contact) => (_contact === contact ? { ..._contact, do_import: checked } : _contact)), ); }} /> {contact.name} {contact.emails.join('\n')} {contact.phones.join('\n')} ))}
); }; export default PrepareContacts;