selectors.ts 491 B

123456789101112
  1. import { createSelector } from '@reduxjs/toolkit';
  2. import { selectors } from './reducers';
  3. export const { selectAll, selectById, selectTotal } = selectors;
  4. const selectQuery = (_: any, query: string) => query;
  5. export const selectInvitesMatchingQuery = createSelector([selectAll, selectQuery], (invites, searchQuery) => {
  6. const regex = new RegExp(searchQuery, 'i');
  7. const matches = invites.filter((invite) => regex.test(invite.name) || regex.test(invite.email));
  8. return matches;
  9. });