From 1a87e5c3d453a899f5abac4b11004d99fa5ac443 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Tue, 3 Jan 2023 21:21:45 -0500 Subject: [PATCH] Save reservation --- .../components/SubscriptionSettingsDialog.js | 79 +++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/web/src/components/SubscriptionSettingsDialog.js b/web/src/components/SubscriptionSettingsDialog.js index 20f6f1e..f6f5125 100644 --- a/web/src/components/SubscriptionSettingsDialog.js +++ b/web/src/components/SubscriptionSettingsDialog.js @@ -6,30 +6,48 @@ import Dialog from '@mui/material/Dialog'; import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import DialogTitle from '@mui/material/DialogTitle'; -import {Autocomplete, Checkbox, FormControlLabel, useMediaQuery} from "@mui/material"; +import {Checkbox, FormControl, FormControlLabel, Select, useMediaQuery} from "@mui/material"; import theme from "./theme"; -import api from "../app/Api"; -import {topicUrl, validTopic, validUrl} from "../app/utils"; -import userManager from "../app/UserManager"; import subscriptionManager from "../app/SubscriptionManager"; -import poller from "../app/Poller"; import DialogFooter from "./DialogFooter"; import {useTranslation} from "react-i18next"; import accountApi, {UnauthorizedError} from "../app/AccountApi"; import session from "../app/Session"; import routes from "./routes"; +import MenuItem from "@mui/material/MenuItem"; +import ListItemIcon from "@mui/material/ListItemIcon"; +import LockIcon from "@mui/icons-material/Lock"; +import ListItemText from "@mui/material/ListItemText"; +import {Public, PublicOff} from "@mui/icons-material"; const SubscriptionSettingsDialog = (props) => { const { t } = useTranslation(); const subscription = props.subscription; + const [reserveTopicVisible, setReserveTopicVisible] = useState(!!subscription.reservation); + const [everyone, setEveryone] = useState(subscription.reservation?.everyone || "deny-all"); const [displayName, setDisplayName] = useState(subscription.displayName ?? ""); const fullScreen = useMediaQuery(theme.breakpoints.down('sm')); + const handleSave = async () => { + // Apply locally await subscriptionManager.setDisplayName(subscription.id, displayName); + + // Apply remotely if (session.exists() && subscription.remoteId) { try { + // Display name console.log(`[SubscriptionSettingsDialog] Updating subscription display name to ${displayName}`); await accountApi.updateSubscription(subscription.remoteId, { display_name: displayName }); + + // Reservation + if (reserveTopicVisible) { + await accountApi.upsertAccess(subscription.topic, everyone); + } else if (!reserveTopicVisible && subscription.reservation) { // Was removed + await accountApi.deleteAccess(subscription.topic); + } + + // Sync account + await accountApi.sync(); } catch (e) { console.log(`[SubscriptionSettingsDialog] Error updating subscription`, e); if ((e instanceof UnauthorizedError)) { @@ -39,6 +57,7 @@ const SubscriptionSettingsDialog = (props) => { } props.onClose(); } + return ( {t("subscription_settings_dialog_title")} @@ -61,6 +80,56 @@ const SubscriptionSettingsDialog = (props) => { "aria-label": t("subscription_settings_dialog_display_name_placeholder") }} /> + + setReserveTopicVisible(ev.target.checked)} + inputProps={{ + "aria-label": t("xxxxxxxxxxxxxxxxxx") + }} + /> + } + label={t("Reserve topic and configure custom access:")} + /> + {reserveTopicVisible && + + + + }