2024-05-20 18:15:36 +00:00
|
|
|
|
import * as React from "react";
|
2024-06-15 05:00:58 +00:00
|
|
|
|
import { FC, useCallback, useMemo, useRef, useState } from "react";
|
2024-06-21 09:02:45 +00:00
|
|
|
|
import { Avatar, MenuItem, Select, SelectChangeEvent, Typography, useMediaQuery, useTheme, Box } from "@mui/material";
|
2024-04-08 14:05:38 +00:00
|
|
|
|
import arrow_down from "../../assets/icons/arrow_down.svg";
|
2024-07-22 23:55:58 +00:00
|
|
|
|
import { MinifiedData } from "@/pages/IntegrationsPage/IntegrationsModal/Amo/types";
|
2024-04-08 14:05:38 +00:00
|
|
|
|
|
|
|
|
|
|
type CustomSelectProps = {
|
2024-06-16 10:48:49 +00:00
|
|
|
|
items: MinifiedData[] | [];
|
2024-06-15 05:00:58 +00:00
|
|
|
|
selectedItemId: string | null;
|
2024-04-09 13:07:42 +00:00
|
|
|
|
setSelectedItem: (value: string | null) => void;
|
2024-06-15 05:00:58 +00:00
|
|
|
|
handleScroll: () => void;
|
2024-04-08 14:05:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-21 09:02:45 +00:00
|
|
|
|
export const CustomSelect: FC<CustomSelectProps> = ({ items, selectedItemId, setSelectedItem, handleScroll }) => {
|
2024-04-08 14:05:38 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
|
|
|
|
|
|
2024-06-15 05:00:58 +00:00
|
|
|
|
const ref = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
|
const [opened, setOpened] = useState<boolean>(false);
|
2024-04-08 14:05:38 +00:00
|
|
|
|
|
|
|
|
|
|
const toggleOpened = useCallback(() => {
|
|
|
|
|
|
setOpened((isOpened) => !isOpened);
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
2024-06-15 05:00:58 +00:00
|
|
|
|
const onScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
2024-05-20 18:15:36 +00:00
|
|
|
|
const scrollHeight = e.currentTarget.scrollHeight;
|
|
|
|
|
|
const scrollTop = e.currentTarget.scrollTop;
|
|
|
|
|
|
const clientHeight = e.currentTarget.clientHeight;
|
|
|
|
|
|
const scrolledToBottom = scrollTop / (scrollHeight - clientHeight) > 0.9;
|
|
|
|
|
|
|
2024-06-15 05:00:58 +00:00
|
|
|
|
if (scrolledToBottom) {
|
|
|
|
|
|
handleScroll();
|
2024-05-20 18:15:36 +00:00
|
|
|
|
}
|
2024-06-15 05:00:58 +00:00
|
|
|
|
}, []);
|
2024-05-20 18:15:36 +00:00
|
|
|
|
|
2024-06-21 09:02:45 +00:00
|
|
|
|
const currentItem = useMemo(() => items.find((item) => item.id === selectedItemId) || null, [selectedItemId, items]);
|
2024-05-20 18:15:36 +00:00
|
|
|
|
|
|
|
|
|
|
const menuItems = useMemo(() => {
|
2024-06-15 05:00:58 +00:00
|
|
|
|
if (items.length !== 0) {
|
|
|
|
|
|
return items.map((item) => (
|
2024-05-20 18:15:36 +00:00
|
|
|
|
<MenuItem
|
2024-06-15 05:00:58 +00:00
|
|
|
|
key={item.id}
|
|
|
|
|
|
value={item.id}
|
2024-05-21 21:29:33 +00:00
|
|
|
|
sx={{
|
|
|
|
|
|
padding: "6px 0",
|
|
|
|
|
|
zIndex: 2,
|
|
|
|
|
|
borderTop: "1px solid rgba(154, 154, 175, 0.1)",
|
|
|
|
|
|
width: "auto",
|
|
|
|
|
|
}}
|
2024-05-20 18:15:36 +00:00
|
|
|
|
>
|
2024-05-21 21:29:33 +00:00
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
|
color: "#4D4D4D",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
flexDirection: isMobile ? "column" : "row",
|
|
|
|
|
|
justifyContent: "space-evenly",
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "33%",
|
2024-06-21 09:02:45 +00:00
|
|
|
|
borderRight: isMobile ? "none" : "1px solid rgba(154, 154, 175, 0.1)",
|
2024-05-21 21:29:33 +00:00
|
|
|
|
padding: isMobile ? "5px 0 5px 20px" : "10px 0 10px 20px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-06-15 05:00:58 +00:00
|
|
|
|
{item.title}
|
2024-05-21 21:29:33 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "33%",
|
2024-06-21 09:02:45 +00:00
|
|
|
|
borderRight: isMobile ? "none" : "1px solid rgba(154, 154, 175, 0.1)",
|
2024-05-21 21:29:33 +00:00
|
|
|
|
padding: isMobile ? "5px 0 5px 20px" : "10px 0 10px 20px",
|
|
|
|
|
|
color: isMobile ? "#9A9AAF" : "#4D4D4D",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-06-15 05:00:58 +00:00
|
|
|
|
{item.subTitle}
|
2024-05-21 21:29:33 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
|
</Box>
|
2024-05-20 18:15:36 +00:00
|
|
|
|
</MenuItem>
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
return (
|
2024-06-21 09:02:45 +00:00
|
|
|
|
<MenuItem
|
|
|
|
|
|
key={"-1"}
|
|
|
|
|
|
disabled
|
|
|
|
|
|
sx={{ padding: "12px", zIndex: 2 }}
|
|
|
|
|
|
>
|
2024-05-20 18:15:36 +00:00
|
|
|
|
нет данных
|
|
|
|
|
|
</MenuItem>
|
|
|
|
|
|
);
|
2024-06-16 10:48:49 +00:00
|
|
|
|
}, [items, selectedItemId]);
|
2024-05-20 18:15:36 +00:00
|
|
|
|
|
2024-04-08 14:05:38 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
2024-04-09 13:07:42 +00:00
|
|
|
|
zIndex: 3,
|
2024-04-08 14:05:38 +00:00
|
|
|
|
position: "relative",
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
height: "56px",
|
|
|
|
|
|
padding: "5px",
|
2024-06-21 09:02:45 +00:00
|
|
|
|
color: currentItem === null ? theme.palette.grey2.main : theme.palette.brightPurple.main,
|
2024-04-12 09:05:33 +00:00
|
|
|
|
border: `2px solid ${theme.palette.common.white}`,
|
2024-04-08 14:05:38 +00:00
|
|
|
|
borderRadius: "30px",
|
|
|
|
|
|
background: "#EFF0F5",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
|
}}
|
2024-06-21 09:02:45 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
if (ref.current !== null) ref.current?.click();
|
|
|
|
|
|
}}
|
2024-04-08 14:05:38 +00:00
|
|
|
|
>
|
|
|
|
|
|
<Avatar sx={{ width: 46, height: 46, marginRight: 1 }} />
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
marginLeft: isMobile ? "10px" : "20px",
|
2024-06-15 05:00:58 +00:00
|
|
|
|
fontWeight: currentItem === null ? "400" : "500",
|
2024-04-08 14:05:38 +00:00
|
|
|
|
fontSize: isMobile ? "14px" : "16px",
|
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-06-15 05:00:58 +00:00
|
|
|
|
{currentItem?.title || "Выберите ответственного за сделку"}
|
2024-04-08 14:05:38 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
|
<img
|
|
|
|
|
|
src={arrow_down}
|
|
|
|
|
|
alt="check"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
position: "absolute",
|
|
|
|
|
|
top: "50%",
|
|
|
|
|
|
right: "10px",
|
|
|
|
|
|
transform: `translateY(-50%) rotate(${opened ? "180deg" : "0deg"}`,
|
|
|
|
|
|
height: "36px",
|
|
|
|
|
|
width: "36px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
className={`select-icon ${opened ? "opened" : ""}`}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
ref={ref}
|
|
|
|
|
|
className="select"
|
2024-06-16 10:48:49 +00:00
|
|
|
|
value={selectedItemId || ""}
|
2024-04-08 14:05:38 +00:00
|
|
|
|
open={opened}
|
|
|
|
|
|
MenuProps={{
|
|
|
|
|
|
disablePortal: true,
|
|
|
|
|
|
PaperProps: {
|
2024-06-15 05:00:58 +00:00
|
|
|
|
onScroll: onScroll,
|
2024-04-08 14:05:38 +00:00
|
|
|
|
style: {
|
2024-04-09 13:07:42 +00:00
|
|
|
|
zIndex: 2,
|
2024-04-08 14:05:38 +00:00
|
|
|
|
maxHeight: "300px",
|
|
|
|
|
|
overflow: "auto",
|
2024-05-21 21:29:33 +00:00
|
|
|
|
overflowX: "auto",
|
2024-06-20 23:27:53 +00:00
|
|
|
|
paddingTop: "50px",
|
|
|
|
|
|
marginTop: "-50px",
|
|
|
|
|
|
borderRadius: "28px",
|
2024-04-08 14:05:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
2024-06-20 23:27:53 +00:00
|
|
|
|
sx={{
|
2024-06-21 09:02:45 +00:00
|
|
|
|
display: "block",
|
|
|
|
|
|
"& .MuiSelect-select.MuiSelect-outlined.MuiInputBase-input": {
|
|
|
|
|
|
display: "none",
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .MuiSelect-icon": {
|
|
|
|
|
|
display: "none",
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .MuiOutlinedInput-notchedOutline": {
|
|
|
|
|
|
border: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .MuiMenu-root.MuiModal-root": {
|
|
|
|
|
|
zIndex: 0,
|
|
|
|
|
|
},
|
2024-06-20 23:27:53 +00:00
|
|
|
|
}}
|
2024-06-15 05:00:58 +00:00
|
|
|
|
onChange={({ target }: SelectChangeEvent<string>) => setSelectedItem(target.value)}
|
2024-04-08 14:05:38 +00:00
|
|
|
|
onClick={toggleOpened}
|
|
|
|
|
|
>
|
2024-05-20 18:15:36 +00:00
|
|
|
|
{menuItems}
|
2024-04-08 14:05:38 +00:00
|
|
|
|
</Select>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|