- Fix the suburl prefix via extending existing HttpAdorment

- Add the rest of content panel UI layouts
- Update the card value with onChange
This commit is contained in:
Shemy Gan committed 2024-12-10 16:07:42 -05:00
1 parent 1ab4bd7275
commit 9370db62cc
5 files changed
+55 -10

No files matched your search

@@ -6,7 +6,7 @@ import Visibility from "@mui/icons-material/Visibility";
import Docs from "../../../../assets/icons/docs.svg?react"; import Docs from "../../../../assets/icons/docs.svg?react";
import DeleteIcon from "../../../../assets/icons/trash-bin.svg?react"; import DeleteIcon from "../../../../assets/icons/trash-bin.svg?react";
export const HttpAdornment = ({ https }) => { export const HttpAdornment = ({ https, prefix }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
<Stack <Stack
@@ -25,7 +25,7 @@ export const HttpAdornment = ({ https }) => {
color={theme.palette.text.secondary} color={theme.palette.text.secondary}
sx={{ lineHeight: 1, opacity: 0.8 }} sx={{ lineHeight: 1, opacity: 0.8 }}
> >
{https ? "https" : "http"}:// {prefix !== undefined ? prefix : https ? "https://" : "http://"}
</Typography> </Typography>
</Stack> </Stack>
); );
@@ -33,6 +33,7 @@ export const HttpAdornment = ({ https }) => {
HttpAdornment.propTypes = { HttpAdornment.propTypes = {
https: PropTypes.bool.isRequired, https: PropTypes.bool.isRequired,
prefix: PropTypes.string,
}; };
export const PasswordEndAdornment = ({ fieldType, setFieldType }) => { export const PasswordEndAdornment = ({ fieldType, setFieldType }) => {
@@ -69,12 +70,11 @@ PasswordEndAdornment.propTypes = {
export const ServerStartAdornment = () => { export const ServerStartAdornment = () => {
return ( return (
<InputAdornment position="start"> <InputAdornment position="start">
<Docs/> <Docs />
</InputAdornment> </InputAdornment>
); );
}; };
export const ServerEndAdornment = ({ id, removeItem }) => { export const ServerEndAdornment = ({ id, removeItem }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@@ -95,7 +95,7 @@ export const ServerEndAdornment = ({ id, removeItem }) => {
}, },
}} }}
> >
<DeleteIcon/> <DeleteIcon />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
); );
@@ -2,7 +2,7 @@ import TextInput from "../../../../Inputs/TextInput";
import { ServerStartAdornment, ServerEndAdornment } from "../../../../Inputs/TextInput/Adornments"; import { ServerStartAdornment, ServerEndAdornment } from "../../../../Inputs/TextInput/Adornments";
const Server = ({ id, removeItem, value }) => { const Server = ({ id, removeItem, value, onChange }) => {
return ( return (
<TextInput <TextInput
type="text" type="text"
@@ -15,6 +15,7 @@ const Server = ({ id, removeItem, value }) => {
} }
id={id} id={id}
value= {value} value= {value}
onChange ={ onChange }
></TextInput> ></TextInput>
); );
}; };
@@ -14,13 +14,14 @@ const CustomCard = React.forwardRef((props, ref) => (
id={props.id} id={props.id}
removeItem={props.removeCard} removeItem={props.removeCard}
value={props.value} value={props.value}
onChange={props.onChange}
/> />
</CardContent> </CardContent>
</CardActionArea> </CardActionArea>
</Card> </Card>
)); ));
const MyCard = ({ id, index, moveCard, removeCard, value }) => { const MyCard = ({ id, index, moveCard, removeCard, value, onChange }) => {
const ref = useRef(null); const ref = useRef(null);
const [, drop] = useDrop({ const [, drop] = useDrop({
accept: ItemTypes.CARD, accept: ItemTypes.CARD,
@@ -81,6 +82,7 @@ const MyCard = ({ id, index, moveCard, removeCard, value }) => {
id={id} id={id}
removeCard={removeCard} removeCard={removeCard}
value={value} value={value}
onChange={onChange}
/> />
); );
}; };
@@ -8,6 +8,7 @@ import { buildErrors } from "../../../Validation/error";
import { hasValidationErrors } from "../../../Validation/error"; import { hasValidationErrors } from "../../../Validation/error";
import Card from "./Card"; import Card from "./Card";
import update from "immutability-helper"; import update from "immutability-helper";
import Checkbox from "../../Inputs/Checkbox";
const ContentPanel = () => { const ContentPanel = () => {
const theme = useTheme(); const theme = useTheme();
@@ -15,6 +16,9 @@ const ContentPanel = () => {
// Local state for form data, errors, and file handling // Local state for form data, errors, and file handling
const [localData, setLocalData] = useState({ const [localData, setLocalData] = useState({
monitors: [], monitors: [],
showUptimePercentage: false,
showBarcode: false
}); });
const [cards, setCards] = useState(localData.monitors); const [cards, setCards] = useState(localData.monitors);
@@ -52,6 +56,17 @@ const ContentPanel = () => {
})); }));
}; };
const handleCardChange = (event) => {
event.preventDefault();
const { value, id } = event.target;
let idx = cards.findIndex((a) => a.id == id);
if (idx >= 0) {
let x = JSON.parse(JSON.stringify(cards[idx]));
x.url = value;
setCards(update(cards, { $splice: [[idx, 1, x]] }));
} else setCards(update(cards, { $push: [{ id: id, url: value }] }));
}
const handleSubmit = () => { const handleSubmit = () => {
if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) { if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) {
return; return;
@@ -154,7 +169,8 @@ const ContentPanel = () => {
text={"" + idx} text={"" + idx}
moveCard={moveCard} moveCard={moveCard}
removeCard={removeCard} removeCard={removeCard}
value={card?.url ?? card?.id} value={card?.url}
onChange = {handleCardChange}
/> />
))} ))}
</Stack> </Stack>
@@ -162,6 +178,33 @@ const ContentPanel = () => {
</Box> </Box>
</Box> </Box>
</ConfigBox> </ConfigBox>
<ConfigBox>
<Box>
<Stack gap={theme.spacing(6)}>
<Typography component="h2">Features</Typography>
<Typography component="p">Show more details on the status page</Typography>
</Stack>
</Box>
<Stack
>
<Checkbox
id="show-barcode"
label={`Show Barcode`}
isChecked={localData.showBarcode}
value={"localData.showBarcode"}
onChange={handleChange}
onBlur={handleBlur}
/>
<Checkbox
id="show-uptime-percentage"
label={`Show Uptime Percentage`}
isChecked={localData.showUptimePercentage}
value={"localData.showUptimePercentage"}
onChange={handleChange}
onBlur={handleBlur}
/>
</Stack>
</ConfigBox>
<Stack <Stack
direction="row" direction="row"
@@ -194,8 +194,7 @@ const GeneralSettingsPanel = () => {
type="url" type="url"
label="SubURL" label="SubURL"
value={localData.url} value={localData.url}
startAdornment={<HttpAdornment https={true} />} startAdornment={<HttpAdornment prefix = {"http://uptimegenie.com/"} https={false} />}
//prefix={"http://uptimegenie.com/"}
onChange={handleChange} onChange={handleChange}
onBlur={handleBlur} onBlur={handleBlur}
helperText={errors["url"]} helperText={errors["url"]}