From 7cc8cc99c2feaf9ce06de2bf97ae7e2a340f438d Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Wed, 19 Nov 2025 16:30:51 +0530 Subject: [PATCH] Creating a list view and modal for Branches. --- src/components/ServiceProject/BranchSchema.js | 43 +++++ .../ServiceProject/ManageBranch.jsx | 176 ++++++++++++++++++ .../ServiceProject/ServiceBranch.jsx | 170 +++++++++++++++++ .../ServiceProject/ServiceProjectProfile.jsx | 5 + src/repositories/ServiceProjectRepository.jsx | 9 + 5 files changed, 403 insertions(+) create mode 100644 src/components/ServiceProject/BranchSchema.js create mode 100644 src/components/ServiceProject/ManageBranch.jsx create mode 100644 src/components/ServiceProject/ServiceBranch.jsx diff --git a/src/components/ServiceProject/BranchSchema.js b/src/components/ServiceProject/BranchSchema.js new file mode 100644 index 00000000..346654d3 --- /dev/null +++ b/src/components/ServiceProject/BranchSchema.js @@ -0,0 +1,43 @@ +import { z } from "zod"; + +export const BranchSchema = () => + z.object({ + projectId: z + .string() + .trim() + .min(1, { message: "Project is required" }), + + branchName: z + .string() + .trim() + .min(1, { message: "Branch Name is required" }), + + contactInformation: z + .string() + .trim() + .min(1, { message: "Contact Information is required" }), + + address: z + .string() + .trim() + .min(1, { message: "Address is required" }), + + branchType: z + .string() + .trim() + .min(1, { message: "Branch Type is required" }), + + googleMapUrl: z + .string() + .trim() + .url({ message: "Enter a valid Google Map URL" }), + }); + +export const defaultBranches = { + branchName: "", + projectId: "", + contactInformation: "", + address: "", + branchType: "", + googleMapUrl: "", +}; \ No newline at end of file diff --git a/src/components/ServiceProject/ManageBranch.jsx b/src/components/ServiceProject/ManageBranch.jsx new file mode 100644 index 00000000..51c8f7f6 --- /dev/null +++ b/src/components/ServiceProject/ManageBranch.jsx @@ -0,0 +1,176 @@ +import React from 'react' +import { useProjectName } from '../../hooks/useProjects'; +import { BranchSchema, defaultBranches } from './BranchSchema'; +import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import Label from '../common/Label'; + +const ManageBranch = ({ BranchToEdit = null }) => { + + const schema = BranchSchema(); + const { + register, + control, + watch, + handleSubmit, + setValue, + reset, + formState: { errors }, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: defaultBranches, + }); + + const { + projectNames, + loading: projectLoading, + error, + isError: isProjectError, + } = useProjectName(); + + const handleClose = () => { + reset(); + closeModal(); + }; + + + return ( +
+
+ {BranchToEdit + ? "Update Branch" + : "Create Branch"} +
+
+
+
+ + + {errors.projectId && ( + {errors.projectId.message} + )} +
+ +
+ + + {errors.branchName && ( + {errors.branchName.message} + )} +
+
+ +
+
+ + + {errors.contactInformation && ( + {errors.contactInformation.message} + )} +
+ +
+ + + {errors.address && ( + {errors.address.message} + )} +
+
+ + +
+
+ + + {errors.branchType && ( + {errors.branchType.message} + )} +
+ +
+ + + {errors.googleMapUrl && ( + {errors.googleMapUrl.message} + )} +
+
+ +
+ + + +
+ + + +
+
+ ) +} + +export default ManageBranch diff --git a/src/components/ServiceProject/ServiceBranch.jsx b/src/components/ServiceProject/ServiceBranch.jsx new file mode 100644 index 00000000..7722bb19 --- /dev/null +++ b/src/components/ServiceProject/ServiceBranch.jsx @@ -0,0 +1,170 @@ +import React, { useState } from 'react' +import GlobalModel from '../common/GlobalModel'; +import ManageBranch from './ManageBranch'; + +const ServiceBranch = () => { + + const [ManageServiceBranch, setManageServiceBranch] = useState({ + IsOpen: null, + branchId: null, + }); + + const ServiceBranch = [ + { + key: "branchName", + label: "Branch Name", + align: "text-start", + getValue: (e) => e?.payee || "N/A", + }, + ]; + return ( +
+
+
+
+ +
+
+ + +
+ {/* {Array.isArray(filteredData) && filteredData.length > 0 && ( */} + + + + {ServiceBranch.map((col) => ( + + ))} + + + + + {/* + {filteredData?.length > 0 ? ( + filteredData?.map((recurringExpense) => ( + + {recurringExpenseColumns.map((col) => ( + + ))} + + + )) + ) : ( + + + + )} + */} +
+ {col.label} + Action
+ {col?.customRender + ? col?.customRender(recurringExpense) + : col?.getValue(recurringExpense)} + +
+ + setViewRecurring({ + recurringId: recurringExpense?.id, + view: true, + }) + } + > + +
+ +
    +
  • + setManageServiceBranch({ + IsOpen: true, + RecurringId: recurringExpense?.id, + }) + } + > + + + Modify + +
  • + +
  • { + setIsDeleteModalOpen(true); + setDeletingId(recurringExpense.id); + }} + > + + + Delete + +
  • +
+
+
+
+ {/* )} */} + {/* {!filteredData || + filteredData.length === 0 + && ( +
+ {isError ? (

{error.message}

) : (

No Recurring Expense Found

)} +
+ )} */} +
+ + {ManageServiceBranch.IsOpen && ( + + setManageServiceBranch({ IsOpen: null, branchId: null }) + } + > + + setManageServiceBranch({ IsOpen: null, branchId: null }) + } + // requestToEdit={ManageServiceBranch.branchId} + /> + + )} +
+
+ ) +} + +export default ServiceBranch diff --git a/src/components/ServiceProject/ServiceProjectProfile.jsx b/src/components/ServiceProject/ServiceProjectProfile.jsx index 8e131852..05a05fd3 100644 --- a/src/components/ServiceProject/ServiceProjectProfile.jsx +++ b/src/components/ServiceProject/ServiceProjectProfile.jsx @@ -5,6 +5,7 @@ import { formatUTCToLocalTime } from "../../utils/dateUtils"; import ManageServiceProject from "./ManageServiceProject"; import GlobalModel from "../common/GlobalModel"; import { SpinnerLoader } from "../common/Loader"; +import ServiceBranch from "./ServiceBranch"; const ServiceProjectProfile = () => { const { projectId } = useParams(); @@ -114,6 +115,10 @@ const ServiceProjectProfile = () => { +
+ +
+ diff --git a/src/repositories/ServiceProjectRepository.jsx b/src/repositories/ServiceProjectRepository.jsx index 94ef3c8e..1da42fd2 100644 --- a/src/repositories/ServiceProjectRepository.jsx +++ b/src/repositories/ServiceProjectRepository.jsx @@ -35,4 +35,13 @@ export const ServiceProjectRepository = { api.patch(`/api/ServiceProject/job/edit/${id}`, patchData, { "Content-Type": "application/json-patch+json", }), + + //Branch API + getServiceBranch: (jobTicketId, pageSize, pageNumber) => + api.get( + `/api/serviceproject/branch/list?jobTicketId=${jobTicketId}&pageSize=${pageSize}&pageNumber=${pageNumber}` + ), + }; + +