Files
Checkmate/client/src/Pages/StatusPage/Create/Components/Tabs/Settings.jsx
T

187 lines
4.6 KiB
React
Raw Normal View History

2025-02-02 21:26:48 -08:00
// Components
import { Stack, Typography } from "@mui/material";
import { TabPanel } from "@mui/lab";
import ConfigBox from "../../../../../Components/ConfigBox";
import Checkbox from "../../../../../Components/Inputs/Checkbox";
import TextInput from "../../../../../Components/Inputs/TextInput";
import Search from "../../../../../Components/Inputs/Search";
import ImageUpload from "../../../../../Components/Inputs/ImageUpload";
2025-02-02 21:26:48 -08:00
import ColorPicker from "../../../../../Components/Inputs/ColorPicker";
import Progress from "../Progress";
2025-02-04 14:07:08 -08:00
2025-02-02 21:26:48 -08:00
// Utils
import { useTheme } from "@emotion/react";
import timezones from "../../../../../Utils/timezones.json";
2025-02-04 14:07:08 -08:00
import PropTypes from "prop-types";
2025-03-17 01:16:42 +05:30
import { useTranslation } from "react-i18next";
import { useMemo, useState, useCallback } from "react";
2025-02-02 21:26:48 -08:00
const TabSettings = ({
2025-02-10 13:49:54 -08:00
isCreate,
2025-02-02 21:26:48 -08:00
tabValue,
form,
handleFormChange,
handleImageChange,
progress,
removeLogo,
errors,
}) => {
// Utils
const theme = useTheme();
2025-03-17 01:16:42 +05:30
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]
);
2025-02-02 21:26:48 -08:00
return (
<TabPanel value={tabValue}>
<Stack gap={theme.spacing(10)}>
<ConfigBox>
<Stack>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
{t("access")}
2025-02-02 21:26:48 -08:00
</Typography>
2025-05-27 09:10:32 -07:00
<Typography component="p">{t("statusPageCreateSettings")}</Typography>
2025-02-02 21:26:48 -08:00
</Stack>
<Stack gap={theme.spacing(18)}>
<Checkbox
id="publish"
name="isPublished"
2025-03-17 01:16:42 +05:30
label={t("statusPageCreateSettingsCheckboxLabel")}
2025-02-02 21:26:48 -08:00
isChecked={form.isPublished}
onChange={handleFormChange}
/>
</Stack>
</ConfigBox>
<ConfigBox>
<Stack gap={theme.spacing(6)}>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
{t("basicInformation")}
</Typography>
2025-02-02 21:26:48 -08:00
<Typography component="p">
2025-03-17 01:16:42 +05:30
{t("statusPageCreateBasicInfoDescription")}
2025-02-02 21:26:48 -08:00
</Typography>
</Stack>
<Stack gap={theme.spacing(18)}>
<TextInput
id="companyName"
name="companyName"
type="text"
2025-03-17 01:16:42 +05:30
label={t("companyName")}
2025-02-02 21:26:48 -08:00
value={form.companyName}
onChange={handleFormChange}
helperText={errors["companyName"]}
error={errors["companyName"] ? true : false}
/>
<TextInput
id="url"
name="url"
type="url"
2025-02-10 13:49:54 -08:00
disabled={!isCreate}
2025-03-17 01:16:42 +05:30
label={t("statusPageCreateBasicInfoStatusPageAddress")}
2025-02-02 21:26:48 -08:00
value={form.url}
onChange={handleFormChange}
helperText={errors["url"]}
error={errors["url"] ? true : false}
2025-02-02 21:26:48 -08:00
/>
</Stack>
</ConfigBox>
<ConfigBox>
<Stack gap={theme.spacing(6)}>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
{t("timezone")}
</Typography>
2025-02-02 21:26:48 -08:00
<Typography component="p">
2025-03-17 01:16:42 +05:30
{t("statusPageCreateSelectTimeZoneDescription")}
2025-02-02 21:26:48 -08:00
</Typography>
</Stack>
<Stack gap={theme.spacing(6)}>
<Search
2025-02-02 21:26:48 -08:00
id="timezone"
2025-03-17 01:16:42 +05:30
label={t("settingsDisplayTimezone")}
options={timezones}
filteredBy="name"
value={selectedTimezone}
inputValue={rawInput}
handleInputChange={(newVal) => setRawInput(newVal)}
handleChange={handleTimezoneChange}
isAdorned={false}
unit="timezone"
2025-02-02 21:26:48 -08:00
/>
</Stack>
</ConfigBox>
<ConfigBox>
<Stack gap={theme.spacing(6)}>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
2025-06-26 11:46:50 +08:00
{t("statusPageCreateAppearanceTitle")}
2025-05-27 09:10:32 -07:00
</Typography>
2025-02-02 21:26:48 -08:00
<Typography component="p">
2025-03-17 01:16:42 +05:30
{t("statusPageCreateAppearanceDescription")}
2025-02-02 21:26:48 -08:00
</Typography>
</Stack>
<Stack gap={theme.spacing(6)}>
<ImageUpload
2025-02-04 13:06:42 -08:00
src={form?.logo?.src}
2025-02-02 21:26:48 -08:00
onChange={handleImageChange}
previewIsRound={false}
2025-02-02 21:26:48 -08:00
/>
<Progress
isLoading={progress.isLoading}
progressValue={progress.value}
logo={form.logo}
logoType={form.logo?.type}
removeLogo={removeLogo}
/>
<ColorPicker
id="color"
name="color"
value={form.color}
onChange={handleFormChange}
/>
</Stack>
</ConfigBox>
</Stack>
</TabPanel>
);
};
2025-02-04 14:07:08 -08:00
TabSettings.propTypes = {
2025-02-10 13:50:11 -08:00
isCreate: PropTypes.bool,
2025-02-04 14:07:08 -08:00
tabValue: PropTypes.string,
form: PropTypes.object,
handleFormChange: PropTypes.func,
handleImageChange: PropTypes.func,
progress: PropTypes.object,
removeLogo: PropTypes.func,
errors: PropTypes.object,
};
2025-02-02 21:26:48 -08:00
export default TabSettings;