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;
// 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",
});