Skip to content

Commit 0401a7e

Browse files
authored
Merge pull request #2673 from Northeastern-Electric-Racing/#2634-admin-tool-useful-links
#2634 admin tool useful links
2 parents 3f3ac40 + 83dd48f commit 0401a7e

19 files changed

Lines changed: 416 additions & 39 deletions

src/backend/src/services/organizations.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import prisma from '../prisma/prisma';
44
import { AccessDeniedAdminOnlyException, HttpException, NotFoundException } from '../utils/errors.utils';
55
import { userHasPermission } from '../utils/users.utils';
66
import { createUsefulLinks } from '../utils/organizations.utils';
7+
import { linkTransformer } from '../transformers/links.transformer';
8+
import { getLinkQueryArgs } from '../prisma-query-args/links.query-args';
79

810
export default class OrganizationsService {
911
/**
@@ -72,8 +74,9 @@ export default class OrganizationsService {
7274
const links = await prisma.link.findMany({
7375
where: {
7476
linkId: { in: organization.usefulLinks.map((link) => link.linkId) }
75-
}
77+
},
78+
...getLinkQueryArgs(organizationId)
7679
});
77-
return links;
80+
return links.map(linkTransformer);
7881
}
7982
}

src/frontend/src/apis/projects.api.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import axios from '../utils/axios';
7-
import { LinkType, LinkTypeCreatePayload, Project, WbsNumber, WorkPackageTemplate } from 'shared';
7+
import { Link, LinkType, LinkCreateArgs, LinkTypeCreatePayload, Project, WbsNumber, WorkPackageTemplate } from 'shared';
88
import { wbsPipe } from '../utils/pipes';
99
import { apiUrls } from '../utils/urls';
1010
import { linkTypeTransformer, projectTransformer } from './transformers/projects.transformers';
@@ -118,3 +118,21 @@ export const getAllWorkPackageTemplates = () => {
118118
export const editLinkType = async (name: string, linkTypeData: LinkTypeCreatePayload) => {
119119
return axios.post(apiUrls.projectsEditLinkTypes(name), linkTypeData);
120120
};
121+
122+
/**
123+
* gets all the useful links from the database
124+
* @returns gets all the useful links
125+
*/
126+
export const getAllUsefulLinks = () => {
127+
return axios.get<Link[]>(apiUrls.organizationsUsefulLinks(), {
128+
transformResponse: (data) => JSON.parse(data)
129+
});
130+
};
131+
132+
/**
133+
* sets all the useful links
134+
* @returns gets all the link types
135+
*/
136+
export const setUsefulLinks = (linksObject: { links: LinkCreateArgs[] }) => {
137+
return axios.post<Link[]>(apiUrls.organizationsSetUsefulLinks(), linksObject);
138+
};

src/frontend/src/hooks/projects.hooks.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { useMutation, useQuery, useQueryClient } from 'react-query';
7-
import { LinkType, LinkTypeCreatePayload, Project, WbsNumber, WorkPackageTemplate } from 'shared';
7+
import { Link, LinkCreateArgs, LinkType, LinkTypeCreatePayload, Project, WbsNumber, WorkPackageTemplate } from 'shared';
88
import {
99
editSingleProject,
1010
createSingleProject,
@@ -16,7 +16,9 @@ import {
1616
getAllLinkTypes,
1717
createLinkType,
1818
getAllWorkPackageTemplates,
19-
editLinkType
19+
editLinkType,
20+
getAllUsefulLinks,
21+
setUsefulLinks
2022
} from '../apis/projects.api';
2123
import { CreateSingleProjectPayload, EditSingleProjectPayload } from '../utils/types';
2224
import { useCurrentUser } from './users.hooks';
@@ -200,3 +202,35 @@ export const useEditLinkType = (linkTypeName: string) => {
200202
}
201203
);
202204
};
205+
206+
/**
207+
* Custom React Hook to get all useful links
208+
*/
209+
export const useAllUsefulLinks = () => {
210+
return useQuery<Link[], Error>(['useful links'], async () => {
211+
const { data } = await getAllUsefulLinks();
212+
return data;
213+
});
214+
};
215+
216+
/**
217+
* Custom React Hook to set all useful links.
218+
*
219+
* @param links All the links to be set
220+
* @returns all the links
221+
*/
222+
export const useSetUsefulLinks = () => {
223+
const queryClient = useQueryClient();
224+
return useMutation<Link[], Error, LinkCreateArgs[]>(
225+
['useful links'],
226+
async (links: LinkCreateArgs[]) => {
227+
const { data } = await setUsefulLinks({ links });
228+
return data;
229+
},
230+
{
231+
onSuccess: () => {
232+
queryClient.invalidateQueries(['useful links']);
233+
}
234+
}
235+
);
236+
};

src/frontend/src/pages/AdminToolsPage/AdminToolsProjectsConfig.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Box } from '@mui/system';
22
import { Typography } from '@mui/material';
33
import WorkPackageTemplateTable from './ProjectsConfig/WorkPackageTemplateTable';
4-
import LinkTypeTable from './ProjectsConfig/LinkTypeTable';
5-
import DescriptionBulletTypeTable from './ProjectsConfig/DescriptionBulletTypeTable';
4+
import LinkTypeTable from './ProjectsConfig/LinkTypes/LinkTypeTable';
5+
import DescriptionBulletTypeTable from './ProjectsConfig/DescriptionBulletTypes/DescriptionBulletTypeTable';
66
import CarsTable from './ProjectsConfig/CarsTable';
7+
import UsefulLinksTable from './ProjectsConfig/UsefulLinks/UsefulLinksTable';
78

89
const AdminToolsProjectsConfig: React.FC = () => {
910
return (
@@ -16,6 +17,10 @@ const AdminToolsProjectsConfig: React.FC = () => {
1617
Links Config
1718
</Typography>
1819
<LinkTypeTable />
20+
<Typography variant="h5" gutterBottom borderBottom={1} color="#ef4345" borderColor={'white'}>
21+
Useful Links
22+
</Typography>
23+
<UsefulLinksTable />
1924
<Typography variant="h5" gutterBottom borderBottom={1} color="#ef4345" borderColor={'white'}>
2025
Description Bullet Types
2126
</Typography>

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/CreateDescriptionBulletTypeModal.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypes/CreateDescriptionBulletTypeModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ErrorPage from '../../ErrorPage';
2-
import LoadingIndicator from '../../../components/LoadingIndicator';
1+
import ErrorPage from '../../../ErrorPage';
2+
import LoadingIndicator from '../../../../components/LoadingIndicator';
33
import { DescriptionBulletType } from 'shared';
44
import DescriptionBulletTypeFormModal from './DescriptionBulletTypeFormModal';
5-
import { useCreateDescriptionBulletType } from '../../../hooks/description-bullets.hooks';
5+
import { useCreateDescriptionBulletType } from '../../../../hooks/description-bullets.hooks';
66

77
interface CreateDescriptionBulletTypeModalProps {
88
open: boolean;

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypeFormModal.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypes/DescriptionBulletTypeFormModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Controller, useForm } from 'react-hook-form';
2-
import NERFormModal from '../../../components/NERFormModal';
2+
import NERFormModal from '../../../../components/NERFormModal';
33
import { FormControl, FormLabel, FormHelperText, Switch, Grid } from '@mui/material';
4-
import ReactHookTextField from '../../../components/ReactHookTextField';
5-
import { useToast } from '../../../hooks/toasts.hooks';
4+
import ReactHookTextField from '../../../../components/ReactHookTextField';
5+
import { useToast } from '../../../../hooks/toasts.hooks';
66
import * as yup from 'yup';
77
import { yupResolver } from '@hookform/resolvers/yup';
88
import { useTheme } from '@mui/material/styles';

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypeTable.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypes/DescriptionBulletTypeTable.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { useCurrentUser } from '../../../hooks/users.hooks';
2-
import { useGetAllDescriptionBulletTypes } from '../../../hooks/description-bullets.hooks';
1+
import { useCurrentUser } from '../../../../hooks/users.hooks';
2+
import { useGetAllDescriptionBulletTypes } from '../../../../hooks/description-bullets.hooks';
33
import { useState } from 'react';
44
import { DescriptionBulletType, isAdmin } from 'shared';
5-
import LoadingIndicator from '../../../components/LoadingIndicator';
6-
import ErrorPage from '../../ErrorPage';
5+
import LoadingIndicator from '../../../../components/LoadingIndicator';
6+
import ErrorPage from '../../../ErrorPage';
77
import { TableCell, TableRow, Typography } from '@mui/material';
88
import CreateDescriptionBulletTypeModal from './CreateDescriptionBulletTypeModal';
99
import EditDescriptionBulletTypeModal from './EditDescriptionBulletTypeModel';
1010
import { Box } from '@mui/system';
11-
import AdminToolTable from '../AdminToolTable';
12-
import { NERButton } from '../../../components/NERButton';
11+
import AdminToolTable from '../../AdminToolTable';
12+
import { NERButton } from '../../../../components/NERButton';
1313

1414
const DescriptionBulletTypeTable = () => {
1515
const currentUser = useCurrentUser();

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/EditDescriptionBulletTypeModel.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/DescriptionBulletTypes/EditDescriptionBulletTypeModel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ErrorPage from '../../ErrorPage';
2-
import LoadingIndicator from '../../../components/LoadingIndicator';
1+
import ErrorPage from '../../../ErrorPage';
2+
import LoadingIndicator from '../../../../components/LoadingIndicator';
33
import { DescriptionBulletType } from 'shared';
44
import DescriptionBulletTypeFormModal from './DescriptionBulletTypeFormModal';
5-
import { useEditDescriptionBulletType } from '../../../hooks/description-bullets.hooks';
5+
import { useEditDescriptionBulletType } from '../../../../hooks/description-bullets.hooks';
66

77
interface EditdescriptionBulletTypeModalProps {
88
open: boolean;

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/CreateLinkTypeModal.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/LinkTypes/CreateLinkTypeModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ErrorPage from '../../ErrorPage';
2-
import LoadingIndicator from '../../../components/LoadingIndicator';
1+
import ErrorPage from '../../../ErrorPage';
2+
import LoadingIndicator from '../../../../components/LoadingIndicator';
33
import LinkTypeFormModal from './LinkTypeFormModal';
44
import { LinkType } from 'shared';
5-
import { useCreateLinkType } from '../../../hooks/projects.hooks';
5+
import { useCreateLinkType } from '../../../../hooks/projects.hooks';
66

77
interface CreateLinkTypeModalProps {
88
open: boolean;

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/EditLinkTypeModal.tsx renamed to src/frontend/src/pages/AdminToolsPage/ProjectsConfig/LinkTypes/EditLinkTypeModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useEditLinkType } from '../../../hooks/projects.hooks';
2-
import ErrorPage from '../../ErrorPage';
3-
import LoadingIndicator from '../../../components/LoadingIndicator';
1+
import { useEditLinkType } from '../../../../hooks/projects.hooks';
2+
import ErrorPage from '../../../ErrorPage';
3+
import LoadingIndicator from '../../../../components/LoadingIndicator';
44
import LinkTypeFormModal from './LinkTypeFormModal';
55
import { LinkType } from 'shared';
66

0 commit comments

Comments
 (0)