fixed Modal provider component and setup organization creation

This commit is contained in:
pramod mahajan 2025-09-17 19:45:42 +05:30
parent 3c4c25b449
commit 2e65007f26
2 changed files with 25 additions and 30 deletions

View File

@ -6,12 +6,10 @@ import {
organizationSchema, organizationSchema,
} from "./OrganizationSchema"; } from "./OrganizationSchema";
import Modal from "../common/Modal"; import Modal from "../common/Modal";
import { import { useCreateOrganization, useOrganizationModal } from "../../hooks/useOrganization";
useCreateOrganization,
useOrganizationModal,
} from "../../hooks/useOrganization";
import Label from "../common/Label"; import Label from "../common/Label";
import SelectMultiple from "../common/SelectMultiple"; import SelectMultiple from "../common/SelectMultiple";
import { useServices } from "../../hooks/masterHook/useMaster";
const ManageOrganization = () => { const ManageOrganization = () => {
const orgModal = useOrganizationModal(); const orgModal = useOrganizationModal();
@ -25,20 +23,15 @@ const ManageOrganization = () => {
const { const {
handleSubmit, handleSubmit,
register, register,
reset,
formState: { errors }, formState: { errors },
} = method; } = method;
const { mutate: CreateOrganization, isPending } = useCreateOrganization( const {mutate:CreateOrganization,isPending} = useCreateOrganization(()=>{})
() => {
reset(defaultOrganizationValues);
orgModal.onClose();
}
);
const onSubmit = (OrgPayload) => { const onSubmit = (OrgPayload) => {
CreateOrganization(OrgPayload); CreateOrganization()
}; };
console.log(services)
const contentBody = ( const contentBody = (
<FormProvider {...method}> <FormProvider {...method}>
<form className="form" onSubmit={handleSubmit(onSubmit)}> <form className="form" onSubmit={handleSubmit(onSubmit)}>
@ -85,18 +78,30 @@ const ManageOrganization = () => {
<Label htmlFor="email" required> <Label htmlFor="email" required>
Email Address Email Address
</Label> </Label>
<input className="form-control form-control-sm" /> <input
className="form-control form-control-sm"
{...register("email")}
/>
{errors.email && (
<span className="danger-text">{errors.email.message}</span>
)}
</div> </div>
<div className="mb-1 text-start"> <div className="mb-1 text-start">
<SelectMultiple <SelectMultiple
name="serviceIds" name="serviceIds"
label="Services" label="Services"
required={true} required={true}
valueKey="id" valueKey="id"
options={services?.data || []}
/> />
{errors.serviceIds && (
<span className="danger-text">{errors.serviceIds.message}</span>
)}
</div> </div>
<div className="mb-1 text-start"> <div className="mb-1 text-start">
<Label htmlFor="organization" required> <Label htmlFor="address" required>
Address Address
</Label> </Label>
<textarea <textarea
@ -113,16 +118,11 @@ const ManageOrganization = () => {
<button <button
type="button" type="button"
className="btn btn-sm btn-secondary" className="btn btn-sm btn-secondary"
onClick={orgModal.onClose} onClick={orgModal.onClose} disabled={isPending || isLoading}
disabled={isPending || isLoading}
> >
Cancel Cancel
</button> </button>
<button <button type="submit" className="btn btn-sm btn-primary" disabled={isPending || isLoading}>
type="submit"
className="btn btn-sm btn-primary"
disabled={isPending || isLoading}
>
{isPending ? "Please Wait...":"Submit"} {isPending ? "Please Wait...":"Submit"}
</button> </button>
</div> </div>
@ -134,9 +134,7 @@ const ManageOrganization = () => {
<Modal <Modal
isOpen={orgModal.isOpen} isOpen={orgModal.isOpen}
onClose={orgModal.onClose} onClose={orgModal.onClose}
onSubmit={onSubmit} title="Manage Organization"
title={"Manage Organization"}
actionLabel={"Submit"}
body={contentBody} body={contentBody}
/> />
); );

View File

@ -12,7 +12,6 @@ const SelectMultiple = ({
valueKey = "id", valueKey = "id",
placeholder = "Please select...", placeholder = "Please select...",
IsLoading = false, IsLoading = false,
required = false,
}) => { }) => {
const { setValue, watch } = useFormContext(); const { setValue, watch } = useFormContext();
const selectedValues = watch(name) || []; const selectedValues = watch(name) || [];
@ -147,9 +146,7 @@ const SelectMultiple = ({
className="multi-select-dropdown-container" className="multi-select-dropdown-container"
style={{ position: "relative" }} style={{ position: "relative" }}
> >
<Label htmlFor={name} required={required}> <label>{label}</label>
{label}
</Label>
<div <div
className="multi-select-dropdown-header" className="multi-select-dropdown-header"