diff --git a/src/pages/Private/settings/ChannelSettings.tsx b/src/pages/Private/settings/ChannelSettings.tsx index 7fffb88a..348f4d39 100644 --- a/src/pages/Private/settings/ChannelSettings.tsx +++ b/src/pages/Private/settings/ChannelSettings.tsx @@ -42,6 +42,27 @@ const ChannelSettings: () => Menu = () => { id: '', public: userChannels?.data[0]?.channel?.public, }); + const [isFormClicked, setIsFormClicked] = useState(false); + + const handleLeaveChannelForm = () => { + if (selectedUserChannelIndex === 0) { + setSelectedUserChannelIndex(0); + return setChannelPayload({ + name: userChannels?.data[1]?.channel?.name || '', + description: userChannels?.data[1]?.channel?.description || null, + id: userChannels?.data[1]?.channel?.id || '', + public: userChannels?.data[1]?.channel?.public, + }); + } + + setSelectedUserChannelIndex(0); + return setChannelPayload({ + name: userChannels?.data[0]?.channel?.name || '', + description: userChannels?.data[0]?.channel?.description || null, + id: userChannels?.data[0]?.channel?.id || '', + public: userChannels?.data[0]?.channel?.public, + }); + }; const [isDropOpen, setIsDropOpen] = useState(false); const { t } = useTranslation(); @@ -55,10 +76,16 @@ const ChannelSettings: () => Menu = () => { const showLeaveButton = user?.id !== selectedChannel?.createdBy?.id; - const isFormInitialState = - channelPayload.name === selectedChannel?.name && - channelPayload.description === selectedChannel?.description && - channelPayload.public === selectedChannel?.public; + const isFormInitialState = () => { + if (isFormClicked) { + return ( + channelPayload.name === selectedChannel?.name && + channelPayload.description === selectedChannel?.description && + channelPayload.public === selectedChannel?.public + ); + } + return true; + }; useEffect(() => { dispatch(getUserChannelsAllAction()); @@ -100,7 +127,7 @@ const ChannelSettings: () => Menu = () => { url: 'channel', saveButton: (