mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-27 13:47:50 +02:00
Refactored Viewer role Notifications settings (#19640)
- now each individual element is shown if allowed by role, instead of having multiple return statement for each role
This commit is contained in:
parent
95cea06dd3
commit
8f4b5b4bdb
@ -73,7 +73,11 @@ export default function Settings() {
|
|||||||
|
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
const allowedViewsForViewer: SettingsType[] = ["ui", "debug"];
|
const allowedViewsForViewer: SettingsType[] = [
|
||||||
|
"ui",
|
||||||
|
"debug",
|
||||||
|
"notifications",
|
||||||
|
];
|
||||||
const visibleSettingsViews = !isAdmin
|
const visibleSettingsViews = !isAdmin
|
||||||
? allowedViewsForViewer
|
? allowedViewsForViewer
|
||||||
: allSettingsViews;
|
: allSettingsViews;
|
||||||
@ -164,7 +168,7 @@ export default function Settings() {
|
|||||||
useSearchEffect("page", (page: string) => {
|
useSearchEffect("page", (page: string) => {
|
||||||
if (allSettingsViews.includes(page as SettingsType)) {
|
if (allSettingsViews.includes(page as SettingsType)) {
|
||||||
// Restrict viewer to UI settings
|
// Restrict viewer to UI settings
|
||||||
if (!isAdmin && !["ui", "debug"].includes(page)) {
|
if (!isAdmin && !allowedViewsForViewer.includes(page as SettingsType)) {
|
||||||
setPage("ui");
|
setPage("ui");
|
||||||
} else {
|
} else {
|
||||||
setPage(page as SettingsType);
|
setPage(page as SettingsType);
|
||||||
@ -200,7 +204,7 @@ export default function Settings() {
|
|||||||
onValueChange={(value: SettingsType) => {
|
onValueChange={(value: SettingsType) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
// Restrict viewer navigation
|
// Restrict viewer navigation
|
||||||
if (!isAdmin && !["ui", "debug"].includes(value)) {
|
if (!isAdmin && !allowedViewsForViewer.includes(value)) {
|
||||||
setPageToggle("ui");
|
setPageToggle("ui");
|
||||||
} else {
|
} else {
|
||||||
setPageToggle(value);
|
setPageToggle(value);
|
||||||
|
@ -46,6 +46,8 @@ import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { useDateLocale } from "@/hooks/use-date-locale";
|
import { useDateLocale } from "@/hooks/use-date-locale";
|
||||||
import { useDocDomain } from "@/hooks/use-doc-domain";
|
import { useDocDomain } from "@/hooks/use-doc-domain";
|
||||||
|
import { useIsAdmin } from "@/hooks/use-is-admin";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const NOTIFICATION_SERVICE_WORKER = "notifications-worker.js";
|
const NOTIFICATION_SERVICE_WORKER = "notifications-worker.js";
|
||||||
|
|
||||||
@ -64,6 +66,10 @@ export default function NotificationView({
|
|||||||
const { t } = useTranslation(["views/settings"]);
|
const { t } = useTranslation(["views/settings"]);
|
||||||
const { getLocaleDocUrl } = useDocDomain();
|
const { getLocaleDocUrl } = useDocDomain();
|
||||||
|
|
||||||
|
// roles
|
||||||
|
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
const { data: config, mutate: updateConfig } = useSWR<FrigateConfig>(
|
const { data: config, mutate: updateConfig } = useSWR<FrigateConfig>(
|
||||||
"config",
|
"config",
|
||||||
{
|
{
|
||||||
@ -380,7 +386,11 @@ export default function NotificationView({
|
|||||||
<div className="flex size-full flex-col md:flex-row">
|
<div className="flex size-full flex-col md:flex-row">
|
||||||
<Toaster position="top-center" closeButton={true} />
|
<Toaster position="top-center" closeButton={true} />
|
||||||
<div className="scrollbar-container order-last mb-10 mt-2 flex h-full w-full flex-col overflow-y-auto rounded-lg border-[1px] border-secondary-foreground bg-background_alt p-2 md:order-none md:mb-0 md:mr-2 md:mt-0">
|
<div className="scrollbar-container order-last mb-10 mt-2 flex h-full w-full flex-col overflow-y-auto rounded-lg border-[1px] border-secondary-foreground bg-background_alt p-2 md:order-none md:mb-0 md:mr-2 md:mt-0">
|
||||||
<div className="grid w-full grid-cols-1 gap-4 md:grid-cols-2">
|
<div
|
||||||
|
className={cn(
|
||||||
|
isAdmin && "grid w-full grid-cols-1 gap-4 md:grid-cols-2",
|
||||||
|
)}
|
||||||
|
>
|
||||||
<div className="col-span-1">
|
<div className="col-span-1">
|
||||||
<Heading as="h3" className="my-2">
|
<Heading as="h3" className="my-2">
|
||||||
{t("notification.notificationSettings.title")}
|
{t("notification.notificationSettings.title")}
|
||||||
@ -403,6 +413,7 @@ export default function NotificationView({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{isAdmin && (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
onSubmit={form.handleSubmit(onSubmit)}
|
||||||
@ -465,7 +476,9 @@ export default function NotificationView({
|
|||||||
<FilterSwitch
|
<FilterSwitch
|
||||||
key={camera.name}
|
key={camera.name}
|
||||||
label={camera.name.replaceAll("_", " ")}
|
label={camera.name.replaceAll("_", " ")}
|
||||||
isChecked={field.value?.includes(camera.name)}
|
isChecked={field.value?.includes(
|
||||||
|
camera.name,
|
||||||
|
)}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
setChangedValue(true);
|
setChangedValue(true);
|
||||||
let newCameras;
|
let newCameras;
|
||||||
@ -528,13 +541,23 @@ export default function NotificationView({
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-span-1">
|
<div className="col-span-1">
|
||||||
<div className="mt-4 gap-2 space-y-6">
|
<div className="mt-4 gap-2 space-y-6">
|
||||||
<div className="flex flex-col gap-2 md:max-w-[50%]">
|
<div
|
||||||
<Separator className="my-2 flex bg-secondary md:hidden" />
|
className={cn(
|
||||||
<Heading as="h4" className="my-2">
|
isAdmin && "flex flex-col gap-2 md:max-w-[50%]",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Separator
|
||||||
|
className={cn(
|
||||||
|
"my-2 flex bg-secondary",
|
||||||
|
isAdmin && "md:hidden",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Heading as="h4" className={cn(isAdmin ? "my-2" : "my-4")}>
|
||||||
{t("notification.deviceSpecific")}
|
{t("notification.deviceSpecific")}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Button
|
<Button
|
||||||
@ -580,7 +603,7 @@ export default function NotificationView({
|
|||||||
? t("notification.unregisterDevice")
|
? t("notification.unregisterDevice")
|
||||||
: t("notification.registerDevice")}
|
: t("notification.registerDevice")}
|
||||||
</Button>
|
</Button>
|
||||||
{registration != null && registration.active && (
|
{isAdmin && registration != null && registration.active && (
|
||||||
<Button
|
<Button
|
||||||
aria-label={t("notification.sendTestNotification")}
|
aria-label={t("notification.sendTestNotification")}
|
||||||
onClick={() => sendTestNotification("notification_test")}
|
onClick={() => sendTestNotification("notification_test")}
|
||||||
@ -590,7 +613,7 @@ export default function NotificationView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{notificationCameras.length > 0 && (
|
{isAdmin && notificationCameras.length > 0 && (
|
||||||
<div className="mt-4 gap-2 space-y-6">
|
<div className="mt-4 gap-2 space-y-6">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<Separator className="my-2 flex bg-secondary" />
|
<Separator className="my-2 flex bg-secondary" />
|
||||||
|
Loading…
Reference in New Issue
Block a user