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 ( - -
- + + + ); } diff --git a/src/utils/constants.jsx b/src/utils/constants.jsx index de875411..cd1f0ced 100644 --- a/src/utils/constants.jsx +++ b/src/utils/constants.jsx @@ -16,7 +16,7 @@ export const VIEW_PROJECT_INFRA = "c7b68e33-72f0-474f-bd96-77636427ecc8" export const REGULARIZE_ATTENDANCE ="57802c4a-00aa-4a1f-a048-fd2f70dd44b6" -export const ASSIGN_TO_PROJECT = "fbd213e0-0250-46f1-9f5f-4b2a1e6e76a3"; +export const ASSIGN_TO_PROJECT = "b94802ce-0689-4643-9e1d-11c86950c35b"; export const INFRASTRUCTURE = "9666de86-d7c7-4d3d-acaa-fcd6d6b81f3c"; @@ -24,4 +24,4 @@ export const MANAGE_TASK = "08752f33-3b29-4816-b76b-ea8a968ed3c5" export const VIEW_TASK = "9fcc5f87-25e3-4846-90ac-67a71ab92e3c" -export const ASSIGN_REPORT_TASK = "d135a4b0-4f9a-4903-ab9c-4843839ebdee" \ No newline at end of file +export const ASSIGN_REPORT_TASK = "6a32379b-8b3f-49a6-8c48-4b7ac1b55dc2" \ No newline at end of file