From b2b40ed643e726145170ff549c78994cba811da4 Mon Sep 17 00:00:00 2001 From: anamontiaga Date: Wed, 11 May 2022 20:03:58 +0200 Subject: [PATCH 1/2] add email colum to admin panel --- app/hooks/admin/index.ts | 6 +++++ .../table/cells/email/component.tsx | 25 +++++++++++++++++++ .../table/cells/email/index.ts | 1 + .../published-projects/table/component.tsx | 9 ++++++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/layout/admin/published-projects/table/cells/email/component.tsx create mode 100644 app/layout/admin/published-projects/table/cells/email/index.ts diff --git a/app/hooks/admin/index.ts b/app/hooks/admin/index.ts index a68b46ae88..86b1d245eb 100644 --- a/app/hooks/admin/index.ts +++ b/app/hooks/admin/index.ts @@ -5,6 +5,9 @@ import { useQuery, useQueryClient, } from 'react-query'; +import keyBy from 'lodash/keyBy'; +import merge from 'lodash/merge'; + import { useSession } from 'next-auth/client'; import ADMIN from 'services/admin'; @@ -324,6 +327,8 @@ export function useAdminPublishedProjects(options: UseAdminPublishedProjectsProp // totalItems: 100, // }, data: data?.data.map((d) => { + const { creators, ownerEmails } = d; + merge(keyBy(creators, 'id'), keyBy(ownerEmails, 'id')); const owners = d.creators ? d.creators.filter((c) => c.roleName === 'project_owner') : []; return { @@ -332,6 +337,7 @@ export function useAdminPublishedProjects(options: UseAdminPublishedProjectsProp description: d.description, status: d.underModeration ? 'under-moderation' : 'published', owners, + emails: owners, }; }), meta: data?.meta, diff --git a/app/layout/admin/published-projects/table/cells/email/component.tsx b/app/layout/admin/published-projects/table/cells/email/component.tsx new file mode 100644 index 0000000000..9db004ed5f --- /dev/null +++ b/app/layout/admin/published-projects/table/cells/email/component.tsx @@ -0,0 +1,25 @@ +import React from 'react'; + +export interface CellEmailProps { + value: Record[], +} + +export const CellEmail: React.FC = ({ + value, +}: CellEmailProps) => { + if (!value) return null; + + return ( +
+ {value.map((owner) => { + const { id, email } = owner; + return ( +
{email}
+ ); + })} +
+ + ); +}; + +export default CellEmail; diff --git a/app/layout/admin/published-projects/table/cells/email/index.ts b/app/layout/admin/published-projects/table/cells/email/index.ts new file mode 100644 index 0000000000..b404d7fd44 --- /dev/null +++ b/app/layout/admin/published-projects/table/cells/email/index.ts @@ -0,0 +1 @@ +export { default } from './component'; diff --git a/app/layout/admin/published-projects/table/component.tsx b/app/layout/admin/published-projects/table/component.tsx index 8aa47c9c5a..bc03479e99 100644 --- a/app/layout/admin/published-projects/table/component.tsx +++ b/app/layout/admin/published-projects/table/component.tsx @@ -7,6 +7,7 @@ import { useAdminPublishedProjects } from 'hooks/admin'; import Search from 'components/search'; import Table2 from 'components/table2'; +import Email from './cells/email'; import Name from './cells/name'; import Owner from './cells/owner'; import Status from './cells/status'; @@ -30,7 +31,6 @@ export const AdminPublishedProjectsTable: React.FC { return [ { @@ -56,6 +56,13 @@ export const AdminPublishedProjectsTable: React.FC Date: Thu, 12 May 2022 13:27:39 +0200 Subject: [PATCH 2/2] fix: avoid unecessary lodash on adding emails to owners --- app/hooks/admin/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/hooks/admin/index.ts b/app/hooks/admin/index.ts index 86b1d245eb..81e78753c1 100644 --- a/app/hooks/admin/index.ts +++ b/app/hooks/admin/index.ts @@ -5,9 +5,6 @@ import { useQuery, useQueryClient, } from 'react-query'; -import keyBy from 'lodash/keyBy'; -import merge from 'lodash/merge'; - import { useSession } from 'next-auth/client'; import ADMIN from 'services/admin'; @@ -328,8 +325,13 @@ export function useAdminPublishedProjects(options: UseAdminPublishedProjectsProp // }, data: data?.data.map((d) => { const { creators, ownerEmails } = d; - merge(keyBy(creators, 'id'), keyBy(ownerEmails, 'id')); - const owners = d.creators ? d.creators.filter((c) => c.roleName === 'project_owner') : []; + + const mergeCreators = creators.map((c) => ({ + ...ownerEmails.find((o) => (o.id === c.id) && o), + ...c, + })); + + const owners = mergeCreators ? mergeCreators.filter((c) => c.roleName === 'project_owner') : []; return { id: d.id,