Fixes channel creation form resetting if also creating a group.

Also fixes group creation form not closing when saving.
This commit is contained in:
SergeantPanda 2025-05-03 13:28:01 -05:00
parent 693d33e18d
commit a387130d23
2 changed files with 21 additions and 4 deletions

View file

@ -339,6 +339,20 @@ const Channel = ({ channel = null, isOpen, onClose }) => {
// },
// });
// Update the handler for when channel group modal is closed
const handleChannelGroupModalClose = (newGroup) => {
setChannelGroupModalOpen(false);
// If a new group was created and returned, update the form with it
if (newGroup && newGroup.id) {
// Preserve all current form values while updating just the channel_group_id
formik.setValues({
...formik.values,
channel_group_id: `${newGroup.id}`
});
}
};
if (!isOpen) {
return <></>;
}
@ -804,7 +818,7 @@ const Channel = ({ channel = null, isOpen, onClose }) => {
<ChannelGroupForm
isOpen={channelGroupModelOpen}
onClose={() => setChannelGroupModalOpen(false)}
onClose={handleChannelGroupModalClose}
/>
</>
);

View file

@ -18,13 +18,16 @@ const ChannelGroup = ({ channelGroup = null, isOpen, onClose }) => {
const onSubmit = async () => {
const values = form.getValues();
let newGroup;
if (channelGroup) {
await API.updateChannelGroup({ id: channelGroup.id, ...values });
newGroup = await API.updateChannelGroup({ id: channelGroup.id, ...values });
} else {
await API.addChannelGroup(values);
newGroup = await API.addChannelGroup(values);
}
return form.reset();
form.reset();
onClose(newGroup); // Pass the new/updated group back to parent
};
if (!isOpen) {