diff --git a/components/publisher/PublisherForm.js b/components/publisher/PublisherForm.js index 51ae652..7d76de3 100644 --- a/components/publisher/PublisherForm.js +++ b/components/publisher/PublisherForm.js @@ -92,15 +92,15 @@ export default function PublisherForm({ item, me }) { let { familyHeadId, userId, congregationId, ...rest } = publisher; // Set the familyHead relation based on the selected head - const familyHeadRelation = familyHeadId ? { connect: { id: familyHeadId } } : { disconnect: true }; - const userRel = userId ? { connect: { id: userId } } : { disconnect: true }; - const congregationRel = congregationId ? { connect: { id: parseInt(congregationId) } } : { disconnect: true }; + const familyHeadRelation = familyHeadId ? { connect: { id: familyHeadId } } : null; + const userRel = userId ? { connect: { id: userId } } : null; + const congregationRel = congregationId ? { connect: { id: parseInt(congregationId) } } : null; // Return the new state without familyHeadId and with the correct familyHead relation rest = { ...rest, - familyHead: familyHeadRelation, - user: userRel, - congregation: congregationRel + ...(familyHeadRelation ? { familyHead: familyHeadRelation } : {}), + ...(userRel ? { user: userRel } : {}), + ...(congregationRel ? { congregation: congregationRel } : {}), }; try { @@ -112,7 +112,7 @@ export default function PublisherForm({ item, me }) { position: "bottom-center", }); } else { - await axiosInstance.post(urls.apiUrl, publisher); + await axiosInstance.post(urls.apiUrl, rest); toast.success("Task Saved", { position: "bottom-center", });