refactor: create channel API
This commit is contained in:
@@ -35,7 +35,7 @@ export const channelApi = createApi({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
createChannel: builder.mutation<number, CreateChannelDTO>({
|
createChannel: builder.mutation<Channel | number, CreateChannelDTO>({
|
||||||
query: (data) => ({
|
query: (data) => ({
|
||||||
url: "group",
|
url: "group",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const ChannelModal: FC<Props> = ({ personal = false, closeModal }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { users, input, updateInput } = useFilteredUsers();
|
const { users, input, updateInput } = useFilteredUsers();
|
||||||
const [createChannel, { isSuccess, isError, isLoading, data: newChannelId }] =
|
const [createChannel, { isSuccess, isError, isLoading, data: newChannel }] =
|
||||||
useCreateChannelMutation();
|
useCreateChannelMutation();
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
@@ -63,12 +63,13 @@ const ChannelModal: FC<Props> = ({ personal = false, closeModal }) => {
|
|||||||
}, [isError]);
|
}, [isError]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess && newChannel) {
|
||||||
toast.success("create new channel success");
|
toast.success("create new channel success");
|
||||||
closeModal();
|
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>) => {
|
const handleNameInput = (evt: ChangeEvent<HTMLInputElement>) => {
|
||||||
setData((prev) => ({ ...prev, name: evt.target.value }));
|
setData((prev) => ({ ...prev, name: evt.target.value }));
|
||||||
|
|||||||
Reference in New Issue
Block a user