fixed update and creation for contacts

This commit is contained in:
pramod mahajan 2025-09-11 17:34:56 +05:30
parent 1a04dd51fc
commit 717264c9f9
3 changed files with 11 additions and 10 deletions

View File

@ -35,7 +35,7 @@ export const ContactSchema = z.object({
tags: z tags: z
.array( .array(
z.object({ z.object({
id: z.string().nullable(), id: z.string().nullable().optional(),
name: z.string(), name: z.string(),
}) })
) )

View File

@ -87,6 +87,7 @@ const ManageContact = ({ contactId, closeModal }) => {
: [{ label: "Office", phoneNumber: "" }], : [{ label: "Office", phoneNumber: "" }],
contactCategoryId: contactData.contactCategory?.id || "", contactCategoryId: contactData.contactCategory?.id || "",
address: contactData?.address || "",
projectIds: contactData.projects?.map((p) => p.id) || [], projectIds: contactData.projects?.map((p) => p.id) || [],
bucketIds: contactData.buckets?.map((b) => b.id) || [], bucketIds: contactData.buckets?.map((b) => b.id) || [],
tags: contactData.tags || [], tags: contactData.tags || [],
@ -177,7 +178,6 @@ const ManageContact = ({ contactId, closeModal }) => {
}; };
const isPending = updating || creating; const isPending = updating || creating;
return ( return (
<FormProvider {...methods}> <FormProvider {...methods}>
<form className="p-2 p-sm-0" onSubmit={handleSubmit(onSubmit)}> <form className="p-2 p-sm-0" onSubmit={handleSubmit(onSubmit)}>
@ -205,12 +205,13 @@ const ManageContact = ({ contactId, closeModal }) => {
<Label htmlFor={"organization"} required> <Label htmlFor={"organization"} required>
Organization Organization
</Label> </Label>
<InputSuggestions <InputSuggestions
organizationList={organizationList} organizationList={organizationList}
value={getValues("organization") || ""} value={watch("organization") || ""}
onChange={(val) => setValue("organization", val)} onChange={(val) => setValue("organization", val, { shouldValidate: true })}
error={errors.organization?.message} error={errors.organization?.message}
/> />
</div> </div>
</div> </div>
@ -471,13 +472,14 @@ const ManageContact = ({ contactId, closeModal }) => {
{/* Actions */} {/* Actions */}
<div className="d-flex justify-content-end gap-3 py-2"> <div className="d-flex justify-content-end gap-3 py-2">
<button className="btn btn-sm btn-primary" type="submit"> <button className="btn btn-sm btn-primary" type="submit" disabled={isPending}>
{isPending ? "Please Wait..." : "Submit"} {isPending ? "Please Wait..." : "Submit"}
</button> </button>
<button <button
className="btn btn-sm btn-secondary" className="btn btn-sm btn-secondary"
type="button" type="button"
onClick={handleClosed} onClick={handleClosed}
disabled={isPending}
> >
Cancel Cancel
</button> </button>

View File

@ -8,7 +8,6 @@ const InputSuggestions = ({
}) => { }) => {
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);