refactor: create channel API

This commit is contained in:
Tristan Yang
2023-01-13 21:26:23 +08:00
parent d6847c9968
commit 2a5e378e73
2 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ export const channelApi = createApi({
}
}
}),
createChannel: builder.mutation<number, CreateChannelDTO>({
createChannel: builder.mutation<Channel | number, CreateChannelDTO>({
query: (data) => ({
url: "group",
method: "POST",
+5 -4
View File
@@ -33,7 +33,7 @@ const ChannelModal: FC<Props> = ({ personal = false, closeModal }) => {
});
const { users, input, updateInput } = useFilteredUsers();
const [createChannel, { isSuccess, isError, isLoading, data: newChannelId }] =
const [createChannel, { isSuccess, isError, isLoading, data: newChannel }] =
useCreateChannelMutation();
const handleToggle = () => {
@@ -63,12 +63,13 @@ const ChannelModal: FC<Props> = ({ personal = false, closeModal }) => {
}, [isError]);
useEffect(() => {
if (isSuccess) {
if (isSuccess && newChannel) {
toast.success("create new channel success");
closeModal();
navigateTo(`/chat/channel/${newChannelId}`);
const id = typeof newChannel == 'object' ? newChannel.gid : newChannel;
navigateTo(`/chat/channel/${id}`);
}
}, [isSuccess, newChannelId]);
}, [isSuccess, newChannel]);
const handleNameInput = (evt: ChangeEvent<HTMLInputElement>) => {
setData((prev) => ({ ...prev, name: evt.target.value }));