aded validation for tags and rename label to bucket
This commit is contained in:
parent
73f57bb59f
commit
36e7755b7d
@ -17,16 +17,14 @@ import { changeMaster } from "../../slices/localVariablesSlice";
|
|||||||
import { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
import { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import SelectMultiple from "../common/SelectMultiple";
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
import {ContactSchema} from "./DirectorySchema";
|
import { ContactSchema } from "./DirectorySchema";
|
||||||
import InputSuggestions from "../common/InputSuggestion";
|
import InputSuggestions from "../common/InputSuggestion";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const ManageDirectory = ({ submitContact, onCLosed }) => {
|
const ManageDirectory = ({ submitContact, onCLosed }) => {
|
||||||
const selectedMaster = useSelector(
|
const selectedMaster = useSelector(
|
||||||
(store) => store.localVariables.selectedMaster
|
(store) => store.localVariables.selectedMaster
|
||||||
);
|
);
|
||||||
const [ categoryData, setCategoryData ] = useState( [] );
|
const [categoryData, setCategoryData] = useState([]);
|
||||||
|
|
||||||
const [TagsData, setTagsData] = useState([]);
|
const [TagsData, setTagsData] = useState([]);
|
||||||
const { data, loading } = useMaster();
|
const { data, loading } = useMaster();
|
||||||
@ -34,7 +32,7 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
const { projects, loading: projectLoading } = useProjects();
|
const { projects, loading: projectLoading } = useProjects();
|
||||||
const { contactCategory, loading: contactCategoryLoading } =
|
const { contactCategory, loading: contactCategoryLoading } =
|
||||||
useContactCategory();
|
useContactCategory();
|
||||||
const {organizationList,loading:orgLoading} = useOrganization()
|
const { organizationList, loading: orgLoading } = useOrganization();
|
||||||
const { contactTags, loading: Tagloading } = useContactTags();
|
const { contactTags, loading: Tagloading } = useContactTags();
|
||||||
const [IsSubmitting, setSubmitting] = useState(false);
|
const [IsSubmitting, setSubmitting] = useState(false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@ -79,15 +77,14 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
remove: removePhone,
|
remove: removePhone,
|
||||||
} = useFieldArray({ control, name: "contactPhones" });
|
} = useFieldArray({ control, name: "contactPhones" });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (emailFields.length === 0) {
|
if (emailFields.length === 0) {
|
||||||
appendEmail({ label: "Work", emailAddress: "" });
|
appendEmail({ label: "Work", emailAddress: "" });
|
||||||
}
|
}
|
||||||
if (phoneFields.length === 0) {
|
if (phoneFields.length === 0) {
|
||||||
appendPhone({ label: "Office", phoneNumber: "" });
|
appendPhone({ label: "Office", phoneNumber: "" });
|
||||||
}
|
}
|
||||||
}, [emailFields.length, phoneFields.length]);
|
}, [emailFields.length, phoneFields.length]);
|
||||||
|
|
||||||
|
|
||||||
const handleAddEmail = async () => {
|
const handleAddEmail = async () => {
|
||||||
const emails = getValues("contactEmails");
|
const emails = getValues("contactEmails");
|
||||||
@ -124,22 +121,21 @@ useEffect(() => {
|
|||||||
setValue("bucketIds", updated, { shouldValidate: true });
|
setValue("bucketIds", updated, { shouldValidate: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = ( data ) =>
|
const onSubmit = (data) => {
|
||||||
{
|
const cleaned = {
|
||||||
const cleaned = {
|
...data,
|
||||||
...data,
|
contactEmails: (data.contactEmails || []).filter(
|
||||||
contactEmails: (data.contactEmails || []).filter(
|
(e) => e.emailAddress?.trim() !== ""
|
||||||
(e) => e.emailAddress?.trim() !== ""
|
),
|
||||||
),
|
contactPhones: (data.contactPhones || []).filter(
|
||||||
contactPhones: (data.contactPhones || []).filter(
|
(p) => p.phoneNumber?.trim() !== ""
|
||||||
(p) => p.phoneNumber?.trim() !== ""
|
),
|
||||||
),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
submitContact(cleaned, reset, setSubmitting);
|
submitContact(cleaned, reset, setSubmitting);
|
||||||
};
|
};
|
||||||
const orgValue = watch("organization")
|
const orgValue = watch("organization");
|
||||||
|
|
||||||
const handleClosed = () => {
|
const handleClosed = () => {
|
||||||
onCLosed();
|
onCLosed();
|
||||||
@ -165,16 +161,11 @@ useEffect(() => {
|
|||||||
<div className="col-md-6 text-start">
|
<div className="col-md-6 text-start">
|
||||||
<label className="form-label">Organization</label>
|
<label className="form-label">Organization</label>
|
||||||
<InputSuggestions
|
<InputSuggestions
|
||||||
organizationList={organizationList}
|
organizationList={organizationList}
|
||||||
value={getValues("organization") || ""}
|
value={getValues("organization") || ""}
|
||||||
onChange={(val) => setValue("organization", val)}
|
onChange={(val) => setValue("organization", val)}
|
||||||
error={errors.organization?.message}
|
error={errors.organization?.message}
|
||||||
/>
|
/>
|
||||||
{errors.organization && (
|
|
||||||
<small className="danger-text">
|
|
||||||
{errors.organization.message}
|
|
||||||
</small>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row mt-1">
|
<div className="row mt-1">
|
||||||
@ -216,7 +207,10 @@ useEffect(() => {
|
|||||||
// onClick={handleAddEmail}
|
// onClick={handleAddEmail}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddEmail} />
|
<i
|
||||||
|
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
||||||
|
onClick={handleAddEmail}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -224,8 +218,10 @@ useEffect(() => {
|
|||||||
// onClick={() => removeEmail(index)}
|
// onClick={() => removeEmail(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={() => removeEmail(index)} />
|
<i
|
||||||
|
className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-primary"
|
||||||
|
onClick={() => removeEmail(index)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{errors.contactEmails?.[index]?.emailAddress && (
|
{errors.contactEmails?.[index]?.emailAddress && (
|
||||||
@ -275,8 +271,10 @@ useEffect(() => {
|
|||||||
// onClick={handleAddPhone}
|
// onClick={handleAddPhone}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddPhone} />
|
<i
|
||||||
|
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
||||||
|
onClick={handleAddPhone}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -284,8 +282,10 @@ useEffect(() => {
|
|||||||
// onClick={() => removePhone(index)}
|
// onClick={() => removePhone(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danager" onClick={() => removePhone(index)} />
|
<i
|
||||||
|
className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danager"
|
||||||
|
onClick={() => removePhone(index)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{errors.contactPhones?.[index]?.phoneNumber && (
|
{errors.contactPhones?.[index]?.phoneNumber && (
|
||||||
@ -297,9 +297,9 @@ useEffect(() => {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{errors.contactPhone?.message && (
|
{errors.contactPhone?.message && (
|
||||||
<div className="danger-text">{errors.contactPhone.message}</div>
|
<div className="danger-text">{errors.contactPhone.message}</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="row my-1">
|
<div className="row my-1">
|
||||||
@ -315,7 +315,7 @@ useEffect(() => {
|
|||||||
</option>
|
</option>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<option disabled value="">
|
<option disabled value="">
|
||||||
Select Category
|
Select Category
|
||||||
</option>
|
</option>
|
||||||
{contactCategory?.map((cate) => (
|
{contactCategory?.map((cate) => (
|
||||||
@ -341,29 +341,23 @@ useEffect(() => {
|
|||||||
valueKey="id"
|
valueKey="id"
|
||||||
IsLoading={projectLoading}
|
IsLoading={projectLoading}
|
||||||
/>
|
/>
|
||||||
{errors.projectIds && (
|
{errors.projectIds && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">{errors.projectIds.message}</small>
|
||||||
{errors.projectIds.message}
|
|
||||||
</small>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 text-start">
|
||||||
<TagInput name="tags" label="Tags" options={contactTags} />
|
<TagInput name="tags" label="Tags" options={contactTags} />
|
||||||
{errors.tags && (
|
{errors.tags && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">{errors.tags.message}</small>
|
||||||
{errors.tags.message}
|
)}
|
||||||
</small>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-md-12 mt-1 text-start">
|
<div className="col-md-12 mt-1 text-start">
|
||||||
<label className="form-label ">Select Label</label>
|
<label className="form-label ">Select Bucket</label>
|
||||||
|
|
||||||
<ul
|
<ul className="d-flex flex-wrap px-1 list-unstyled mb-0">
|
||||||
className="d-flex flex-wrap px-1 list-unstyled mb-0"
|
|
||||||
>
|
|
||||||
{bucketsLoaging && <p>Loading...</p>}
|
{bucketsLoaging && <p>Loading...</p>}
|
||||||
{buckets?.map((item) => (
|
{buckets?.map((item) => (
|
||||||
<li
|
<li
|
||||||
@ -387,11 +381,12 @@ useEffect(() => {
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
{errors.bucketIds && (
|
||||||
|
<small className="danger-text mt-0">
|
||||||
|
{errors.bucketIds.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{errors.BucketIds && (
|
|
||||||
<small className="text-danger">{errors.BucketIds.message}</small>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user