Compare commits
No commits in common. "de088fcfc20f7f619d1c9e287c2034d9d68e62f6" and "8e12eb67970d1cd106ea0aab1ac863109fcfbf49" have entirely different histories.
de088fcfc2
...
8e12eb6797
@ -5,7 +5,6 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||||||
import Label from "../../common/Label";
|
import Label from "../../common/Label";
|
||||||
import {
|
import {
|
||||||
useBranchDetails,
|
useBranchDetails,
|
||||||
useBranchTypes,
|
|
||||||
useCreateBranch,
|
useCreateBranch,
|
||||||
useServiceProjects,
|
useServiceProjects,
|
||||||
useUpdateBranch,
|
useUpdateBranch,
|
||||||
@ -13,8 +12,6 @@ import {
|
|||||||
import { useAppForm } from "../../../hooks/appHooks/useAppForm";
|
import { useAppForm } from "../../../hooks/appHooks/useAppForm";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { BranchSchema, defaultBranches } from "../ServiceProjectSchema";
|
import { BranchSchema, defaultBranches } from "../ServiceProjectSchema";
|
||||||
import InputSuggessionField from "../../common/Forms/InputSuggesstionField";
|
|
||||||
import InputSuggestions from "../../common/InputSuggestion";
|
|
||||||
|
|
||||||
const ManageBranch = ({ closeModal, BranchToEdit = null }) => {
|
const ManageBranch = ({ closeModal, BranchToEdit = null }) => {
|
||||||
const {
|
const {
|
||||||
@ -23,7 +20,7 @@ const ManageBranch = ({ closeModal, BranchToEdit = null }) => {
|
|||||||
isError,
|
isError,
|
||||||
error: requestError,
|
error: requestError,
|
||||||
} = useBranchDetails(BranchToEdit);
|
} = useBranchDetails(BranchToEdit);
|
||||||
const { data: branchTypes } = useBranchTypes();
|
|
||||||
const [contacts, setContacts] = React.useState([
|
const [contacts, setContacts] = React.useState([
|
||||||
{
|
{
|
||||||
contactPerson: "",
|
contactPerson: "",
|
||||||
@ -125,17 +122,15 @@ const ManageBranch = ({ closeModal, BranchToEdit = null }) => {
|
|||||||
<Label htmlFor="branchType" className="form-label" required>
|
<Label htmlFor="branchType" className="form-label" required>
|
||||||
Branch Type
|
Branch Type
|
||||||
</Label>
|
</Label>
|
||||||
|
<input
|
||||||
<InputSuggestions
|
type="text"
|
||||||
organizationList={branchTypes}
|
id="branchType"
|
||||||
value={watch("branchType") || ""}
|
className="form-control form-control-sm"
|
||||||
onChange={(val) =>
|
{...register("branchType")}
|
||||||
setValue("branchType", val, { shouldValidate: true })
|
|
||||||
}
|
|
||||||
error={errors.branchType?.message}
|
|
||||||
/>
|
/>
|
||||||
|
{errors.branchType && (
|
||||||
|
<small className="danger-text">{errors.branchType.message}</small>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const ServiceBranch = () => {
|
|||||||
const handleDelete = (id) => {
|
const handleDelete = (id) => {
|
||||||
setDeletingId(id);
|
setDeletingId(id);
|
||||||
DeleteBranch(
|
DeleteBranch(
|
||||||
{ id, isActive: showInactive },
|
{ id, isActive: false },
|
||||||
{
|
{
|
||||||
onSettled: () => {
|
onSettled: () => {
|
||||||
setDeletingId(null);
|
setDeletingId(null);
|
||||||
@ -64,13 +64,9 @@ const ServiceBranch = () => {
|
|||||||
{IsDeleteModalOpen && (
|
{IsDeleteModalOpen && (
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
isOpen={IsDeleteModalOpen}
|
isOpen={IsDeleteModalOpen}
|
||||||
type={!showInactive ? "delete" : "undo"}
|
type="delete"
|
||||||
header={!showInactive ? "Delete Branch" : "Restore Branch"}
|
header="Delete Expense"
|
||||||
message={
|
message="Are you sure you want delete?"
|
||||||
!showInactive
|
|
||||||
? "Are you sure you want delete?"
|
|
||||||
: "Are you sure you want restore?"
|
|
||||||
}
|
|
||||||
onSubmit={handleDelete}
|
onSubmit={handleDelete}
|
||||||
onClose={() => setIsDeleteModalOpen(false)}
|
onClose={() => setIsDeleteModalOpen(false)}
|
||||||
loading={isPending}
|
loading={isPending}
|
||||||
@ -186,9 +182,9 @@ const ServiceBranch = () => {
|
|||||||
>
|
>
|
||||||
<i className="bx bx-dots-vertical-rounded text-muted p-0"></i>
|
<i className="bx bx-dots-vertical-rounded text-muted p-0"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<ul className="dropdown-menu dropdown-menu-end w-auto">
|
<ul className="dropdown-menu dropdown-menu-end w-auto">
|
||||||
{!showInactive ? (
|
{/* Modify */}
|
||||||
<>
|
|
||||||
<li
|
<li
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setManageState({
|
setManageState({
|
||||||
@ -202,6 +198,8 @@ const ServiceBranch = () => {
|
|||||||
Modify
|
Modify
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
{/* Delete */}
|
||||||
<li
|
<li
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsDeleteModalOpen(true);
|
setIsDeleteModalOpen(true);
|
||||||
@ -213,20 +211,6 @@ const ServiceBranch = () => {
|
|||||||
Delete
|
Delete
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<li
|
|
||||||
onClick={() => {
|
|
||||||
setIsDeleteModalOpen(true);
|
|
||||||
setDeletingId(branch.id);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<a className="dropdown-item px-2 cursor-pointer py-1">
|
|
||||||
<i className="bx bx-undo text-danger me-2"></i>
|
|
||||||
Restore
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@ -18,10 +18,8 @@ const ConfirmModal = ({
|
|||||||
return <i className="bx bx-x-circle text-danger" style={{ fontSize: "60px" }}></i>;
|
return <i className="bx bx-x-circle text-danger" style={{ fontSize: "60px" }}></i>;
|
||||||
case "success":
|
case "success":
|
||||||
return <i className="bx bx-archive-in text-warning" style={{ fontSize: "60px" }}></i>;
|
return <i className="bx bx-archive-in text-warning" style={{ fontSize: "60px" }}></i>;
|
||||||
case "archive":
|
case "warning":
|
||||||
return <i className="bx bx-error-circle text-warning" style={{ fontSize: "60px" }}></i>;
|
return <i className="bx bx-error-circle text-warning" style={{ fontSize: "60px" }}></i>;
|
||||||
case "undo":
|
|
||||||
return <i className="bx bx-undo text-info" style={{ fontSize: "50px" }}></i>;
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,19 +2,15 @@ import React, { useEffect, useRef, useState } from "react";
|
|||||||
import Label from "../Label";
|
import Label from "../Label";
|
||||||
|
|
||||||
const InputSuggessionField = ({
|
const InputSuggessionField = ({
|
||||||
suggesstionList = [],
|
organizationList = [],
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
error,
|
error,
|
||||||
disabled = false,
|
disabled=false
|
||||||
label = "Label",
|
|
||||||
placeholder = "Please Enter",
|
|
||||||
required = false,
|
|
||||||
isLoading = false,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const dropdownRef = useRef(null);
|
const dropdownRef = useRef(null);
|
||||||
console.log(suggesstionList)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleClickOutside = (event) => {
|
const handleClickOutside = (event) => {
|
||||||
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||||
@ -25,12 +21,12 @@ console.log(suggesstionList)
|
|||||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const selectedOption = suggesstionList.find((opt) => opt === value);
|
const selectedOption = options.find((opt) => opt[valueKey] === value);
|
||||||
|
|
||||||
const displayText = selectedOption ? selectedOption : placeholder;
|
const displayText = selectedOption ? selectedOption[labelKey] : placeholder;
|
||||||
|
|
||||||
const handleSelect = (option) => {
|
const handleSelect = (option) => {
|
||||||
onChange(option);
|
onChange(option[valueKey]);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,14 +68,16 @@ console.log(suggesstionList)
|
|||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{suggesstionList.map((option, i) => (
|
{options.map((option, i) => (
|
||||||
<li key={i}>
|
<li key={i}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`dropdown-item ${option === value ? "active" : ""}`}
|
className={`dropdown-item ${
|
||||||
|
option[valueKey] === value ? "active" : ""
|
||||||
|
}`}
|
||||||
onClick={() => handleSelect(option)}
|
onClick={() => handleSelect(option)}
|
||||||
>
|
>
|
||||||
{option}
|
{option[labelKey]}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -5,13 +5,14 @@ const InputSuggestions = ({
|
|||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
error,
|
error,
|
||||||
disabled = false,
|
disabled=false
|
||||||
}) => {
|
}) => {
|
||||||
const [filteredList, setFilteredList] = useState([]);
|
const [filteredList, setFilteredList] = useState([]);
|
||||||
const [showSuggestions, setShowSuggestions] = useState(false);
|
const [showSuggestions, setShowSuggestions] = useState(false);
|
||||||
const handleInputChange = (e) => {
|
const handleInputChange = (e) => {
|
||||||
const val = e.target.value;
|
const val = e.target.value;
|
||||||
onChange(val);
|
onChange(val);
|
||||||
|
|
||||||
const matches = organizationList.filter((org) =>
|
const matches = organizationList.filter((org) =>
|
||||||
org.toLowerCase().includes(val.toLowerCase())
|
org.toLowerCase().includes(val.toLowerCase())
|
||||||
);
|
);
|
||||||
@ -25,7 +26,7 @@ const InputSuggestions = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-3 position-relative">
|
<div className="position-relative">
|
||||||
<input
|
<input
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
value={value}
|
value={value}
|
||||||
@ -38,19 +39,19 @@ const InputSuggestions = ({
|
|||||||
/>
|
/>
|
||||||
{showSuggestions && filteredList.length > 0 && (
|
{showSuggestions && filteredList.length > 0 && (
|
||||||
<ul
|
<ul
|
||||||
className="dropdown-menu w-100 shadow-sm show animate__fadeIn"
|
className="list-group shadow-sm position-absolute w-100 bg-white border zindex-tooltip"
|
||||||
style={{
|
style={{
|
||||||
maxHeight: "180px",
|
maxHeight: "180px",
|
||||||
overflowY: "auto",
|
overflowY: "auto",
|
||||||
marginTop: "2px",
|
marginTop: "2px",
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
borderRadius: "0px",
|
borderRadius:"0px"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{filteredList.map((org) => (
|
{filteredList.map((org) => (
|
||||||
<li
|
<li
|
||||||
key={org}
|
key={org}
|
||||||
className="ropdown-item"
|
className="list-group-item list-group-item-action border-none "
|
||||||
style={{
|
style={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
padding: "5px 12px",
|
padding: "5px 12px",
|
||||||
@ -58,15 +59,17 @@ const InputSuggestions = ({
|
|||||||
transition: "background-color 0.2s",
|
transition: "background-color 0.2s",
|
||||||
}}
|
}}
|
||||||
onMouseDown={() => handleSelectSuggestion(org)}
|
onMouseDown={() => handleSelectSuggestion(org)}
|
||||||
className={`dropdown-item ${
|
onMouseEnter={(e) =>
|
||||||
org === value ? "active" : ""
|
(e.currentTarget.style.backgroundColor = "#f8f9fa")
|
||||||
}`}
|
}
|
||||||
|
onMouseLeave={(e) =>
|
||||||
|
(e.currentTarget.style.backgroundColor = "transparent")
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{org}
|
{org}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{error && <small className="danger-text">{error}</small>}
|
{error && <small className="danger-text">{error}</small>}
|
||||||
|
|||||||
@ -148,11 +148,6 @@ export const useAllocationServiceProjectTeam = (onSuccessCallback) => {
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#region Service Jobs
|
//#region Service Jobs
|
||||||
|
|
||||||
export const useServiceProjectJobs = (
|
export const useServiceProjectJobs = (
|
||||||
@ -299,12 +294,6 @@ export const useUpdateServiceProjectJob = (onSuccessCallback) => {
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#region Branch
|
//#region Branch
|
||||||
export const useBranches = (
|
export const useBranches = (
|
||||||
projectId,
|
projectId,
|
||||||
@ -336,15 +325,6 @@ export const useBranches = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useBranchTypes = ()=>{
|
|
||||||
return useQuery({
|
|
||||||
queryKey:["branch_Type"],
|
|
||||||
queryFn:async()=> {
|
|
||||||
const resp = await ServiceProjectRepository.GetBranchTypeList();
|
|
||||||
return resp.data;
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useBranchDetails = (id) => {
|
export const useBranchDetails = (id) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@ -377,7 +357,6 @@ export const useCreateBranch = (onSuccessCallBack) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useUpdateBranch = (onSuccessCallBack) => {
|
export const useUpdateBranch = (onSuccessCallBack) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
@ -409,9 +388,9 @@ export const useDeleteBranch = () => {
|
|||||||
mutationFn: async ({ id, isActive }) =>
|
mutationFn: async ({ id, isActive }) =>
|
||||||
await ServiceProjectRepository.DeleteBranch(id, isActive),
|
await ServiceProjectRepository.DeleteBranch(id, isActive),
|
||||||
|
|
||||||
onSuccess: (_,variable) => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["branches"] });
|
queryClient.invalidateQueries({ queryKey: ["branches"] });
|
||||||
showToast(`Branch ${variable.isActive ? "restored":"deleted"} successfully`, "success");
|
showToast("Branch deleted successfully", "success");
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
|||||||
@ -56,5 +56,5 @@ export const ServiceProjectRepository = {
|
|||||||
DeleteBranch: (id, isActive = false) =>
|
DeleteBranch: (id, isActive = false) =>
|
||||||
api.delete(`/api/ServiceProject/branch/delete/${id}?isActive=${isActive}`),
|
api.delete(`/api/ServiceProject/branch/delete/${id}?isActive=${isActive}`),
|
||||||
|
|
||||||
GetBranchTypeList: () => api.get(`/api/serviceproject/branch-type/list`),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user