-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add messaging page and validate csv upload headers
- Loading branch information
1 parent
6e5a9f2
commit fff1f17
Showing
8 changed files
with
199 additions
and
34 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
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,59 @@ | ||
import React from "react"; | ||
import IconButton from "@mui/material/IconButton"; | ||
Check warning on line 2 in src/components/common/ConfirmMessageButton.tsx GitHub Actions / Continuous Integration
|
||
import SendIcon from "@mui/icons-material/Send"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogTitle from "@mui/material/DialogTitle"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
import Button from "@mui/material/Button"; | ||
import { useTheme } from "@mui/material"; | ||
import { Recipient, recipientDescriptions } from "../messaging/Messaging"; | ||
|
||
interface ConfirmMessageButtonProps { | ||
recipients: Recipient; | ||
message: string; | ||
setMessage(string): void; | ||
setOpenSnackbar(boolean): void; | ||
setSnackbarMessage(string): void; | ||
} | ||
|
||
export const ConfirmMessageButton = ({ recipients, message, setMessage, setOpenSnackbar, setSnackbarMessage }: ConfirmMessageButtonProps) => { | ||
const [open, setOpen] = React.useState(false); | ||
const theme = useTheme(); | ||
|
||
const handleCloseDialog = () => { | ||
setOpen(false); | ||
}; | ||
|
||
const sendMessage = async (message: string, recipients: Recipient) => { | ||
try { | ||
console.log(message); | ||
console.log(recipients); | ||
setSnackbarMessage("Message successfully sent"); | ||
setMessage(""); | ||
} catch { | ||
setSnackbarMessage("Failed to send message"); | ||
} | ||
setOpenSnackbar(true); | ||
handleCloseDialog(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Dialog open={open} onClose={handleCloseDialog} maxWidth='sm'> | ||
<DialogTitle> Are you sure you want to send message to {recipientDescriptions[recipients]}? </DialogTitle> | ||
<DialogActions sx={{ mr: 1 }}> | ||
<Button sx={{ backgroundColor: theme.palette.error.main }} onClick={handleCloseDialog}>Do not Send</Button> | ||
<Button sx={{ backgroundColor: theme.palette.success.main }} onClick={() => sendMessage(message, recipients)}>Send</Button> | ||
</DialogActions> | ||
</Dialog> | ||
<Button | ||
endIcon={<SendIcon />} | ||
sx={{ | ||
backgroundColor: theme.palette.success.main, | ||
my: 1 | ||
}} | ||
onClick={() => setOpen(true)} | ||
>Send</Button> | ||
</> | ||
); | ||
}; |
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,90 @@ | ||
import React, { useState } from "react"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import TextField from "@mui/material/TextField"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import Stack from "@mui/material/Stack"; | ||
import Typography from "@mui/material/Typography"; | ||
import { useTheme } from "@mui/material/styles"; | ||
import MenuItem from "@mui/material/MenuItem"; | ||
import Select from "@mui/material/Select"; | ||
import { useSnackbar } from "../../hooks/useSnackbar"; | ||
import { ConfirmMessageButton } from "../common/ConfirmMessageButton"; | ||
import { getAuth } from "firebase/auth"; | ||
import useGetAdmins from "../../hooks/useGetAdmins"; | ||
|
||
export enum Recipient { | ||
All = "All", | ||
PickedUp = "PickedUp", | ||
NotPickedUp = "NotPickedUp" | ||
} | ||
|
||
export const recipientDescriptions = { | ||
"All": "All Donors", | ||
"PickedUp": "Donors who have picked up", | ||
"NotPickedUp": "Donors who have not picked up" | ||
}; | ||
|
||
export default function Messaging() { | ||
const theme = useTheme(); | ||
const auth = getAuth(); | ||
const { data: admins, isLoading: loadingAdmins } = useGetAdmins(); | ||
|
||
const { setOpenSnackbar, setSnackbarMessage, snackbar } = useSnackbar(); | ||
|
||
const [message, setMessage] = useState(""); | ||
const [recipients, setRecipients] = useState(Recipient.All); | ||
|
||
return ( | ||
<> | ||
<Box | ||
sx={{ | ||
flexGrow: 1, | ||
height: "100%", | ||
marginBottom: "3%" | ||
}} | ||
> | ||
<Box sx={{ mx: 2 }}> | ||
<Typography fontSize={30} sx={{ borderBottom: "solid", borderWidth: 2, borderColor: "primary.main", mb: 2, width: "100%" }}>Messaging</Typography> | ||
{ | ||
!loadingAdmins && admins?.map((admin) => admin.email).indexOf(auth.currentUser?.email ?? "") !== -1 ? ( | ||
<> | ||
<Stack my={2} direction="row" alignItems="center"> | ||
<Typography variant="h6">Select Recipients:</Typography> | ||
<Select | ||
value={recipients} | ||
onChange={(e) => setRecipients(e.target.value as Recipient)} | ||
sx={{ my: 1, mx: 2 }} | ||
> | ||
<MenuItem value={Recipient.All}>{recipientDescriptions.All}</MenuItem> | ||
<MenuItem value={Recipient.PickedUp}>{recipientDescriptions.PickedUp}</MenuItem> | ||
<MenuItem value={Recipient.NotPickedUp}>{recipientDescriptions.NotPickedUp}</MenuItem> | ||
</Select> | ||
</Stack> | ||
<TextField | ||
variant="outlined" | ||
multiline | ||
fullWidth | ||
placeholder="Enter Message" | ||
minRows={3} | ||
value={message} | ||
onChange={(e) => setMessage(e.target.value)} | ||
/> | ||
<ConfirmMessageButton message={message} setMessage={setMessage} recipients={recipients} setOpenSnackbar={setOpenSnackbar} setSnackbarMessage={setSnackbarMessage} /><Button | ||
endIcon={<DeleteIcon />} | ||
sx={{ | ||
backgroundColor: theme.palette.error.main, | ||
my: 1, | ||
mx: 1 | ||
}} | ||
onClick={() => setMessage("")} | ||
>Clear</Button> | ||
</> | ||
) : <Typography my={1} variant="h6">Only site admins can use this feature</Typography> | ||
} | ||
{snackbar} | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
} |
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,11 @@ | ||
import React from "react"; | ||
import { Dashboard } from "../components/dashboard/Dashboard"; | ||
import Messaging from "../components/messaging/Messaging"; | ||
|
||
export default function MessagingPage() { | ||
return ( | ||
<Dashboard> | ||
<Messaging /> | ||
</Dashboard> | ||
); | ||
} |
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