Skip to content

Commit

Permalink
Log Record Row Expansion (#217)
Browse files Browse the repository at this point in the history
* create new view log component

* adding edit button functionality

* small fixes

* modal styling

---------

Co-authored-by: Connor Bechthold <[email protected]>
  • Loading branch information
braydonwang and Connor Bechthold authored Jan 7, 2024
1 parent 101e042 commit 53d0a8c
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 10 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/forms/CreateLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { getLocalStorageObj } from "../../utils/LocalStorageUtils";
import AUTHENTICATED_USER_KEY from "../../constants/AuthConstants";
import LogRecordAPIClient from "../../APIClients/LogRecordAPIClient";
import BuildingAPIClient from "../../APIClients/BuildingAPIClient";
import selectStyle from "../../theme/forms/selectStyles";
import { selectStyle } from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
import { Resident } from "../../types/ResidentTypes";
import combineDateTime from "../../helper/combineDateTime";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/CreateResident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SingleDatepicker } from "chakra-dayzed-datepicker";
import { Col, Row } from "react-bootstrap";
import CreateToast from "../common/Toasts";

import selectStyle from "../../theme/forms/selectStyles";
import { selectStyle } from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
import ResidentAPIClient from "../../APIClients/ResidentAPIClient";
import BuildingAPIClient from "../../APIClients/BuildingAPIClient";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/EditLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AuthenticatedUser } from "../../types/AuthTypes";
import { getLocalStorageObj } from "../../utils/LocalStorageUtils";
import AUTHENTICATED_USER_KEY from "../../constants/AuthConstants";
import LogRecordAPIClient from "../../APIClients/LogRecordAPIClient";
import selectStyle from "../../theme/forms/selectStyles";
import { selectStyle } from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
import { LogRecord } from "../../types/LogRecordTypes";
import { combineDateTime } from "../../helper/dateHelpers";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/EditResident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { SingleDatepicker } from "chakra-dayzed-datepicker";
import { Col, Row } from "react-bootstrap";
import ResidentAPIClient from "../../APIClients/ResidentAPIClient";
import { Resident } from "../../types/ResidentTypes";
import selectStyle from "../../theme/forms/selectStyles";
import { selectStyle } from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
import CreateToast from "../common/Toasts";
import { convertToDate, convertToString } from "../../helper/dateHelpers";
Expand Down
252 changes: 252 additions & 0 deletions frontend/src/components/forms/ViewLog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/* eslint-disable prettier/prettier */
import React, { useEffect, useState } from "react";
import Select from "react-select";
import {
Box,
Button,
Checkbox,
Divider,
FormControl,
FormLabel,
Grid,
GridItem,
Input,
Modal,
ModalBody,
ModalContent,
ModalOverlay,
ModalHeader,
Text,
Textarea,
ModalFooter,
} from "@chakra-ui/react";
import { Col, Row } from "react-bootstrap";
import { AuthenticatedUser } from "../../types/AuthTypes";
import { getLocalStorageObj } from "../../utils/LocalStorageUtils";
import AUTHENTICATED_USER_KEY from "../../constants/AuthConstants";
import { viewStyle} from "../../theme/forms/selectStyles";
import { LogRecord } from "../../types/LogRecordTypes";
import { SelectLabel } from "../../types/SharedTypes";

type Props = {
logRecord: LogRecord;
isOpen: boolean;
toggleClose: () => void;
toggleEdit: () => void;
employeeOptions: SelectLabel[];
residentOptions: SelectLabel[];
buildingOptions: SelectLabel[];
tagOptions: SelectLabel[];
};

// Helper to get the currently logged in user
const getCurUserSelectOption = () => {
const curUser: AuthenticatedUser | null = getLocalStorageObj(
AUTHENTICATED_USER_KEY,
);
if (curUser && curUser.firstName) {
return curUser.firstName
}
return "";
};

const ViewLog = ({
logRecord,
isOpen,
toggleClose,
toggleEdit,
employeeOptions,
residentOptions,
buildingOptions,
tagOptions,
}: Props) => {
const [date, setDate] = useState(new Date());
const [time, setTime] = useState(
date.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
hour12: false,
}),
);

const initializeValues = () => {
// set state variables
setDate(new Date(logRecord.datetime));
setTime(
date.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
hour12: false,
}),
);
};

const formatDate = (dateObj: Date) => {
return dateObj.toISOString().slice(0, 10);
}

const handleEdit = () => {
toggleClose();
setTimeout(toggleEdit, 400);
}

useEffect(() => {
if (isOpen) {
initializeValues();
}
}, [isOpen]);

return (
<>
<Box>
<Modal isOpen={isOpen} scrollBehavior="inside" onClose={toggleClose} size="xl">
<ModalOverlay />
<ModalContent>
<ModalHeader>View Log Entry Details</ModalHeader>
<ModalBody>
<Divider />
<Row style={{ marginTop: "16px" }}>
<Col>
<FormControl>
<FormLabel>Employee</FormLabel>
<Input
isDisabled
defaultValue={getCurUserSelectOption()}
_disabled={{ bg: "transparent" }}
_hover={{ borderColor: "teal.100" }}
/>
</FormControl>
</Col>
<Col>
<Grid templateColumns="repeat(2, 1fr)" gap="8px">
<GridItem minWidth="100%">
<FormControl>
<FormLabel>Date</FormLabel>
<Input
isDisabled
defaultValue={formatDate(date)}
_disabled={{ bg: "transparent" }}
_hover={{ borderColor: "teal.100" }}
/>
</FormControl>
</GridItem>
<GridItem minWidth="100%">
<FormControl>
<FormLabel>Time</FormLabel>
<Input
isDisabled
size="md"
type="time"
defaultValue={time}
_disabled={{ bg: "transparent" }}
_hover={{ borderColor: "teal.100" }}
/>
</FormControl>
</GridItem>
</Grid>
</Col>
</Row>

<Row>
<Col>
<FormControl mt={4}>
<FormLabel>Building</FormLabel>
<Input
isDisabled
defaultValue={logRecord.building.name}
_disabled={{ bg: "transparent" }}
_hover={{ borderColor: "teal.100" }}
/>
</FormControl>
</Col>
<Col>
<FormControl mt={4}>
<FormLabel>Residents</FormLabel>
<Select
isDisabled
isMulti
components={{ DropdownIndicator: () => null, MultiValueRemove: () => null }}
defaultValue={residentOptions.filter(
(item) => logRecord.residents.includes(item.label),
)}
styles={viewStyle}
/>
</FormControl>
</Col>
</Row>

<Row>
<Col>
<FormControl mt={4}>
<FormLabel>Tags</FormLabel>
<Select
isDisabled
isMulti
components={{ DropdownIndicator: () => null, MultiValueRemove: () => null }}
placeholder="No Tags"
defaultValue={tagOptions.filter(
(item) => logRecord.tags.includes(item.label),
)}
styles={viewStyle}
/>
</FormControl>
</Col>
<Col>
<FormControl mt={4}>
<FormLabel>Attention To</FormLabel>
<Input
isDisabled
placeholder="No Attn To"
defaultValue={logRecord.attnTo?.firstName}
_disabled={{ bg: "transparent" }}
_hover={{ borderColor: "teal.100" }}
/>
</FormControl>
</Col>
</Row>

<Checkbox
colorScheme="gray"
style={{ paddingTop: "1rem", pointerEvents: "none" }}
marginBottom="16px"
defaultChecked={logRecord.flagged}
>
<Text>Flagged</Text>
</Checkbox>

<Divider />

<Row>
<Col>
<FormControl mt={4}>
<FormLabel>Notes</FormLabel>
<Text whiteSpace="pre-wrap">
{logRecord.note}
</Text>
</FormControl>
</Col>
</Row>
</ModalBody>

<ModalFooter>
<Box textAlign="right" marginTop="12px" marginBottom="12px">
<Button
onClick={toggleClose}
variant="tertiary"
marginRight="8px"
>
Cancel
</Button>
<Button onClick={handleEdit} variant="primary" type="submit">
Edit
</Button>
</Box>
</ModalFooter>
</ModalContent>
</Modal>
</Box>
</>
);
};

export default ViewLog;
2 changes: 1 addition & 1 deletion frontend/src/components/pages/HomePage/HomePageFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SmallCloseIcon } from "@chakra-ui/icons";
import { Card } from "react-bootstrap";
import Select, { MultiValue, SingleValue } from "react-select";
import { SingleDatepicker } from "chakra-dayzed-datepicker";
import selectStyle from "../../../theme/forms/selectStyles";
import { selectStyle } from "../../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../../theme/forms/datePickerStyles";
import { Resident } from "../../../types/ResidentTypes";
import { Tag } from "../../../types/TagTypes";
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/components/pages/HomePage/LogRecordsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import getFormattedDateAndTime from "../../../utils/DateUtils";
import AuthContext from "../../../contexts/AuthContext";

import EditLog from "../../forms/EditLog";
import ViewLog from "../../forms/ViewLog";
import LogRecordAPIClient from "../../../APIClients/LogRecordAPIClient";
import ResidentAPIClient from "../../../APIClients/ResidentAPIClient";
import TagAPIClient from "../../../APIClients/TagAPIClient";
Expand Down Expand Up @@ -90,6 +91,9 @@ const LogRecordsTable = ({
const [editOpenMap, setEditOpenMap] = useState<{ [key: number]: boolean }>(
{},
);
const [viewOpenMap, setViewOpenMap] = useState<{ [key: number]: boolean }>(
{},
);

// Dropdown option states
const [employeeOptions, setEmployeeOptions] = useState<SelectLabel[]>([]);
Expand All @@ -112,6 +116,14 @@ const LogRecordsTable = ({
}));
};

// Handle view form toggle
const handleViewToggle = (logId: number) => {
setViewOpenMap((prevViewOpenMap) => ({
...prevViewOpenMap,
[logId]: !prevViewOpenMap[logId],
}));
};

// fetch resident + employee + tag data for log creation
const getLogEntryOptions = async () => {
const residentsData = await ResidentAPIClient.getResidents({
Expand Down Expand Up @@ -243,6 +255,11 @@ const LogRecordsTable = ({
variant="ghost"
/>
<MenuList>
<MenuItem
onClick={() => handleViewToggle(record.logId)}
>
View Log Record
</MenuItem>
<MenuItem
onClick={() => handleEditToggle(record.logId)}
>
Expand Down Expand Up @@ -273,6 +290,17 @@ const LogRecordsTable = ({
buildingOptions={buildingOptions}
/>

<ViewLog
logRecord={record}
isOpen={viewOpenMap[record.logId]}
toggleClose={() => handleViewToggle(record.logId)}
toggleEdit={() => handleEditToggle(record.logId)}
employeeOptions={employeeOptions}
residentOptions={residentOptions}
buildingOptions={buildingOptions}
tagOptions={tagOptions}
/>

<ConfirmationModal
header={DELETE_CONFIRMATION_HEADER}
message={DELETE_CONFIRMATION_MESSAGE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CloseIcon, SmallCloseIcon } from "@chakra-ui/icons";
import { Card } from "react-bootstrap";
import Select, { MultiValue, SingleValue } from "react-select";
import { SingleDatepicker } from "chakra-dayzed-datepicker";
import selectStyle from "../../../theme/forms/selectStyles";
import { selectStyle } from "../../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../../theme/forms/datePickerStyles";
import {
Resident,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CloseIcon, SmallCloseIcon } from "@chakra-ui/icons";
import { Card } from "react-bootstrap";
import Select, { MultiValue, SingleValue } from "react-select";
import { SingleDatepicker } from "chakra-dayzed-datepicker";
import selectStyle from "../../../theme/forms/selectStyles";
import { selectStyle } from "../../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../../theme/forms/datePickerStyles";
import {
Resident,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/theme/forms/inputStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Input: ComponentStyleConfig = {
color: "teal.300",
height: "36px",
_placeholder: {
color: "gray.600",
color: "gray.500",
},
_hover: {
borderColor: "teal.400",
Expand Down Expand Up @@ -77,7 +77,7 @@ const Textarea: ComponentStyleConfig = {
color: "teal.300",
height: "36px",
_placeholder: {
color: "gray.600",
color: "gray.500",
},
_hover: {
borderColor: "teal.400",
Expand Down
Loading

0 comments on commit 53d0a8c

Please sign in to comment.