generated from hack4impact-upenn/boilerplate-s2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a0ccd7
commit 5c3f832
Showing
44 changed files
with
1,199 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
6 changes: 3 additions & 3 deletions
6
...t/src/AdminDashboard/DeleteUserButton.tsx → ...minDashboard/Buttons/DeleteUserButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
6 changes: 3 additions & 3 deletions
6
.../src/AdminDashboard/PromoteUserButton.tsx → ...inDashboard/Buttons/PromoteUserButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"http://"</strong> or{' '} | ||
<strong>"https://"</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> | ||
); | ||
} |
Oops, something went wrong.