Skip to content

Commit

Permalink
fix console warnings (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansonjwhe authored Apr 12, 2024
1 parent 19ba73a commit bcae6f7
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 117 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/CommentInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const HOTKEYS = {
const cleanInput = (val) => {
const textList = val.map((item) => item['children'][0]['text'])

const firstIndex = textList.findIndex((text) => text != '')
if (firstIndex == -1) {
const firstIndex = textList.findIndex((text) => text !== '')
if (firstIndex === -1) {
return []
}

const lastIndex = textList.findLastIndex((text) => text != '')
const lastIndex = textList.findLastIndex((text) => text !== '')

return val.slice(firstIndex, lastIndex + 1)
}

//Disables the "send" button if input isn't valid
const invalidInput = (val) => {
for (let i = 0; i < val.length; i++) {
if (val[i]['children'][0]['text'] != '') {
if (val[i]['children'][0]['text'] !== '') {
return false
}
}
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/CommentSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const CommentSection = ({ ticket, allUsers }) => {
.then((data) => {
setComments([...data.data])
forceRefresh()
console.log(data)
})
.then(() => {
setLoading(false)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/CommentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const CommentView = ({ comment, allUsers, getComments }) => {
{comment.replies.map((reply) => {
return (
<ReplyView
key={reply._id}
parent={comment}
comment={reply}
allUsers={allUsers}
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/components/ReporterInfoTableRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react'
import { Th, Tr, PopoverTrigger, Td } from '@chakra-ui/react'

const ReporterTableRow = (props) => {
const { heading, reporter } = props

return (
<Tr borderTopWidth="2px" borderBottomWidth="2px">
<Th
w="185px"
fontSize={{ base: 'xs', md: 'sm' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
}}
>
{heading}
</Th>

{!reporter ? (
<Td
fontSize={{ base: 'sm', md: 'md' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
}}
>
No Reporter
</Td>
) : (
<PopoverTrigger>
<Td
fontSize={{ base: 'sm', md: 'md' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
}}
cursor="pointer"
>
{reporter.displayName}
</Td>
</PopoverTrigger>
)}
</Tr>
)
}

export default ReporterTableRow
115 changes: 31 additions & 84 deletions frontend/src/components/ReporterInfoTip.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,43 @@
import React from 'react'
import {
Th,
Tr,
Text,
Image,
Box,
Popover,
PopoverTrigger,
PopoverContent,
HStack,
Td,
} from '@chakra-ui/react'
import { Text, Image, Box, PopoverContent, HStack } from '@chakra-ui/react'

const ReporterInfoTip = (props) => {
const { heading, reporter } = props
const ReporterInfoTip = ({ reporter }) => {
if (!reporter) return null

return (
<Tr borderTopWidth="2px" borderBottomWidth="2px">
<Th
w="185px"
fontSize={{ base: 'xs', md: 'sm' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
}}
>
{heading}
</Th>

{!reporter ? (
<Td
fontSize={{ base: 'sm', md: 'md' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
}}
>
No Reporter
</Td>
) : (
<Popover trigger="hover" closeDelay={200} placement="top-start">
<PopoverTrigger>
<PopoverContent zIndex="tooltip" width="auto">
<Box px={4} py={4}>
<HStack spacing="12px">
<Image
boxSize="50px"
objectFit="cover"
src={reporter.photoURL}
alt="reporter photo"
/>
<Box flex="1">
<Text
fontSize={{ base: 'sm', md: 'md' }}
p={{
base: '4px 4px',
sm: '8px 8px',
lg: '12px 24px',
fontSize={{
base: 'sm',
md: 'md',
lg: 'lg',
}}
cursor="pointer"
as="b"
color="blue.600"
>
{reporter.displayName}
</Text>
</PopoverTrigger>
<PopoverContent zIndex="tooltip" width="auto">
<Box px={4} py={4}>
<HStack spacing="12px">
<Image
boxSize="50px"
objectFit="cover"
src={reporter.photoURL}
alt="reporter photo"
/>
<Box flex="1">
<Text
fontSize={{
base: 'sm',
md: 'md',
lg: 'lg',
}}
as="b"
color="blue.600"
>
{reporter.displayName}
</Text>
<br />
<Text
fontSize={{ base: 'xs', md: 'sm' }}
as="u"
color="gray.600"
>
{reporter.email}
</Text>
</Box>
</HStack>
</Box>
</PopoverContent>
</Popover>
)}
</Tr>
<br />
<Text
fontSize={{ base: 'xs', md: 'sm' }}
as="u"
color="gray.600"
>
{reporter.email}
</Text>
</Box>
</HStack>
</Box>
</PopoverContent>
)
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/TicketContent/UPRAdminContentTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { useGetCurrentTicket } from '../../hooks/hooks'
const UPRAdminContentTable = () => {
const location = useLocation()
const currentTicket = useGetCurrentTicket()
const [reqNum, setReqNum] = useState(currentTicket.requisition_number)
const [poNum, setPoNum] = useState(currentTicket.po_number)
const [reqNum, setReqNum] = useState('')
const [poNum, setPoNum] = useState('')
const [changed, setChanged] = React.useState(false)
const setAllTickets = useSetRecoilState(allTicketsState)
const changeReqNumber = (e) => {
Expand Down
76 changes: 50 additions & 26 deletions frontend/src/pages/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useDisclosure,
Grid,
useToast,
Popover,
} from '@chakra-ui/react'
import TreeView from '../components/TreeView'
import Navbar from '../components/Navbar'
Expand Down Expand Up @@ -45,6 +46,7 @@ import PPRReporterTable from '../components/TicketContent/PPRReporterTable'
import ClaimSummary from './ClaimSummary'
import { createErrorMessage } from '../utils/errorToasts'
import { useGetCurrentTicket } from '../hooks/hooks'
import ReporterTableRow from '../components/ReporterInfoTableRow'

const Dashboard = () => {
const navigate = useNavigate()
Expand Down Expand Up @@ -313,30 +315,42 @@ const Dashboard = () => {
<Heading mb="8px" fontSize="2xl">
Metadata
</Heading>
<Table>
<Tbody>
<ReporterInfoTip
heading={'Reporter Id'}
reporter={allUsers.users.find(
(user) =>
user.uid ===
currentTicket.reporter_id
)}
/>
<TicketContentTableRow
heading={'Created at'}
value={getStandardizedDate(
currentTicket.createdAt
)}
/>
<TicketContentTableRow
heading={'Updated at'}
value={getStandardizedDate(
currentTicket.updatedAt
)}
/>
</Tbody>
</Table>
<Popover
trigger="hover"
closeDelay={200}
placement="top-start"
>
<Table>
<Tbody>
<ReporterTableRow
heading={'Reporter Id'}
reporter={allUsers.users.find(
(user) =>
user.uid ===
currentTicket.reporter_id
)}
/>
<TicketContentTableRow
heading={'Created at'}
value={getStandardizedDate(
currentTicket.createdAt
)}
/>
<TicketContentTableRow
heading={'Updated at'}
value={getStandardizedDate(
currentTicket.updatedAt
)}
/>
</Tbody>
</Table>
<ReporterInfoTip
reporter={allUsers.users.find(
(user) =>
user.uid === currentTicket.reporter_id
)}
/>
</Popover>
</Box>
{supportingDocuments.length > 0 && (
<Box w="100%" mt="12px">
Expand All @@ -345,7 +359,12 @@ const Dashboard = () => {
</Heading>
<Grid gap="5px">
{supportingDocuments?.map((file) => {
return <FileViewer file={file} />
return (
<FileViewer
key={file._id}
file={file}
/>
)
})}
</Grid>
</Box>
Expand All @@ -357,7 +376,12 @@ const Dashboard = () => {
</Heading>
<Grid gap="5px">
{attachments?.map((file) => {
return <FileViewer file={file} />
return (
<FileViewer
key={file._id}
file={file}
/>
)
})}
</Grid>
</Box>
Expand Down

0 comments on commit bcae6f7

Please sign in to comment.