Skip to content

Commit

Permalink
enhancement fictadvisor#354: refactor admin panel
Browse files Browse the repository at this point in the history
- refactor fetching data in all files
- refactor pages inside app folder and renamed components
- renamed files inside those folders
- renamed folders and fixed bugs in students
- rewrite disciplines
- api fix
- admin styles
  • Loading branch information
sifes committed Apr 9, 2024
1 parent 39df0b3 commit fc8b3b1
Show file tree
Hide file tree
Showing 449 changed files with 3,358 additions and 5,175 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';

import CommentsAdminEditPage from '@/components/pages/admin/admin-comments/pages/edit-comments-page';
import CommentsEditAdminPage from '@/components/pages/admin/admin-comments/edit-comments/CommentsEditAdminPage';

interface AdminCommentEditProps {
params: {
Expand All @@ -10,7 +10,7 @@ interface AdminCommentEditProps {

const AdminCommentEdit: FC<AdminCommentEditProps> = ({ params }) => {
const comment = JSON.parse(decodeURIComponent(params.comment));
return <CommentsAdminEditPage comment={comment} />;
return <CommentsEditAdminPage comment={comment} />;
};

export default AdminCommentEdit;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/comments/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import CommentsAdminPage from '@/components/pages/admin/admin-comments';
import SeacrhCommentsAdminPage from '@/components/pages/admin/admin-comments/search-comments/SeacrhCommentsAdminPage';

const Page = () => {
return <CommentsAdminPage />;
return <SeacrhCommentsAdminPage />;
};

export default Page;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/departments/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
import React from 'react';

import AdminDepartmentsCreatePage from '@/components/pages/admin/admin-departments/admin-departments-create-page/AdminDepartmentsCreatePage';
import CreateDepartmentsAdminPage from '@/components/pages/admin/admin-departments/create-departments/CreateDepartmentsAdminPage';

const Page = () => {
return <AdminDepartmentsCreatePage />;
return <CreateDepartmentsAdminPage />;
};

export default Page;
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@
import React, { FC } from 'react';
import { useQuery } from 'react-query';

import Progress from '@/components/common/ui/progress/Progress';
import AdminDepartmentsEditPage from '@/components/pages/admin/admin-departments/admin-departments-edit-page/AdminDepartmentsEditPage';
import CathedraAPI from '@/lib/api/cathera/CathedraAPI';
import LoadPage from '@/components/common/ui/load-page';
import EditDepartmentsAdminPage from '@/components/pages/admin/admin-departments/edit-departments/EditDepartmentsAdminPage';
import { useQueryAdminOptions } from '@/components/pages/admin/common/constants';
import CathedraAPI from '@/lib/api/cathedras/CathedraAPI';

interface AdminDepartmentEditProps {
params: {
departmentId: string;
};
}
const Page: FC<AdminDepartmentEditProps> = ({ params }) => {
const { data, isSuccess, isLoading } = useQuery('department', () =>
CathedraAPI.getAll(),
const { data: department, isLoading } = useQuery(
['departmentById', params.departmentId],
() => CathedraAPI.getDepartmentById(params.departmentId),
useQueryAdminOptions,
);

if (isLoading) return <Progress />;
if (isLoading) return <LoadPage />;

const department = data?.cathedras.find(cathedra => {
return cathedra.id === params.departmentId;
});
if (!department)
throw new Error('Something went wrong in department edit page');

if (!isSuccess || !department)
return <>Something went wrong with the admin department edit</>;

return <AdminDepartmentsEditPage department={department} />;
return <EditDepartmentsAdminPage department={department.data} />;
};

export default Page;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/departments/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
import React from 'react';

import AdminDepartmentSearchPage from '@/components/pages/admin/admin-departments/admin-departments-search-page/AdminDepartmentSearchPage';
import SearchDepartmentsAdminPage from '@/components/pages/admin/admin-departments/search-departments/SearchDepartmentsAdminPage';

const Page = () => {
return <AdminDepartmentSearchPage />;
return <SearchDepartmentsAdminPage />;
};

export default Page;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/disciplines/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
import React from 'react';

import DisciplinesAdminCreatePage from '@/components/pages/admin/disciplines-admin-page/pages/disciplines-create-page/DisciplinesAdminCreatePage';
import CreateDisciplinesAdminPage from '@/components/pages/admin/admin-disciplines/create-disciplines';

const AdminSubjectCreate = () => {
return <DisciplinesAdminCreatePage />;
return <CreateDisciplinesAdminPage />;
};

export default AdminSubjectCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import React, { FC } from 'react';
import { useQuery } from 'react-query';

import Progress from '@/components/common/ui/progress';
import DisciplinesEditPage from '@/components/pages/admin/disciplines-admin-page/pages/disciplines-edit-page/DisciplinesAdminEditPage';
import LoadPage from '@/components/common/ui/load-page/LoadPage';
import EditDisciplinesAdminPage from '@/components/pages/admin/admin-disciplines/edit-disciplines/EditDisciplinesAdminPage';
import { useQueryAdminOptions } from '@/components/pages/admin/common/constants';
import DisciplineAPI from '@/lib/api/discipline/DisciplineAPI';

interface AdminDisciplineEditProps {
Expand All @@ -14,21 +15,23 @@ interface AdminDisciplineEditProps {

const DisciplinesAdminEdit: FC<AdminDisciplineEditProps> = ({ params }) => {
const {
data: disciplines,
data: discipline,
isSuccess,
isLoading,
} = useQuery('discipline', () => DisciplineAPI.getAllDisciplines());
} = useQuery(
['discipline', params.disciplineId],
() => DisciplineAPI.getDisciplinesById(params.disciplineId),
useQueryAdminOptions,
);

if (isLoading) return <Progress />;
if (isLoading) return <LoadPage />;

const discipline = disciplines?.disciplines.find(discipline => {
return discipline.id === params.disciplineId;
});
if (!isSuccess)
throw new Error(
`An error has occurred while editing ${params.disciplineId} discipline`,
);

if (!isSuccess || !discipline)
return <>Something went wrong with the admin discipline edit</>;

return <DisciplinesEditPage discipline={discipline} />;
return <EditDisciplinesAdminPage discipline={discipline} />;
};

export default DisciplinesAdminEdit;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/disciplines/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
import React from 'react';

import DisciplinesAdminPage from '@/components/pages/admin/disciplines-admin-page/DisciplinesAdminPage';
import SearchDisciplinesAdminPage from '@/components/pages/admin/admin-disciplines/search-disciplines';

const DisciplinesAdminSearch = () => {
return <DisciplinesAdminPage />;
return <SearchDisciplinesAdminPage />;
};

export default DisciplinesAdminSearch;
48 changes: 48 additions & 0 deletions fictadvisor-web/src/app/admin/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use client';
import React from 'react';
import { Box, Typography } from '@mui/material';

import Button from '@/components/common/ui/button';
import {
ButtonColor,
ButtonSize,
ButtonVariant,
} from '@/components/common/ui/button-mui/types';
import getErrorMessage from '@/lib/utils/getErrorMessage';

export default function Error({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
console.log(error);
return (
<Box
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
minHeight: '100vh',
}}
>
<Typography
variant="h4Medium"
style={{ color: 'grey.100', marginBottom: '32px' }}
>
Sorry! {getErrorMessage(error)}
</Typography>
<Box sx={{ maxWidth: '200px' }}>
<Button
text="Спробувати знову"
size={ButtonSize.MEDIUM}
color={ButtonColor.PRIMARY}
variant={ButtonVariant.FILLED}
onClick={reset}
/>
</Box>
</Box>
);
}
2 changes: 1 addition & 1 deletion fictadvisor-web/src/app/admin/groups/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import AdminGroupsCreate from '@/components/pages/admin/admin-groups/create-groups-admin-page/AdminGroupsCreate';
import AdminGroupsCreate from '@/components/pages/admin/admin-groups/create-groups/CreateGroupsAdminPage';

const AdminCreateStudentPage = () => {
return <AdminGroupsCreate />;
Expand Down
18 changes: 13 additions & 5 deletions fictadvisor-web/src/app/admin/groups/edit/[groupId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import React, { FC } from 'react';
import { useQuery } from 'react-query';

import Progress from '@/components/common/ui/progress/Progress';
import AdminGroupsEdit from '@/components/pages/admin/admin-groups/edit-groups-admin-page/AdminGroupsEdit';
import LoadPage from '@/components/common/ui/load-page/LoadPage';
import AdminGroupsEdit from '@/components/pages/admin/admin-groups/edit-groups/AdminGroupsEdit';
import { useQueryAdminOptions } from '@/components/pages/admin/common/constants';
import GroupAPI from '@/lib/api/group/GroupAPI';

interface AdminGroupEditBodyPageProps {
Expand All @@ -18,11 +19,18 @@ const AdminGroupEditBodyPage: FC<AdminGroupEditBodyPageProps> = ({
data: group,
isSuccess,
isLoading,
} = useQuery('getAdminGroup', () => GroupAPI.get(params.groupId));
} = useQuery(
['getAdminGroup', params.groupId],
() => GroupAPI.get(params.groupId),
useQueryAdminOptions,
);

if (isLoading) return <Progress />;
if (isLoading) return <LoadPage />;

if (!isSuccess) return <>Something went wrong with the admin user edit</>;
if (!isSuccess)
throw new Error(
`An error has occurred while editing ${params.groupId} group`,
);

return <AdminGroupsEdit group={group} />;
};
Expand Down
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/groups/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import GroupsAdminPage from '@/components/pages/admin/admin-groups/search-groups-admin-page/AdminGroupsPage';
import SearchGroupsAdminPage from '@/components/pages/admin/admin-groups/search-groups/SearchGroupsAdminPage';

export default async function GroupsAdmin() {
return <GroupsAdminPage />;
return <SearchGroupsAdminPage />;
}
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/questions/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import QuestionsCreatePage from '@/components/pages/admin/questions-admin-page/components/questions-create-page';
import CreateQuestionsAdminPage from '@/components/pages/admin/admin-questions/create-questions/CreateQuestionsAdminPage';

const Page = () => {
return <QuestionsCreatePage />;
return <CreateQuestionsAdminPage />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';

import QuestionsEditPage from '@/components/pages/admin/questions-admin-page/components/questions-edit-page';
import EditQuestionsAdminPage from '@/components/pages/admin/admin-questions/edit-questions/EditQuestionsAdminPage';

interface PageProps {
params: {
Expand All @@ -9,7 +9,7 @@ interface PageProps {
}

const Edit: FC<PageProps> = ({ params }) => {
return <QuestionsEditPage questionId={params.questionId} />;
return <EditQuestionsAdminPage questionId={params.questionId} />;
};

export default Edit;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/questions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import QuestionsAdminPage from '@/components/pages/admin/questions-admin-page/QueationsAdminPage';
import SearchQuestionsAdminPage from '@/components/pages/admin/admin-questions/search-questions';

const Page = () => {
return <QuestionsAdminPage />;
return <SearchQuestionsAdminPage />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC } from 'react';

import AdminGrantsCreate from '@/components/pages/admin/admin-grants/create-grants-page/AdminGrantsCreate';
import CreateGrantsAdminPage from '@/components/pages/admin/admin-grants/create-grants/CreateGrantsAdminPage';

interface AdminGrantsCreatePageProps {
params: {
roleId: string;
Expand All @@ -9,7 +10,7 @@ interface AdminGrantsCreatePageProps {
}

const AdminGrantsCreatePage: FC<AdminGrantsCreatePageProps> = ({ params }) => {
return <AdminGrantsCreate roleId={params.roleId} />;
return <CreateGrantsAdminPage roleId={params.roleId} />;
};

export default AdminGrantsCreatePage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import React, { FC } from 'react';
import { useQuery } from 'react-query';

import Progress from '@/components/common/ui/progress';
import EditGrantsPage from '@/components/pages/admin/admin-grants/edit-grants-page';
import LoadPage from '@/components/common/ui/load-page/LoadPage';
import EditGrantsAdminPage from '@/components/pages/admin/admin-grants/edit-grants/EditGrantsAdminPage';
import { useQueryAdminOptions } from '@/components/pages/admin/common/constants';
import GrantsAPI from '@/lib/api/grants/GrantsAPI';

interface AdminGrantsEditProps {
Expand All @@ -18,15 +19,20 @@ const AdminGrantsEdit: FC<AdminGrantsEditProps> = ({ params }) => {
data: grant,
isSuccess,
isLoading,
} = useQuery('getGrantById', () =>
GrantsAPI.getByGrantId(params.roleId, params.grantId),
} = useQuery(
['getGrantById', params.roleId, params.grantId],
() => GrantsAPI.getByGrantId(params.roleId, params.grantId),
useQueryAdminOptions,
);

if (isLoading) return <Progress />;
if (isLoading) return <LoadPage />;

if (!isSuccess) return <>Something went wrong with the admin grant edit</>;
if (!isSuccess)
throw new Error(
`An error has occurred while editing ${params.grantId} grant`,
);

return <EditGrantsPage grant={grant} roleId={params.roleId} />;
return <EditGrantsAdminPage grant={grant} roleId={params.roleId} />;
};

export default AdminGrantsEdit;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/roles/[roleId]/grants/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import React, { FC } from 'react';

import AdminGrantsSearch from '@/components/pages/admin/admin-grants/search-grants-page/AdminGrantsSearch';
import SearchGrantsAdminPage from '@/components/pages/admin/admin-grants/search-grants/SearchGrantsAdminPage';

interface AdminGrantsEditProps {
params: {
Expand All @@ -10,7 +10,7 @@ interface AdminGrantsEditProps {
}

const AdminGrantsEdit: FC<AdminGrantsEditProps> = ({ params }) => {
return <AdminGrantsSearch roleId={params.roleId} />;
return <SearchGrantsAdminPage roleId={params.roleId} />;
};

export default AdminGrantsEdit;
4 changes: 2 additions & 2 deletions fictadvisor-web/src/app/admin/roles/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import AdminRolesCreate from '@/components/pages/admin/admin-roles/create-roles-page/AdminRolesCreate';
import CreateRolesAdminPage from '@/components/pages/admin/admin-roles/create-roles/CreateRolesAdminPage';

const Create = () => {
return <AdminRolesCreate />;
return <CreateRolesAdminPage />;
};

export default Create;
Loading

0 comments on commit fc8b3b1

Please sign in to comment.