Merge pull request #2600 from career-yashaswee/feat/2598-search-timezone-ux
Feat/2598 Search Timezone UX Addition
This commit is contained in:
4 files changed
+76
-15
No files matched your search
@@ -24,6 +24,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
* @param {Function} props.handleChange - Function to call when the input changes
|
* @param {Function} props.handleChange - Function to call when the input changes
|
||||||
* @param {Function} Prop.onBlur - Function to call when the input is blured
|
* @param {Function} Prop.onBlur - Function to call when the input is blured
|
||||||
* @param {Object} props.sx - Additional styles to apply to the component
|
* @param {Object} props.sx - Additional styles to apply to the component
|
||||||
|
* @param {string} props.unit - Label to identify type of options
|
||||||
* @returns {JSX.Element} The rendered Search component
|
* @returns {JSX.Element} The rendered Search component
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ const Search = ({
|
|||||||
startAdornment,
|
startAdornment,
|
||||||
endAdornment,
|
endAdornment,
|
||||||
onBlur,
|
onBlur,
|
||||||
|
unit = "option",
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -186,7 +188,12 @@ const Search = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (filtered.length === 0) {
|
if (filtered.length === 0) {
|
||||||
return [{ [filteredBy]: "No monitors found", noOptions: true }];
|
return [
|
||||||
|
{
|
||||||
|
[filteredBy]: t("general.noOptionsFound", { unit: unit }),
|
||||||
|
noOptions: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
return filtered;
|
return filtered;
|
||||||
}}
|
}}
|
||||||
@@ -281,7 +288,7 @@ Search.propTypes = {
|
|||||||
options: PropTypes.array.isRequired,
|
options: PropTypes.array.isRequired,
|
||||||
filteredBy: PropTypes.string.isRequired,
|
filteredBy: PropTypes.string.isRequired,
|
||||||
secondaryLabel: PropTypes.string,
|
secondaryLabel: PropTypes.string,
|
||||||
value: PropTypes.array,
|
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||||
inputValue: PropTypes.string.isRequired,
|
inputValue: PropTypes.string.isRequired,
|
||||||
handleInputChange: PropTypes.func.isRequired,
|
handleInputChange: PropTypes.func.isRequired,
|
||||||
handleChange: PropTypes.func,
|
handleChange: PropTypes.func,
|
||||||
@@ -292,6 +299,7 @@ Search.propTypes = {
|
|||||||
startAdornment: PropTypes.object,
|
startAdornment: PropTypes.object,
|
||||||
endAdornment: PropTypes.object,
|
endAdornment: PropTypes.object,
|
||||||
onBlur: PropTypes.func,
|
onBlur: PropTypes.func,
|
||||||
|
unit: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Search;
|
export default Search;
|
||||||
@@ -2,16 +2,37 @@ import Box from "@mui/material/Box";
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import ConfigBox from "../../Components/ConfigBox";
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import Search from "../../Components/Inputs/Search";
|
||||||
import timezones from "../../Utils/timezones.json";
|
import timezones from "../../Utils/timezones.json";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { PropTypes } from "prop-types";
|
import { PropTypes } from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useCallback, useMemo, useState } from "react";
|
||||||
const SettingsTimeZone = ({ HEADING_SX, handleChange, timezone }) => {
|
const SettingsTimeZone = ({ HEADING_SX, handleChange, timezone }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [rawInput, setRawInput] = useState("");
|
||||||
|
|
||||||
|
const selectedTimezone = useMemo(
|
||||||
|
() => timezones.find((tz) => tz._id === timezone) ?? null,
|
||||||
|
[timezone]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTimezoneChange = useCallback(
|
||||||
|
(newValue) => {
|
||||||
|
setRawInput("");
|
||||||
|
handleChange({
|
||||||
|
target: {
|
||||||
|
name: "timezone",
|
||||||
|
value: newValue?._id ?? "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[handleChange]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -28,12 +49,17 @@ const SettingsTimeZone = ({ HEADING_SX, handleChange, timezone }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Stack gap={theme.spacing(20)}>
|
||||||
<Select
|
<Search
|
||||||
label={t("settingsPage.timezoneSettings.label")}
|
id="timezone"
|
||||||
name="timezone"
|
label={t("settingsDisplayTimezone")}
|
||||||
value={timezone}
|
options={timezones}
|
||||||
onChange={handleChange}
|
filteredBy="name"
|
||||||
items={timezones}
|
value={selectedTimezone}
|
||||||
|
inputValue={rawInput}
|
||||||
|
handleInputChange={(val) => setRawInput(val)}
|
||||||
|
handleChange={handleTimezoneChange}
|
||||||
|
isAdorned={false}
|
||||||
|
unit="timezone"
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { TabPanel } from "@mui/lab";
|
|||||||
import ConfigBox from "../../../../../Components/ConfigBox";
|
import ConfigBox from "../../../../../Components/ConfigBox";
|
||||||
import Checkbox from "../../../../../Components/Inputs/Checkbox";
|
import Checkbox from "../../../../../Components/Inputs/Checkbox";
|
||||||
import TextInput from "../../../../../Components/Inputs/TextInput";
|
import TextInput from "../../../../../Components/Inputs/TextInput";
|
||||||
import Select from "../../../../../Components/Inputs/Select";
|
import Search from "../../../../../Components/Inputs/Search";
|
||||||
import ImageUpload from "../../../../../Components/Inputs/ImageUpload";
|
import ImageUpload from "../../../../../Components/Inputs/ImageUpload";
|
||||||
import ColorPicker from "../../../../../Components/Inputs/ColorPicker";
|
import ColorPicker from "../../../../../Components/Inputs/ColorPicker";
|
||||||
import Progress from "../Progress";
|
import Progress from "../Progress";
|
||||||
@@ -14,6 +14,7 @@ import { useTheme } from "@emotion/react";
|
|||||||
import timezones from "../../../../../Utils/timezones.json";
|
import timezones from "../../../../../Utils/timezones.json";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useMemo, useState, useCallback } from "react";
|
||||||
|
|
||||||
const TabSettings = ({
|
const TabSettings = ({
|
||||||
isCreate,
|
isCreate,
|
||||||
@@ -28,6 +29,25 @@ const TabSettings = ({
|
|||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [rawInput, setRawInput] = useState("");
|
||||||
|
|
||||||
|
const selectedTimezone = useMemo(
|
||||||
|
() => timezones.find((tz) => tz._id === form.timezone) ?? null,
|
||||||
|
[form.timezone]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTimezoneChange = useCallback(
|
||||||
|
(newValue) => {
|
||||||
|
setRawInput("");
|
||||||
|
handleFormChange({
|
||||||
|
target: {
|
||||||
|
name: "timezone",
|
||||||
|
value: newValue?._id ?? "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[handleFormChange]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabPanel value={tabValue}>
|
<TabPanel value={tabValue}>
|
||||||
@@ -101,13 +121,17 @@ const TabSettings = ({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack gap={theme.spacing(6)}>
|
<Stack gap={theme.spacing(6)}>
|
||||||
<Select
|
<Search
|
||||||
id="timezone"
|
id="timezone"
|
||||||
name="timezone"
|
|
||||||
label={t("settingsDisplayTimezone")}
|
label={t("settingsDisplayTimezone")}
|
||||||
items={timezones}
|
options={timezones}
|
||||||
value={form.timezone}
|
filteredBy="name"
|
||||||
onChange={handleFormChange}
|
value={selectedTimezone}
|
||||||
|
inputValue={rawInput}
|
||||||
|
handleInputChange={(newVal) => setRawInput(newVal)}
|
||||||
|
handleChange={handleTimezoneChange}
|
||||||
|
isAdorned={false}
|
||||||
|
unit="timezone"
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
|||||||
@@ -229,6 +229,9 @@
|
|||||||
"unknownError": "Unknown error"
|
"unknownError": "Unknown error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"general": {
|
||||||
|
"noOptionsFound": "No {{unit}} found"
|
||||||
|
},
|
||||||
"commonSave": "Save",
|
"commonSave": "Save",
|
||||||
"commonSaving": "Saving...",
|
"commonSaving": "Saving...",
|
||||||
"companyName": "Company name",
|
"companyName": "Company name",
|
||||||
|
|||||||
Reference in new issue
Block a user