Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
rosewang01 committed Dec 31, 2024
1 parent 9a0ccd7 commit 5c3f832
Show file tree
Hide file tree
Showing 44 changed files with 1,199 additions and 712 deletions.
87 changes: 68 additions & 19 deletions client/src/AdminDashboard/AdminDashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { Typography, Grid } from '@mui/material';
import { Typography, AppBar, Box } from '@mui/material';
import ScreenGrid from '../components/ScreenGrid';
import QuestionTable from './QuestionTable';
import QuestionTable from './Tables/QuestionTable';
import ResourceTable from './Tables/ResourceTable';
import DefinitionTable from './Tables/DefinitionTable';
import NavBar from '../components/NavBar';

/**
Expand All @@ -11,26 +13,73 @@ import NavBar from '../components/NavBar';
function AdminDashboardPage() {
return (
<ScreenGrid>
<Grid
container
direction="row"
justifyContent="space-between"
alignItems="flex-start"
height="100vh"
fit-content="100%"
<AppBar
position="fixed"
sx={{
zIndex: 1,
}}
>
<Grid item width="100%">
<NavBar />
</Grid>
<Grid item marginX="auto">
<NavBar />
</AppBar>
<Box
component="main"
sx={{
mt: '64px',
px: 0,
overflowY: 'auto',
width: '100%',
}}
>
<div
style={{
margin: 'auto',
width: '70vw',
marginTop: '60px',
marginBottom: '60px',
}}
>
<Typography variant="h2">Welcome to the Admin Dashboard</Typography>

<div style={{ height: '60vh', width: '60vw' }}>
{/* <UserTable /> */}
<QuestionTable />
<div
style={{
marginTop: '20px',
marginBottom: '40px',
}}
>
<Typography variant="h5" marginBottom="10px">
Questions
</Typography>
<div style={{ width: '100%', height: '60vh' }}>
<QuestionTable />
</div>
</div>
<div
style={{
marginTop: '40px',
marginBottom: '40px',
}}
>
<Typography variant="h5" marginBottom="10px">
Resources
</Typography>
<div style={{ width: '100%', height: '60vh' }}>
<ResourceTable />
</div>
</div>
<div
style={{
marginTop: '40px',
marginBottom: '40px',
}}
>
<Typography variant="h5" marginBottom="10px">
Definitions
</Typography>
<div style={{ width: '100%', height: '60vh' }}>
<DefinitionTable />
</div>
</div>
</Grid>
</Grid>
</div>
</Box>
</ScreenGrid>
);
}
Expand Down
40 changes: 40 additions & 0 deletions client/src/AdminDashboard/Buttons/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useState } from 'react';
import LoadingButton from '../../components/buttons/LoadingButton';
import ConfirmationModal from '../../components/ConfirmationModal';
import { IDefinition } from '../../util/types/definition';
import { IAnswer } from '../../util/types/answer';

interface DeleteButtonProps {
id: string;
object: IDefinition | IAnswer;
removeRow: (object: IDefinition | IAnswer) => void;
}

function DeleteButton({ id, object, removeRow }: DeleteButtonProps) {
const [isLoading, setLoading] = useState(false);

const isDefinition = (object as IDefinition).word !== undefined;

const bodyString = `Are you sure you want to delete this ${
isDefinition ? 'definition' : 'resource'
}?`;

async function handleDelete() {
setLoading(true);
removeRow(object);
setLoading(false);
}
if (isLoading) {
return <LoadingButton />;
}
return (
<ConfirmationModal
buttonText="Delete"
title={bodyString}
body="This action is permanent. Information will not be able to be recovered."
onConfirm={() => handleDelete()}
/>
);
}

export default DeleteButton;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import Button from '@mui/material/Button';
import { deleteUser } from './api';
import LoadingButton from '../components/buttons/LoadingButton';
import ConfirmationModal from '../components/ConfirmationModal';
import { deleteUser } from '../api';
import LoadingButton from '../../components/buttons/LoadingButton';
import ConfirmationModal from '../../components/ConfirmationModal';

interface DeleteUserButtonProps {
admin: boolean;
Expand Down
39 changes: 39 additions & 0 deletions client/src/AdminDashboard/Buttons/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import Button from '@mui/material/Button';
import { Link } from 'react-router-dom';
import { IQuestion } from '../../util/types/question';
import { IAnswer } from '../../util/types/answer';
import { IDefinition } from '../../util/types/definition';

/**
* Returns the edit button for the object
* @param object - the object to edit
* @returns the edit button for the object
*/

interface EditButtonProps {
object: IQuestion | IAnswer | IDefinition;
}

function EditButton({ object }: EditButtonProps) {
let toPath = '';
if ((object as IQuestion).isQuestion !== undefined) {
toPath = '/edit-question';
} else if ((object as IAnswer).resourceContent !== undefined) {
toPath = '/edit-resource';
} else if ((object as IDefinition).word !== undefined) {
toPath = '/edit-definition';
} else {
toPath = '/home';
}

return (
<div>
<Link to={toPath} state={{ object }} style={{ textDecoration: 'none' }}>
<Button variant="outlined">Edit</Button>
</Link>
</div>
);
}

export default EditButton;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import Button from '@mui/material/Button';
import { upgradePrivilege } from './api';
import LoadingButton from '../components/buttons/LoadingButton';
import ConfirmationModal from '../components/ConfirmationModal';
import { upgradePrivilege } from '../api';
import LoadingButton from '../../components/buttons/LoadingButton';
import ConfirmationModal from '../../components/ConfirmationModal';

interface PromoteUserButtonProps {
admin: boolean;
Expand Down
56 changes: 0 additions & 56 deletions client/src/AdminDashboard/DeleteQuestionButton.tsx

This file was deleted.

90 changes: 90 additions & 0 deletions client/src/AdminDashboard/EditDefinitionPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable no-underscore-dangle */
import React, { useEffect, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';
import {
Typography,
Container,
Box,
Alert,
AlertTitle,
AppBar,
} from '@mui/material';
import { editDefinition } from './api';
import { IDefinition } from '../util/types/definition';
import EditorGUI from '../components/EditorGUI';
import NavBar from '../components/NavBar';
import ScreenGrid from '../components/ScreenGrid';

export default function EditDefinitionPage() {
const defaultDefinition: IDefinition = useLocation().state.object;
const didMountRef = useRef(false);

const [values, setValueState] = useState(defaultDefinition);
const setValue = (field: string, value: any) => {
setValueState((prevState) => ({
...prevState,
...{ [field]: value },
}));
};

useEffect(() => {
if (!didMountRef.current) {
didMountRef.current = true;
} else {
// console.log(values);
editDefinition(values);
}
}, [values]);

return (
<ScreenGrid>
<AppBar
position="fixed"
sx={{
zIndex: 1,
}}
>
<NavBar />
</AppBar>
<Box
component="main"
sx={{
mt: '64px',
px: 0,
overflowY: 'auto',
width: '100%',
}}
>
<Box margin="auto" width="70vw">
<Container sx={{ margin: 4 }}>
<Alert severity="warning" sx={{ marginBottom: 4 }}>
<AlertTitle>
Please make sure that any link you add starts with
<strong>&quot;http://&quot;</strong> or{' '}
<strong>&quot;https://&quot;</strong>!
</AlertTitle>
</Alert>
</Container>
<Container sx={{ margin: 4, width: '100%' }}>
<Typography variant="h5" marginBottom={2}>
Word:
</Typography>
<EditorGUI values={values} setValue={setValue} type="word" />
</Container>
<Container sx={{ margin: 4, width: '100%', padding: 0 }}>
<Typography variant="h5" marginBottom={2}>
Definition:
</Typography>
<EditorGUI values={values} setValue={setValue} type="definition" />
</Container>
<Container sx={{ margin: 4, width: '100%', padding: 0 }}>
<Typography variant="h5" marginBottom={2}>
Link:
</Typography>
<EditorGUI values={values} setValue={setValue} type="link" />
</Container>
</Box>
</Box>
</ScreenGrid>
);
}
Loading

0 comments on commit 5c3f832

Please sign in to comment.