fix bug when creating new publishers afrer adding congregation field

This commit is contained in:
Dobromir Popov
2024-06-14 14:28:23 +03:00
parent 8ca0884acd
commit 901d577b9c

View File

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