Merge pull request #37 from CPSC319-Winter-term-2/mbalsdon-callfavs-improvement
Add search and per-group-selection to Call Favorites (now "Call Group")
This commit is contained in:
commit
f330be87b6
@ -7,8 +7,14 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
|
TextField,
|
||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { useAppSelector } from "../../redux/hooks";
|
||||||
|
import { selectFavorites } from "../../redux/slices/favoritesSlice";
|
||||||
|
import { selectTeam, selectUsers } from "../../redux/slices/usersSlice";
|
||||||
|
import GroupSelect from "../sidebar/GroupSelect";
|
||||||
import { SidebarUserObj } from "./Home";
|
import { SidebarUserObj } from "./Home";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -28,22 +34,72 @@ const CallFavouritesDialog: React.FC<Props> = ({
|
|||||||
onClose(selectedValue);
|
onClose(selectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [group, setGroup] = useState<string>("Favorites");
|
||||||
|
const [inputText, setInputText] = useState<string>("");
|
||||||
|
const [checkedUuids, setCheckedUuids] = useState<string[]>([]);
|
||||||
|
|
||||||
|
const handleCheck = (uuid: string, checked: boolean) => {
|
||||||
|
if (checked) {
|
||||||
|
setCheckedUuids(checkedUuids.concat([uuid]));
|
||||||
|
} else {
|
||||||
|
setCheckedUuids(checkedUuids.filter((id) => id != uuid));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGroupChange = () => {
|
||||||
|
setCheckedUuids([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const favoritesUuids = useAppSelector(selectFavorites);
|
||||||
|
const teamUuids = useAppSelector(selectTeam);
|
||||||
|
|
||||||
|
const groupMembersUuids: string[] =
|
||||||
|
group === "Favorites" ? favoritesUuids : teamUuids;
|
||||||
|
const groupMembers = useAppSelector((state) =>
|
||||||
|
selectUsers(state, groupMembersUuids)
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={handleClose} open={open} fullWidth maxWidth="sm">
|
<Dialog onClose={handleClose} open={open} fullWidth maxWidth="sm">
|
||||||
<DialogTitle>Select who to call:</DialogTitle>
|
<DialogTitle>Select who to call:</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<FormControlLabel
|
<GroupSelect
|
||||||
control={<Checkbox color="success" />}
|
group={group}
|
||||||
label="Select everyone"
|
setGroup={setGroup}
|
||||||
|
onGroupChange={handleGroupChange}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogContent sx={{ height: "40vh" }} dividers>
|
<DialogContent sx={{ height: "40vh" }} dividers>
|
||||||
|
<TextField
|
||||||
|
label="Search"
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="Person"
|
||||||
|
fullWidth
|
||||||
|
sx={{ pb: 1 }}
|
||||||
|
onChange={(e) => {
|
||||||
|
setInputText(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
{users.map((user) => (
|
{groupMembers
|
||||||
|
.filter((member) =>
|
||||||
|
member.name.toLowerCase().includes(inputText.toLowerCase())
|
||||||
|
)
|
||||||
|
.map((member) => (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
key={user.id}
|
key={member.uuid}
|
||||||
control={<Checkbox color="success" />}
|
label={member.name}
|
||||||
label={user.name}
|
sx={{ pl: 1 }}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
onChange={(e: any) => {
|
||||||
|
handleCheck(member.uuid, e.target.checked);
|
||||||
|
}}
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
color="success"
|
||||||
|
checked={checkedUuids.includes(member.uuid)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|||||||
@ -58,7 +58,7 @@ const ShortCuts: React.FC<Props> = ({ users }: Props) => {
|
|||||||
users={users}
|
users={users}
|
||||||
/>
|
/>
|
||||||
<Typography className="mylabel" sx={{ ml: 1 }}>
|
<Typography className="mylabel" sx={{ ml: 1 }}>
|
||||||
Call Favourites
|
Call Group
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={6}>
|
<Grid item sm={6}>
|
||||||
|
|||||||
@ -13,13 +13,17 @@ import React from "react";
|
|||||||
interface Props {
|
interface Props {
|
||||||
group: string;
|
group: string;
|
||||||
setGroup: (group: string) => void;
|
setGroup: (group: string) => void;
|
||||||
|
onGroupChange: (() => void) | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const groups = ["Favorites", "Team"];
|
const groups = ["Favorites", "Team"];
|
||||||
|
|
||||||
const GroupSelect: React.FC<Props> = ({ group, setGroup }) => {
|
const GroupSelect: React.FC<Props> = ({ group, setGroup, onGroupChange }) => {
|
||||||
const handleChange = (e: SelectChangeEvent) => {
|
const handleChange = (e: SelectChangeEvent) => {
|
||||||
setGroup(e.target.value);
|
setGroup(e.target.value);
|
||||||
|
if (onGroupChange) {
|
||||||
|
onGroupChange();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const Sidebar: React.FC = () => {
|
|||||||
<Toolbar />
|
<Toolbar />
|
||||||
<List disablePadding sx={{ height: "80%", overflow: "auto" }}>
|
<List disablePadding sx={{ height: "80%", overflow: "auto" }}>
|
||||||
<ListSubheader disableGutters>
|
<ListSubheader disableGutters>
|
||||||
<GroupSelect group={group} setGroup={setGroup} />
|
<GroupSelect group={group} setGroup={setGroup} onGroupChange={null} />
|
||||||
</ListSubheader>
|
</ListSubheader>
|
||||||
{groupMembers.map((user, i) => (
|
{groupMembers.map((user, i) => (
|
||||||
<ListItem disablePadding key={user.uuid}>
|
<ListItem disablePadding key={user.uuid}>
|
||||||
|
|||||||
Reference in New Issue
Block a user