integrated job details api and optimized form
This commit is contained in:
parent
9b7988d6d8
commit
297e0712bc
@ -3,6 +3,11 @@
|
|||||||
--bs-nav-link-font-size: 0.7375rem;
|
--bs-nav-link-font-size: 0.7375rem;
|
||||||
--bg-border-color :#f8f6f6
|
--bg-border-color :#f8f6f6
|
||||||
}
|
}
|
||||||
|
.offcanvas.offcanvas-wide {
|
||||||
|
width: 700px !important; /* adjust as needed */
|
||||||
|
max-width: 90vw; /* responsive fallback */
|
||||||
|
}
|
||||||
|
|
||||||
/* ===========================% Background_Colors %========================================================== */
|
/* ===========================% Background_Colors %========================================================== */
|
||||||
.bg-light-primary {
|
.bg-light-primary {
|
||||||
background-color: color-mix(in srgb, var(--bs-primary) 10.4%, transparent);
|
background-color: color-mix(in srgb, var(--bs-primary) 10.4%, transparent);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import { getNextBadgeColor } from "../../utils/appUtils";
|
import { getNextBadgeColor } from "../../utils/appUtils";
|
||||||
import { useServiceProjectJobs } from "../../hooks/useServiceProject";
|
import { useServiceProjectJobs } from "../../hooks/useServiceProject";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
@ -6,8 +6,12 @@ import EmployeeAvatarGroup from "../common/EmployeeAvatarGroup";
|
|||||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
import { SpinnerLoader } from "../common/Loader";
|
import { SpinnerLoader } from "../common/Loader";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import ProjectPage from "../../pages/project/ProjectPage";
|
||||||
|
import { useServiceProjectJobContext } from "./Jobs";
|
||||||
|
|
||||||
|
|
||||||
const JobList = ({ filterByProject }) => {
|
const JobList = ({ filterByProject }) => {
|
||||||
|
const {setSelectedJob} = useServiceProjectJobContext()
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const { data, isLoading, isError, error } = useServiceProjectJobs(
|
const { data, isLoading, isError, error } = useServiceProjectJobs(
|
||||||
ITEMS_PER_PAGE,
|
ITEMS_PER_PAGE,
|
||||||
@ -55,7 +59,7 @@ const JobList = ({ filterByProject }) => {
|
|||||||
label: "Start Date",
|
label: "Start Date",
|
||||||
getValue: (e) => formatUTCToLocalTime(e.startDate),
|
getValue: (e) => formatUTCToLocalTime(e.startDate),
|
||||||
isAlwaysVisible: true,
|
isAlwaysVisible: true,
|
||||||
className: "text-center ",
|
className: "text-center d-none d-sm-table-cell ",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "dueDate",
|
key: "dueDate",
|
||||||
@ -108,7 +112,7 @@ const JobList = ({ filterByProject }) => {
|
|||||||
</button>
|
</button>
|
||||||
<div className="dropdown-menu dropdown-menu-end">
|
<div className="dropdown-menu dropdown-menu-end">
|
||||||
{/* View always visible */}
|
{/* View always visible */}
|
||||||
<button className="dropdown-item py-1">
|
<button className="dropdown-item py-1" onClick={()=>setSelectedJob({showCanvas:true,job:row?.id})}>
|
||||||
<i className="bx bx-detail bx-sm"></i> View
|
<i className="bx bx-detail bx-sm"></i> View
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|||||||
@ -1,48 +1,79 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||||
import JobList from "./JobList";
|
import JobList from "./JobList";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useServiceProjects } from "../../hooks/useServiceProject";
|
import { useServiceProjects } from "../../hooks/useServiceProject";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
|
import OffcanvasComponent from "../common/OffcanvasComponent";
|
||||||
|
import showToast from "../../services/toastService";
|
||||||
|
import ManageJob from "./ManageJob";
|
||||||
|
import ManageJobTicket from "./ManageJobTicket";
|
||||||
|
|
||||||
|
export const JonContext = createContext();
|
||||||
|
export const useServiceProjectJobContext = () => {
|
||||||
|
const context = useContext(JonContext);
|
||||||
|
if (!context) {
|
||||||
|
showToast("Something went wrong", "warning");
|
||||||
|
window.location = "/dashboard";
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
const Jobs = () => {
|
const Jobs = () => {
|
||||||
|
const [showCanvas, setShowCanvas] = useState(false);
|
||||||
const [selectedProject, setSelectedProject] = useState(null);
|
const [selectedProject, setSelectedProject] = useState(null);
|
||||||
|
const [selectJob,setSelectedJob] = useState({showCanvas:false,job:null})
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { data } = useServiceProjects(ITEMS_PER_PAGE, 1);
|
const { data } = useServiceProjects(ITEMS_PER_PAGE, 1);
|
||||||
|
|
||||||
|
const contextProvider = {
|
||||||
|
setSelectedJob
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="card page-min-h my-2 px-4">
|
<>
|
||||||
<div className="row">
|
<JonContext.Provider value={contextProvider}>
|
||||||
<div className="col-12 py-2 d-flex justify-content-between ">
|
<OffcanvasComponent
|
||||||
<div>
|
id="customCanvas"
|
||||||
{" "}
|
title="Job"
|
||||||
<select
|
placement="end"
|
||||||
className="form-select form-select-sm"
|
show={selectJob.showCanvas}
|
||||||
value={selectedProject}
|
onClose={() => setSelectedJob({showCanvas:false,job:null})}
|
||||||
onChange={(e) => setSelectedProject(e.target.value)}
|
>
|
||||||
>
|
<ManageJobTicket Job={selectJob} />
|
||||||
<option disabled selected>
|
</OffcanvasComponent>
|
||||||
Select Poject
|
<div className="card page-min-h my-2 px-4">
|
||||||
</option>
|
<div className="row">
|
||||||
{data?.data?.map((project) => (
|
<div className="col-12 py-2 d-flex justify-content-between ">
|
||||||
<option key={project.id} value={project.id}>
|
<div>
|
||||||
{project.name}
|
{" "}
|
||||||
</option>
|
<select
|
||||||
))}
|
className="form-select form-select-sm"
|
||||||
</select>
|
value={selectedProject}
|
||||||
</div>
|
onChange={(e) => setSelectedProject(e.target.value)}
|
||||||
<div className="px-2">
|
>
|
||||||
<button
|
<option disabled selected>
|
||||||
className="btn btn-sm btn-primary"
|
Select Poject
|
||||||
onClick={() => navigate("/service/job")}
|
</option>
|
||||||
>
|
{data?.data?.map((project) => (
|
||||||
<i className="bx bx-plus-circle bx-md me-2"></i>New Job
|
<option key={project.id} value={project.id}>
|
||||||
</button>
|
{project.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="px-2">
|
||||||
|
<button
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
onClick={() => navigate("/service/job")}
|
||||||
|
>
|
||||||
|
<i className="bx bx-plus-circle bx-md me-2"></i>New Job
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<JobList filterByProject={selectedProject} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</JonContext.Provider>
|
||||||
<JobList filterByProject={selectedProject} />
|
</>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Breadcrumb from "../common/Breadcrumb";
|
import Breadcrumb from "../common/Breadcrumb";
|
||||||
import Label from "../common/Label";
|
import Label from "../common/Label";
|
||||||
import { FormProvider, useForm } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { defaultJobValue, jobSchema } from "./ServiceProjectSchema";
|
import { defaultJobValue, jobSchema } from "./ServiceProjectSchema";
|
||||||
import {
|
import {
|
||||||
@ -13,9 +12,15 @@ import DatePicker from "../common/DatePicker";
|
|||||||
import PmsEmployeeInputTag from "../common/PmsEmployeeInputTag";
|
import PmsEmployeeInputTag from "../common/PmsEmployeeInputTag";
|
||||||
import TagInput from "../common/TagInput";
|
import TagInput from "../common/TagInput";
|
||||||
import { localToUtc } from "../../utils/appUtils";
|
import { localToUtc } from "../../utils/appUtils";
|
||||||
|
import SelectField from "../common/Forms/SelectField";
|
||||||
|
import {
|
||||||
|
AppFormController,
|
||||||
|
AppFormProvider,
|
||||||
|
useAppForm,
|
||||||
|
} from "../../hooks/appHooks/useAppForm";
|
||||||
|
|
||||||
const ManageJob = () => {
|
const ManageJob = () => {
|
||||||
const methods = useForm({
|
const methods = useAppForm({
|
||||||
resolver: zodResolver(jobSchema),
|
resolver: zodResolver(jobSchema),
|
||||||
defaultValues: defaultJobValue,
|
defaultValues: defaultJobValue,
|
||||||
});
|
});
|
||||||
@ -40,21 +45,6 @@ const ManageJob = () => {
|
|||||||
reset();
|
reset();
|
||||||
});
|
});
|
||||||
const onSubmit = (formData) => {
|
const onSubmit = (formData) => {
|
||||||
// if (serviceProjectId) {
|
|
||||||
// let existingServiceIds = projectdata?.services?.map((s) => s.id) || [];
|
|
||||||
|
|
||||||
// const oldAssigneed = projectdata.services.map((service) => ({
|
|
||||||
// serviceId: service.id,
|
|
||||||
// isActive: formData.services.includes(service.id),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// const newAassigneed = formData.services
|
|
||||||
// .filter((s) => !existingServiceIds.includes(s))
|
|
||||||
// .map((service) => ({ serviceId: service, isActive: true }));
|
|
||||||
|
|
||||||
// formData.assignees = [...oldServices, ...newServices];
|
|
||||||
// }
|
|
||||||
|
|
||||||
formData.assignees = formData.assignees.map((emp) => ({
|
formData.assignees = formData.assignees.map((emp) => ({
|
||||||
employeeId: emp,
|
employeeId: emp,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@ -62,9 +52,10 @@ const ManageJob = () => {
|
|||||||
|
|
||||||
formData.startDate = localToUtc(formData.startDate);
|
formData.startDate = localToUtc(formData.startDate);
|
||||||
formData.dueDate = localToUtc(formData.dueDate);
|
formData.dueDate = localToUtc(formData.dueDate);
|
||||||
CreateJob(formData);
|
// CreateJob(formData);
|
||||||
|
console.log(formData);
|
||||||
};
|
};
|
||||||
|
console.log(errors);
|
||||||
return (
|
return (
|
||||||
<div className="container-fluid">
|
<div className="container-fluid">
|
||||||
<Breadcrumb
|
<Breadcrumb
|
||||||
@ -75,48 +66,39 @@ const ManageJob = () => {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<div className="card m-auto page-min-h">
|
<div className="card m-auto page-min-h">
|
||||||
<div className="col-4 p-3"></div>
|
<div className="col-md-4 col-12 p-3"></div>
|
||||||
<div className="col-md-8 p-3">
|
<div className="col-md-8 p-3">
|
||||||
<FormProvider {...methods}>
|
<AppFormProvider {...methods}>
|
||||||
<form className="row text-start" onSubmit={handleSubmit(onSubmit)}>
|
<form className="row text-start" onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div>
|
<div>
|
||||||
<p className="fs-5 fw-medium">Create Job</p>
|
<p className="fs-5 fw-medium">Create Job</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
<div className="col-12 col-md-6 mb-2 ">
|
||||||
<Label required>Title</Label>
|
<Label required>Title</Label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
{...register("title")}
|
{...register("title")}
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
<div className="col-12 col-md-6 mb-2">
|
||||||
<Label required>Project</Label>
|
<AppFormController
|
||||||
<select
|
name="projectId"
|
||||||
className="form-select form-select-sm"
|
control={control}
|
||||||
{...register("projectId")}
|
render={({ field }) => (
|
||||||
>
|
<SelectField
|
||||||
{isProjectLoading ? (
|
label="Project"
|
||||||
<option selected disabled>
|
options={data?.data}
|
||||||
Loading....
|
placeholder="Choose a Project"
|
||||||
</option>
|
required
|
||||||
) : (
|
labelKeyKey="name"
|
||||||
<>
|
valueKeyKey="id"
|
||||||
<option selected disabled>
|
value={field.value}
|
||||||
Select Project
|
onChange={field.onChange}
|
||||||
</option>
|
isLoading={isProjectLoading}
|
||||||
{data?.data?.map((project) => (
|
/>
|
||||||
<option
|
|
||||||
key={project.id}
|
|
||||||
value={project.id}
|
|
||||||
className="selection-option"
|
|
||||||
>
|
|
||||||
{project.name}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</select>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
||||||
<Label required>Start Date</Label>
|
<Label required>Start Date</Label>
|
||||||
@ -124,7 +106,7 @@ const ManageJob = () => {
|
|||||||
name="startDate"
|
name="startDate"
|
||||||
control={control}
|
control={control}
|
||||||
placeholder="DD-MM-YYYY"
|
placeholder="DD-MM-YYYY"
|
||||||
className="w-full"
|
className="w-full form-control-md"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
||||||
@ -165,7 +147,7 @@ const ManageJob = () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</AppFormProvider>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
71
src/components/ServiceProject/ManageJobTicket.jsx
Normal file
71
src/components/ServiceProject/ManageJobTicket.jsx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { useServiceProjectJobDetails } from "../../hooks/useServiceProject";
|
||||||
|
import { SpinnerLoader } from "../common/Loader";
|
||||||
|
import Error from "../common/Error";
|
||||||
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
|
import Avatar from "../common/Avatar";
|
||||||
|
import EmployeeAvatarGroup from "../common/EmployeeAvatarGroup";
|
||||||
|
|
||||||
|
const ManageJobTicket = ({ Job }) => {
|
||||||
|
const { data, isLoading, isError, error } = useServiceProjectJobDetails(
|
||||||
|
Job?.job
|
||||||
|
);
|
||||||
|
if (isLoading) return <SpinnerLoader />;
|
||||||
|
if (isError)
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Error error={error} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className="row text-start">
|
||||||
|
<div className="col-12">
|
||||||
|
<h6 className="fs-5 fw-semibold">{data?.title}</h6>
|
||||||
|
<div className="d-flex justify-content-between">
|
||||||
|
<div className="d-flex flex-row gap-2">
|
||||||
|
<i className="bx bx-calendar"></i>{" "}
|
||||||
|
<span>{formatUTCToLocalTime(data?.createdAt, true)}</span>
|
||||||
|
</div>
|
||||||
|
<span className="badge bg-label-primary">{data?.status?.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex flex-wrap my-3">
|
||||||
|
<p>{data?.description}</p>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex flex-row gap-3">
|
||||||
|
<span className="fw-medium">
|
||||||
|
Start Date : {formatUTCToLocalTime(data?.startDate)}
|
||||||
|
</span>{" "}
|
||||||
|
<i className="bx bx-right-arrow-alt"></i>{" "}
|
||||||
|
<span className="fw-medium">
|
||||||
|
Due To : {formatUTCToLocalTime(data?.startDate)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex justify-content-between">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<small className="fs-6 text-secondary fs-italic me-3 mt-2">
|
||||||
|
<em>Created By</em>
|
||||||
|
</small>{" "}
|
||||||
|
<Avatar size="xs"
|
||||||
|
firstName={data?.createdBy?.firstName}
|
||||||
|
lastName={data?.createdBy?.lastName}
|
||||||
|
/>{" "}
|
||||||
|
<span className="fw-medium">{`${data?.createdBy?.firstName} ${data?.createdBy?.lastName}`}</span>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<small className="fs-6 text-secondary fs-italic me-3 mt-2">
|
||||||
|
<em>Created By</em>
|
||||||
|
</small><EmployeeAvatarGroup employees={data?.assignees}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr className="divider"/>
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManageJobTicket;
|
||||||
@ -31,6 +31,7 @@ export const defaultProjectValues = {
|
|||||||
|
|
||||||
//#region JobSchema
|
//#region JobSchema
|
||||||
|
|
||||||
|
|
||||||
export const TagSchema = z.object({
|
export const TagSchema = z.object({
|
||||||
name: z.string().min(1, "Tag name is required"),
|
name: z.string().min(1, "Tag name is required"),
|
||||||
isActive: z.boolean().default(true),
|
isActive: z.boolean().default(true),
|
||||||
|
|||||||
94
src/components/common/Forms/SelectField.jsx
Normal file
94
src/components/common/Forms/SelectField.jsx
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import Label from "../Label";
|
||||||
|
|
||||||
|
const SelectField = ({
|
||||||
|
label = "Select",
|
||||||
|
options = [],
|
||||||
|
placeholder = "Select Option",
|
||||||
|
required = false,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
valueKey = "id",
|
||||||
|
labelKey = "name",
|
||||||
|
isLoading = false,
|
||||||
|
}) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const dropdownRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event) => {
|
||||||
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const selectedOption = options.find((opt) => opt[valueKey] === value);
|
||||||
|
|
||||||
|
const displayText = selectedOption ? selectedOption[labelKey] : placeholder;
|
||||||
|
|
||||||
|
const handleSelect = (option) => {
|
||||||
|
onChange(option[valueKey]);
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleDropdown = () => setOpen((prev) => !prev);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mb-3 position-relative" ref={dropdownRef}>
|
||||||
|
{label && (
|
||||||
|
<Label className="form-label" required={required}>
|
||||||
|
{label}
|
||||||
|
</Label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`select2-icons form-select d-flex align-items-center justify-content-between ${
|
||||||
|
open ? "show" : ""
|
||||||
|
}`}
|
||||||
|
onClick={toggleDropdown}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={`text-truncate ${!selectedOption ? "text-muted" : ""}`}
|
||||||
|
>
|
||||||
|
{isLoading ? "Loading..." : displayText}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{open && !isLoading && (
|
||||||
|
<ul
|
||||||
|
className="dropdown-menu w-100 shadow-sm show animate__fadeIn"
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: "100%",
|
||||||
|
left: 0,
|
||||||
|
zIndex: 1050,
|
||||||
|
marginTop: "4px",
|
||||||
|
borderRadius: "0.375rem",
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((option, i) => (
|
||||||
|
<li key={i}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`dropdown-item ${
|
||||||
|
option[valueKey] === value ? "active" : ""
|
||||||
|
}`}
|
||||||
|
onClick={() => handleSelect(option)}
|
||||||
|
>
|
||||||
|
{option[labelKey]}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SelectField;
|
||||||
98
src/components/common/Forms/SelectFieldServerSide.jsx
Normal file
98
src/components/common/Forms/SelectFieldServerSide.jsx
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import Label from "../Label";
|
||||||
|
import { useDebounce } from "../../../utils/appUtils";
|
||||||
|
|
||||||
|
const SelectFieldServerSide = ({
|
||||||
|
label = "Select",
|
||||||
|
options = [],
|
||||||
|
placeholder = "Select Option",
|
||||||
|
required = false,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
valueKey = "id",
|
||||||
|
labelKey = "name",
|
||||||
|
isLoading = false,
|
||||||
|
}) => {
|
||||||
|
const [searchText,setSeachText] = useState("")
|
||||||
|
const debounce = useDebounce(searchText,300);
|
||||||
|
// const {} = use
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const dropdownRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event) => {
|
||||||
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const selectedOption = options.find((opt) => opt[valueKey] === value);
|
||||||
|
|
||||||
|
const displayText = selectedOption ? selectedOption[labelKey] : placeholder;
|
||||||
|
|
||||||
|
const handleSelect = (option) => {
|
||||||
|
onChange(option[valueKey]);
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleDropdown = () => setOpen((prev) => !prev);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mb-3 position-relative" ref={dropdownRef}>
|
||||||
|
{label && (
|
||||||
|
<Label className="form-label" required={required}>
|
||||||
|
{label}
|
||||||
|
</Label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`select2-icons form-select d-flex align-items-center justify-content-between ${
|
||||||
|
open ? "show" : ""
|
||||||
|
}`}
|
||||||
|
onClick={toggleDropdown}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={`text-truncate ${!selectedOption ? "text-muted" : ""}`}
|
||||||
|
>
|
||||||
|
{isLoading ? "Loading..." : displayText}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{open && !isLoading && (
|
||||||
|
<ul
|
||||||
|
className="dropdown-menu w-100 shadow-sm show animate__fadeIn"
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: "100%",
|
||||||
|
left: 0,
|
||||||
|
zIndex: 1050,
|
||||||
|
marginTop: "4px",
|
||||||
|
borderRadius: "0.375rem",
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((option, i) => (
|
||||||
|
<li key={i}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`dropdown-item ${
|
||||||
|
option[valueKey] === value ? "active" : ""
|
||||||
|
}`}
|
||||||
|
onClick={() => handleSelect(option)}
|
||||||
|
>
|
||||||
|
{option[labelKey]}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SelectFieldServerSide;
|
||||||
67
src/components/common/OffcanvasComponent.jsx
Normal file
67
src/components/common/OffcanvasComponent.jsx
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import React, { useEffect, useRef } from "react";
|
||||||
|
|
||||||
|
const OffcanvasComponent = ({
|
||||||
|
id = "globalOffcanvas",
|
||||||
|
title = "Offcanvas Title",
|
||||||
|
placement = "start", // start | end | top | bottom
|
||||||
|
children,
|
||||||
|
show = false,
|
||||||
|
onClose = () => {},
|
||||||
|
}) => {
|
||||||
|
const offcanvasRef = useRef(null);
|
||||||
|
const bsInstance = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!offcanvasRef.current) return;
|
||||||
|
|
||||||
|
// initialize once
|
||||||
|
bsInstance.current = bootstrap.Offcanvas.getOrCreateInstance(offcanvasRef.current);
|
||||||
|
|
||||||
|
const el = offcanvasRef.current;
|
||||||
|
const handleHide = () => onClose();
|
||||||
|
|
||||||
|
el.addEventListener("hidden.bs.offcanvas", handleHide);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
el.removeEventListener("hidden.bs.offcanvas", handleHide);
|
||||||
|
};
|
||||||
|
}, [onClose]);
|
||||||
|
|
||||||
|
// react to `show` changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (!bsInstance.current) return;
|
||||||
|
|
||||||
|
if (show) bsInstance.current.show();
|
||||||
|
else bsInstance.current.hide();
|
||||||
|
}, [show]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div >
|
||||||
|
<div
|
||||||
|
ref={offcanvasRef}
|
||||||
|
id={id}
|
||||||
|
className={`offcanvas offcanvas offcanvas-${placement} offcanvas-wide`}
|
||||||
|
tabIndex="-1"
|
||||||
|
aria-labelledby={`${id}-label`}
|
||||||
|
>
|
||||||
|
<div className="offcanvas-header">
|
||||||
|
<div className='d-flex flex-row gap-3'>
|
||||||
|
<i className='bx bx-lg bx-left-arrow-alt cursor-pointer' data-bs-dismiss="offcanvas"
|
||||||
|
aria-label="Close"></i> <i className='bx bx-briefcase text-primary'></i> <h5 className="offcanvas-title" id={`${id}-label`}>{title}</h5>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn-close"
|
||||||
|
data-bs-dismiss="offcanvas"
|
||||||
|
aria-label="Close"
|
||||||
|
></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="offcanvas-body">{children}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OffcanvasComponent;
|
||||||
6
src/hooks/appHooks/useAppForm.js
Normal file
6
src/hooks/appHooks/useAppForm.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { useForm, Controller,FormProvider } from "react-hook-form";
|
||||||
|
|
||||||
|
export const useAppForm = (config) => useForm(config);
|
||||||
|
export const AppFormProvider = FormProvider;
|
||||||
|
export const AppFormController = Controller;
|
||||||
|
|
||||||
@ -112,6 +112,16 @@ export const useServiceProjectJobs=(pageSize,pageNumber,isActive=true,project)=>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export const useServiceProjectJobDetails = (job)=>{
|
||||||
|
return useQuery({
|
||||||
|
queryKey:['service-job',job],
|
||||||
|
queryFn:async() =>{
|
||||||
|
const resp = await ServiceProjectRepository.GetJobDetails(job);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
enabled:!!job
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const useCreateServiceProjectJob = (onSuccessCallback) => {
|
export const useCreateServiceProjectJob = (onSuccessCallback) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|||||||
@ -19,4 +19,5 @@ export const ServiceProjectRepository = {
|
|||||||
api.get(
|
api.get(
|
||||||
`/api/ServiceProject/job/list?pageSize=${pageSize}&pageNumber=${pageNumber}&isActive=${isActive}&projectId=${projectId}`
|
`/api/ServiceProject/job/list?pageSize=${pageSize}&pageNumber=${pageNumber}&isActive=${isActive}&projectId=${projectId}`
|
||||||
),
|
),
|
||||||
|
GetJobDetails:(id)=>api.get(`/api/ServiceProject/job/details/${id}`)
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user