From 911532734b2cff04d418987388d85a4cf14a99c2 Mon Sep 17 00:00:00 2001 From: Jr7468 Date: Fri, 16 May 2025 21:53:58 +0100 Subject: [PATCH] feat: Enhance CippExchangeSettingsForm with dynamic permission handling and tooltip for private item visibility --- .../CippExchangeSettingsForm.jsx | 102 ++++++++++++------ 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/src/components/CippFormPages/CippExchangeSettingsForm.jsx b/src/components/CippFormPages/CippExchangeSettingsForm.jsx index db924f6476d1..1b293aefd7d1 100644 --- a/src/components/CippFormPages/CippExchangeSettingsForm.jsx +++ b/src/components/CippFormPages/CippExchangeSettingsForm.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Box, Button, @@ -9,6 +9,7 @@ import { Stack, SvgIcon, Typography, + Tooltip, } from "@mui/material"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import CippFormComponent from "/src/components/CippComponents/CippFormComponent"; @@ -18,6 +19,7 @@ import { ApiGetCall, ApiPostCall } from "../../api/ApiCall"; import { useSettings } from "../../hooks/use-settings"; import { Grid } from "@mui/system"; import { CippApiResults } from "../CippComponents/CippApiResults"; +import { useWatch, useFormContext } from "react-hook-form"; const CippExchangeSettingsForm = (props) => { const userSettingsDefaults = useSettings(); @@ -312,44 +314,80 @@ const CippExchangeSettingsForm = (props) => { multiple={false} formControl={formControl} /> - - - value ? true : "Select the permission level for the calendar", - }} - isFetching={isFetching || usersList.isFetching} - options={[ - { value: "Author", label: "Author" }, - { value: "Contributor", label: "Contributor" }, - { value: "Editor", label: "Editor" }, - { value: "Owner", label: "Owner" }, - { value: "NonEditingAuthor", label: "Non Editing Author" }, - { value: "PublishingAuthor", label: "Publishing Author" }, - { value: "PublishingEditor", label: "Publishing Editor" }, - { value: "Reviewer", label: "Reviewer" }, - { value: "LimitedDetails", label: "Limited Details" }, - { value: "AvailabilityOnly", label: "Availability Only" }, - ]} - multiple={false} - formControl={formControl} - /> + + + value ? true : "Select the permission level for the calendar", + }} + isFetching={isFetching || usersList.isFetching} + options={[ + { value: "Author", label: "Author" }, + { value: "Contributor", label: "Contributor" }, + { value: "Editor", label: "Editor" }, + { value: "Owner", label: "Owner" }, + { value: "NonEditingAuthor", label: "Non Editing Author" }, + { value: "PublishingAuthor", label: "Publishing Author" }, + { value: "PublishingEditor", label: "Publishing Editor" }, + { value: "Reviewer", label: "Reviewer" }, + { value: "LimitedDetails", label: "Limited Details" }, + { value: "AvailabilityOnly", label: "Availability Only" }, + ]} + multiple={false} + formControl={formControl} + /> + + {(() => { + const permissionLevel = useWatch({ + control: formControl.control, + name: "calendar.Permissions" + }); + const isEditor = permissionLevel?.value === "Editor"; + + // Use useEffect to handle the switch value reset + useEffect(() => { + if (!isEditor) { + formControl.setValue("calendar.CanViewPrivateItems", false); + } + }, [isEditor, formControl]); + + return ( + + + + + + ); + })()} + + +