Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(front): add emails to admin panel [MARXAN-1547] #1059

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/hooks/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -332,6 +337,7 @@ export function useAdminPublishedProjects(options: UseAdminPublishedProjectsProp
description: d.description,
status: d.underModeration ? 'under-moderation' : 'published',
owners,
emails: owners,
};
}),
meta: data?.meta,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

export interface CellEmailProps {
value: Record<string, string>[],
}

export const CellEmail: React.FC<CellEmailProps> = ({
value,
}: CellEmailProps) => {
if (!value) return null;

return (
<div className="space-y-1">
{value.map((owner) => {
const { id, email } = owner;
return (
<div key={id}>{email}</div>
);
})}
</div>

);
};

export default CellEmail;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './component';
9 changes: 8 additions & 1 deletion app/layout/admin/published-projects/table/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,7 +31,6 @@ export const AdminPublishedProjectsTable: React.FC<AdminPublishedProjectsTablePr
sort,
search,
});

const COLUMNS = useMemo(() => {
return [
{
Expand All @@ -56,6 +56,13 @@ export const AdminPublishedProjectsTable: React.FC<AdminPublishedProjectsTablePr
Cell: Owner,
// width: 100,
},
{
Header: 'Email',
accessor: 'emails',
className: 'text-sm leading-none',
disableSortBy: true,
Cell: Email,
},
{
Header: 'Status',
accessor: 'status',
Expand Down