Skip to content

Commit

Permalink
Merge branch '536-Enhancement-Confirmation_Modal_For_Uploading_Docs' of
Browse files Browse the repository at this point in the history
https://github.com/codeforpdx/PASS into 536-Enhancement-Confirmation_Modal_For_Uploading_Docs
  • Loading branch information
rioredwards committed Nov 30, 2023
2 parents 876484d + 385665a commit 2c15e18
Show file tree
Hide file tree
Showing 31 changed files with 604 additions and 502 deletions.
4 changes: 3 additions & 1 deletion src/components/CivicProfileForms/HousingInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// React Imports
import React, { useState, useEffect } from 'react';
// MUI Imports
import { TextField, Button } from '@mui/material';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
// Custom Hooks Imports
import { useCivicProfile } from '@hooks';

/**
Expand Down
3 changes: 3 additions & 0 deletions src/components/Footer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Footer from './Footer';

export default Footer;
2 changes: 1 addition & 1 deletion src/components/Messages/MessageFolder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { EmptyListNotification, LoadingAnimation } from '../Notification';
* @param {object} Props - Component props for MessageFolder
* @param {string} Props.folderType - The name of the message box, i.e. "inbox"
* or "outbox"
* @param {() => Promise<void>} Props.handleRefresh - The handle function for
* @param {(folderType: string) => Promise<void>} Props.handleRefresh - The handle function for
* message folder refresh
* @param {boolean} Props.loadMessages - Boolean for triggering loading message
* @param {messageListObject[]} Props.messageList - A list of messages from
Expand Down
108 changes: 50 additions & 58 deletions src/components/Messages/MessagePreview.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React Imports
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
// Material UI Imports
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
Expand All @@ -12,11 +12,7 @@ import Typography from '@mui/material/Typography';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTheme } from '@mui/material/styles';
// Custom Hook Imports
import { useSession } from '@hooks';
// Utility Imports
import { updateMessageReadStatus, getMessageTTL } from '@utils';
// Context Imports
import { MessageContext, SignedInUserContext } from '@contexts';
import { useMessageList } from '@hooks';
// Component Imports
import { NewMessageModal } from '../Modals';

Expand All @@ -38,18 +34,13 @@ import { NewMessageModal } from '../Modals';
const MessagePreview = ({ message, folderType }) => {
const [showContents, setShowContents] = useState(false);
const [showModal, setShowModal] = useState(false);
const { session } = useSession();
const { podUrl } = useContext(SignedInUserContext);
const { inboxList, setInboxList } = useContext(MessageContext);
const { add: updateReadStatus } = useMessageList('Inbox');

const handleClick = async () => {
setShowContents(!showContents);
if (folderType === 'Inbox') {
if (folderType === 'Inbox' && !message.readStatus) {
try {
await updateMessageReadStatus(session, message);
const messagesInSolid = await getMessageTTL(session, folderType, inboxList, podUrl);
messagesInSolid.sort((a, b) => b.uploadDate - a.uploadDate);
setInboxList(messagesInSolid);
await updateReadStatus(message);
} catch {
throw new Error('Failed to update read status');
}
Expand Down Expand Up @@ -93,52 +84,53 @@ const MessagePreview = ({ message, folderType }) => {
];

return (
<Container sx={{ wordWrap: 'break-word' }}>
<Paper>
<Box sx={{ flexGrow: 1 }}>
<ListItemButton onClick={() => handleClick()} alignItems="flex-start">
<Grid container columnSpacing={1} sx={{ padding: isSmallScreen ? '0' : '10px' }}>
{messageInfo.map((info, index) => (
<Grid
item
xs={info.xs_value}
sx={{ opacity: message.readStatus ? '0.5' : '1' }}
key={info.title + String(index)}
>
<Typography>
{info.title} <strong>{info.text}</strong>
</Typography>
</Grid>
))}

{showContents && (
<Grid item xs={12}>
<Divider />
{message.message.split('\n').map((line, index) => (
<Typography sx={{ padding: '10px 5px' }} key={line + String(index)}>
{line}
<>
<Container sx={{ wordWrap: 'break-word' }}>
<Paper>
<Box sx={{ flexGrow: 1 }}>
<ListItemButton
onClick={handleClick}
alignItems="flex-start"
aria-label={`open message preview ${message.messageId}`}
>
<Grid container columnSpacing={1} sx={{ padding: isSmallScreen ? '0' : '10px' }}>
{messageInfo.map((info, index) => (
<Grid
item
xs={info.xs_value}
sx={{ opacity: message.readStatus ? '0.5' : '1' }}
key={info.title + String(index)}
>
<Typography>
{info.title} <strong>{info.text}</strong>
</Typography>
))}
{showContents && folderType === 'Inbox' && (
<Button variant="contained" type="button" onClick={handleReplyMessage}>
Reply
</Button>
)}
</Grid>
)}
</Grid>
</Grid>
))}

{showModal && (
<NewMessageModal
showModal={showModal}
setShowModal={setShowModal}
oldMessage={message}
/>
)}
</ListItemButton>
</Box>
</Paper>
</Container>
{showContents && (
<Grid item xs={12}>
<Divider />
{message.message.split('\n').map((line, index) => (
<Typography sx={{ padding: '10px 5px' }} key={line + String(index)}>
{line}
</Typography>
))}
{showContents && folderType === 'Inbox' && (
<Button variant="contained" type="button" onClick={handleReplyMessage}>
Reply
</Button>
)}
</Grid>
)}
</Grid>
</ListItemButton>
</Box>
</Paper>
</Container>
{showModal && (
<NewMessageModal showModal={showModal} setShowModal={setShowModal} oldMessage={message} />
)}
</>
);
};

Expand Down
15 changes: 5 additions & 10 deletions src/components/Modals/NewMessageModal.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// React Imports
import React, { useContext, useEffect, useState } from 'react';
// Inrupt Library Imports
import { useNotification, useSession } from '@hooks';
import { useMessageList, useNotification, useSession } from '@hooks';
// Material UI Imports
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
Expand All @@ -14,9 +14,9 @@ import Typography from '@mui/material/Typography';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTheme } from '@mui/material/styles';
// Utility Imports
import { sendMessageTTL, getMessageTTL } from '@utils';
import { sendMessageTTL } from '@utils';
// Context Imports
import { MessageContext, SignedInUserContext } from '@contexts';
import { SignedInUserContext } from '@contexts';

/**
* @typedef {import("../../typedefs.js").messageListObject} messageListObject
Expand All @@ -39,7 +39,7 @@ import { MessageContext, SignedInUserContext } from '@contexts';
*/
const NewMessageModal = ({ showModal, setShowModal, oldMessage = '', toField = '' }) => {
const { session } = useSession();
const { outboxList, setOutboxList } = useContext(MessageContext);
const { refetch: refreshOutbox } = useMessageList('Outbox');
const { podUrl } = useContext(SignedInUserContext);
const { addNotification } = useNotification();
const [originalMessage, setOriginalMessage] = useState(oldMessage.message);
Expand Down Expand Up @@ -107,12 +107,7 @@ const NewMessageModal = ({ showModal, setShowModal, oldMessage = '', toField = '
}, 2000);
}
}

// Re-sorts messages when new message is added to outboxList
const outboxMessages = await getMessageTTL(session, 'Outbox', outboxList, podUrl);
const sortedOutbox = outboxMessages;
sortedOutbox.sort((a, b) => b.uploadDate - a.uploadDate);
setOutboxList(sortedOutbox);
await refreshOutbox();
};

/* eslint-disable jsx-a11y/label-has-associated-control */
Expand Down
7 changes: 5 additions & 2 deletions src/components/NavBar/NavMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import SettingsIcon from '@mui/icons-material/Settings';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTheme } from '@mui/material/styles';
// Context Imports
import { DocumentListContext, MessageContext } from '@contexts';
import { DocumentListContext } from '@contexts';
import { useMessageList } from '@hooks';

/**
* NavMenu Component - Component that generates NavMenu section for PASS
Expand Down Expand Up @@ -52,7 +53,9 @@ const NavMenu = ({
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
const { setContact } = useContext(DocumentListContext);
const { numUnreadMessages } = useContext(MessageContext);
const { data } = useMessageList('Inbox');

const numUnreadMessages = data?.reduce((a, m) => (!m.readStatus ? a + 1 : a), 0);

const handleMenuClose = () => {
setOpenMenu(false);
Expand Down
8 changes: 6 additions & 2 deletions src/components/NavBar/NavbarDesktop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import MenuItem from '@mui/material/MenuItem';
import NotificationsIcon from '@mui/icons-material/Notifications';
import Toolbar from '@mui/material/Toolbar';
import { useTheme } from '@mui/material/styles';
// Custom Hook Imports
import { useMessageList } from '@hooks';
// Component Imports
import { MessageContext, SignedInUserContext } from '@contexts';
import { SignedInUserContext } from '@contexts';
import NavbarLinks from './NavbarLinks';
import NavMenu from './NavMenu';

Expand All @@ -32,7 +34,9 @@ import NavMenu from './NavMenu';
*/
const NavbarDesktop = ({ setShowConfirmation }) => {
const theme = useTheme();
const { numUnreadMessages } = useContext(MessageContext);
const { data } = useMessageList('Inbox');

const numUnreadMessages = data?.reduce((a, m) => (!m.readStatus ? a + 1 : a), 0);

// states for NavMenu component
const [anchorEl, setAnchorEl] = useState(null);
Expand Down
8 changes: 4 additions & 4 deletions src/constants/HMIS_ONTOLOGY_VALUES.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const prefix = 'urn:hud:hmis:owl#';

const HMIS_ONTOLOGY_VALUES = {
legalFirstName: 'urn:hud:hmis:owl#FirstName',
legalLastName: 'urn:hud:hmis:owl#LastName',
legalDOB: 'urn:hud:hmis:owl#DOB',
legalGender: 'urn:hud:hmis:owl#Gender',
legalFirstName: `${prefix}FirstName`,
legalLastName: `${prefix}LastName`,
legalDOB: `${prefix}DOB`,
legalGender: `${prefix}Gender`,
lastPermanentCity: `${prefix}LastPermanentCity`,
lastPermanentState: `${prefix}LastPermanentState`,
lastPermanentStreet: `${prefix}LastPermanentStreet`,
Expand Down
86 changes: 0 additions & 86 deletions src/contexts/MessageContext.jsx

This file was deleted.

10 changes: 2 additions & 8 deletions src/contexts/UserDataContext.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// React Imports
import React from 'react';
// Context Imports
import {
MessageContextProvider,
DocumentListContextProvider,
SignedInUserContextProvider
} from '.';
import { DocumentListContextProvider, SignedInUserContextProvider } from '.';

/**
* A collection of React Contexts used for PASS to be used as a single wrapper
Expand All @@ -18,9 +14,7 @@ import {
*/
const UserDataContextProvider = ({ children }) => (
<SignedInUserContextProvider>
<DocumentListContextProvider>
<MessageContextProvider>{children}</MessageContextProvider>
</DocumentListContextProvider>
<DocumentListContextProvider>{children}</DocumentListContextProvider>
</SignedInUserContextProvider>
);

Expand Down
1 change: 0 additions & 1 deletion src/contexts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
*/

export * from './SignedInUserContext';
export * from './MessageContext';
export * from './DocumentListContext';
export * from './SessionContext';
3 changes: 2 additions & 1 deletion src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import useContactsList from './useContactsList';
import useNotification from './useNotification';
import useCivicProfile from './useCivicProfile';
import useSession from './useSession';
import useMessageList from './useMessageList';
/**
* The hooks module contains custom hooks to assist with form handling or status
* notifications
*
* @namespace hooks
*/

export { useContactsList, useNotification, useSession, useCivicProfile };
export { useContactsList, useNotification, useSession, useCivicProfile, useMessageList };
Loading

0 comments on commit 2c15e18

Please sign in to comment.