Przeglądaj źródła

create group fix

Viktoriia 4 miesięcy temu
rodzic
commit
e1545dde63

+ 7 - 1
src/modules/api/chat/chat-api.ts

@@ -174,6 +174,12 @@ export interface PostCreateGroup {
   members_can_send_messages?: 0 | 1;
 }
 
+export interface PostCreateGroupReturn extends ResponseType {
+  groupToken: string;
+  groupAvatar: string | null;
+  can_send_messages: boolean;
+}
+
 export const chatApi = {
   searchUsers: (token: string, search: string) =>
     request.postForm<PostSearchUsersReturn>(API.SEARCH_USERS, { token, search }),
@@ -254,7 +260,7 @@ export const chatApi = {
       } as unknown as Blob);
     }
 
-    return request.postForm<ResponseType>(API.CREATE_GROUP, formData);
+    return request.postForm<PostCreateGroupReturn>(API.CREATE_GROUP, formData);
   },
   getGroupChat: (
     token: string,

+ 9 - 8
src/modules/api/chat/queries/use-post-create-group.tsx

@@ -1,17 +1,18 @@
 import { useMutation } from '@tanstack/react-query';
 
 import { chatQueryKeys } from '../chat-query-keys';
-import { chatApi, type PostCreateGroup } from '../chat-api';
+import { chatApi, type PostCreateGroup, type PostCreateGroupReturn } from '../chat-api';
 
 import type { BaseAxiosError } from '../../../../types';
-import { ResponseType } from '@api/response-type';
 
 export const usePostCreateGroupMutation = () => {
-  return useMutation<ResponseType, BaseAxiosError, PostCreateGroup, ResponseType>({
-    mutationKey: chatQueryKeys.createGroup(),
-    mutationFn: async (data) => {
-      const response = await chatApi.createGroup(data);
-      return response.data;
+  return useMutation<PostCreateGroupReturn, BaseAxiosError, PostCreateGroup, PostCreateGroupReturn>(
+    {
+      mutationKey: chatQueryKeys.createGroup(),
+      mutationFn: async (data) => {
+        const response = await chatApi.createGroup(data);
+        return response.data;
+      }
     }
-  });
+  );
 };

+ 4 - 5
src/screens/InAppScreens/MessagesScreen/Components/RouteAddGroup.tsx

@@ -122,15 +122,14 @@ const RouteAddGroup = () => {
 
         await createGroup(groupData, {
           onSuccess: (res) => {
-            console.log('res', res);
             setIsSubmitting(false);
             navigation.navigate(
               ...([
-                NAVIGATION_PAGES.CHAT,
+                NAVIGATION_PAGES.GROUP_CHAT,
                 {
-                  id: 8948,
-                  name: 'Test Name',
-                  avatar: null,
+                  group_token: res.groupToken,
+                  name: values.name,
+                  avatar: res.groupAvatar,
                   userType: 'normal'
                 }
               ] as never)