From aa0bdb7a578d14e874998732f4867217d69cd46b Mon Sep 17 00:00:00 2001 From: "kartik.sharma" Date: Tue, 13 May 2025 18:48:40 +0530 Subject: [PATCH 1/6] Implemented Pushover to display permission descriptions when editing or creating application role --- src/components/master/CreateRole.jsx | 304 +++++++++++++++------------ src/components/master/EditRole.jsx | 215 +++++++++++-------- 2 files changed, 303 insertions(+), 216 deletions(-) diff --git a/src/components/master/CreateRole.jsx b/src/components/master/CreateRole.jsx index ae9ce302..0648cac1 100644 --- a/src/components/master/CreateRole.jsx +++ b/src/components/master/CreateRole.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useRef } from "react"; import { useFeatures } from "../../hooks/useMasterRole"; import { useForm } from 'react-hook-form'; @@ -16,7 +16,7 @@ import showToast from "../../services/toastService"; const schema = z.object({ role: z.string().min(1, { message: "Role is required" }), description: z.string().min(1, { message: "Description is required" }) - .max(255, { message: "Description cannot exceed 255 characters" }), + .max(255, { message: "Description cannot exceed 255 characters" }), selectedPermissions: z .array(z.string()) @@ -24,78 +24,91 @@ const schema = z.object({ }); -const CreateRole = ({modalType,onClose}) => { - - const[isLoading,setIsLoading] = useState(false) - const {masterFeatures} = useFeatures() - const { - register, - handleSubmit, - formState: { errors }, - -} = useForm({ - resolver: zodResolver(schema), - defaultValues: { - role: "", - description: "", - selectedPermissions: [], - }, -}); +const CreateRole = ({ modalType, onClose }) => { + + const [isLoading, setIsLoading] = useState(false) + + const popoverRefs = useRef([]); + const { masterFeatures } = useFeatures() + + const { + register, + handleSubmit, + formState: { errors }, + + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + role: "", + description: "", + selectedPermissions: [], + }, + }); + + const onSubmit = (values) => { + setIsLoading(true) + const result = { + + role: values.role, + description: values.description, + featuresPermission: values.selectedPermissions.map((id) => ({ + id, + isEnabled: true, + })), + }; + + MasterRespository.createRole(result).then((resp) => { + setIsLoading(false) + const cachedData = getCachedData("Application Role"); + const updatedData = [...cachedData, resp.data]; + cacheData("Application Role", updatedData); + showToast("Application Role Added successfully.", "success"); + onClose() + }).catch((err) => { + + showToast(err?.response?.data?.message, "error"); + setIsLoading(false) + onClose() + }) + -const onSubmit = (values) => { - setIsLoading(true) - const result = { - - role: values.role, - description: values.description, - featuresPermission: values.selectedPermissions.map((id) => ({ - id, - isEnabled: true, - })), }; + const [descriptionLength, setDescriptionLength] = useState(0); + const maxDescriptionLength = 255; + useEffect(() => { + setDescriptionLength(0); + }, []); + useEffect(() => { + popoverRefs.current.forEach((el) => { + if (el) { + new bootstrap.Popover(el, { + trigger: "focus", + placement: "right", + html: true, + content: el.getAttribute("data-bs-content"), // use inline content from attribute + }); + } + }); + }, [masterFeatures]); - MasterRespository.createRole(result).then((resp)=>{ - setIsLoading(false) - const cachedData = getCachedData( "Application Role" ); - const updatedData = [...cachedData, resp.data]; - cacheData("Application Role", updatedData); - showToast( "Application Role Added successfully.", "success" ); - onClose() - } ).catch( ( err ) => - { - - showToast(err?.response?.data?.message, "error"); - setIsLoading( false ) - onClose() - }) - - -}; -const [descriptionLength, setDescriptionLength] = useState(0); -const maxDescriptionLength = 255; -useEffect(() => { - setDescriptionLength(0); -}, []); - - return ( - -
- -
- - - {errors.role &&

{errors.role.message}

} -
- -
- + + +
+ + + {errors.role &&

{errors.role.message}

} +
+ + +
+