Refactor_Expenses #321
@ -1,17 +1,17 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { getProjectStatusName } from "../../utils/projectStatus";
|
import { getProjectStatusName } from "../../utils/projectStatus";
|
||||||
import {useProjectDetails, useUpdateProject} from "../../hooks/useProjects";
|
import { useProjectDetails, useUpdateProject } from "../../hooks/useProjects";
|
||||||
import { useSelector } from "react-redux"; // Import useSelector
|
import { useSelector } from "react-redux"; // Import useSelector
|
||||||
import {useHasUserPermission} from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import {MANAGE_PROJECT} from "../../utils/constants";
|
import { MANAGE_PROJECT } from "../../utils/constants";
|
||||||
import GlobalModel from "../common/GlobalModel";
|
import GlobalModel from "../common/GlobalModel";
|
||||||
import ManageProjectInfo from "./ManageProjectInfo";
|
import ManageProjectInfo from "./ManageProjectInfo";
|
||||||
import {useQueryClient} from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
const AboutProject = () => {
|
const AboutProject = () => {
|
||||||
const [IsOpenModal, setIsOpenModal] = useState(false);
|
const [IsOpenModal, setIsOpenModal] = useState(false);
|
||||||
const {mutate: UpdateProjectDetails, isPending} = useUpdateProject({
|
const { mutate: UpdateProjectDetails, isPending } = useUpdateProject({
|
||||||
onSuccessCallback: () => {
|
onSuccessCallback: () => {
|
||||||
setIsOpenModal(false);
|
setIsOpenModal(false);
|
||||||
}
|
}
|
||||||
@ -22,43 +22,43 @@ const AboutProject = () => {
|
|||||||
const projectId = useSelector((store) => store.localVariables.projectId);
|
const projectId = useSelector((store) => store.localVariables.projectId);
|
||||||
|
|
||||||
const manageProject = useHasUserPermission(MANAGE_PROJECT);
|
const manageProject = useHasUserPermission(MANAGE_PROJECT);
|
||||||
const {projects_Details, isLoading, error,refetch} = useProjectDetails( projectId ); // Pass projectId from useSelector
|
const { projects_Details, isLoading, error, refetch } = useProjectDetails(projectId); // Pass projectId from useSelector
|
||||||
|
|
||||||
const handleFormSubmit = ( updatedProject ) => {
|
const handleFormSubmit = (updatedProject) => {
|
||||||
if ( projects_Details?.id ) {
|
if (projects_Details?.id) {
|
||||||
UpdateProjectDetails({ projectId: projects_Details?.id,updatedData: updatedProject });
|
UpdateProjectDetails({ projectId: projects_Details?.id, updatedData: updatedProject });
|
||||||
// The refetch here might be redundant or could be handled by react-query's invalidateQueries
|
// The refetch here might be redundant or could be handled by react-query's invalidateQueries
|
||||||
// if UpdateProjectDetails properly invalidates the 'projectDetails' query key.
|
// if UpdateProjectDetails properly invalidates the 'projectDetails' query key.
|
||||||
// If refetch is still needed, consider adding a delay or using onSuccess of UpdateProjectDetails.
|
// If refetch is still needed, consider adding a delay or using onSuccess of UpdateProjectDetails.
|
||||||
// For now, keeping it as is based on your original code.
|
// For now, keeping it as is based on your original code.
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{IsOpenModal && (
|
{IsOpenModal && (
|
||||||
<GlobalModel isOpen={IsOpenModal} closeModal={()=>setIsOpenModal(false)}>
|
<GlobalModel isOpen={IsOpenModal} closeModal={() => setIsOpenModal(false)}>
|
||||||
<ManageProjectInfo
|
<ManageProjectInfo
|
||||||
project={projects_Details}
|
project={projects_Details}
|
||||||
handleSubmitForm={handleFormSubmit}
|
handleSubmitForm={handleFormSubmit}
|
||||||
onClose={() => setIsOpenModal( false )}
|
onClose={() => setIsOpenModal(false)}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
/>
|
/>
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
{projects_Details && (
|
{projects_Details && (
|
||||||
<>
|
<>
|
||||||
<div className="card mb-6">
|
<div className="card mb-6">
|
||||||
<div className="card-header text-start">
|
<div className="card-header text-start">
|
||||||
<h6 className="card-action-title mb-0">
|
<h6 className="card-action-title mb-0">
|
||||||
{" "}
|
{" "}
|
||||||
<i className="fa fa-building rounded-circle text-primary"></i>
|
<i className="fa fa-building rounded-circle text-primary"></i>
|
||||||
<span className="ms-2">Project Profile</span>
|
<span className="ms-2">Project Profile</span>
|
||||||
</h6>
|
</h6>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<ul className="list-unstyled my-3 ps-2">
|
<ul className="list-unstyled my-3 ps-2">
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}> {/* Adjust width as needed for alignment */}
|
<div className="d-flex align-items-center" style={{ width: '120px' }}> {/* Adjust width as needed for alignment */}
|
||||||
<i className="bx bx-cog"></i>
|
<i className="bx bx-cog"></i>
|
||||||
@ -140,27 +140,12 @@ const AboutProject = () => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<li className="d-flex justify-content-center mt-4"> {/* Added mt-4 for some top margin */}
|
|
||||||
{manageProject && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={`btn btn-sm btn-primary ${!manageProject && "d-none"
|
|
||||||
}`}
|
|
||||||
data-bs-toggle="modal"
|
|
||||||
data-bs-target="#edit-project-modal"
|
|
||||||
onClick={() => setIsOpenModal(true)}
|
|
||||||
>
|
|
||||||
Modify Details
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isLoading && <span>loading...</span>}
|
{isLoading && <span>loading...</span>}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user