diff --git a/App.tsx b/App.tsx
index 38ae918..b766208 100644
--- a/App.tsx
+++ b/App.tsx
@@ -26,6 +26,7 @@ import Loading from "./src/routes/Loading/Loading";
import StartStudying from "./src/routes/StartStudying/StartStudying";
import { ToastProvider } from "react-native-toast-notifications";
import InfoIcon from "./src/icons/InfoIcon/InfoIcon";
+import CreateGroup from "./src/routes/CreateGroup/CreateGroup";
const Drawer = createDrawerNavigator();
@@ -83,6 +84,7 @@ export default function App() {
+
diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx
index 3130d12..489ede2 100644
--- a/src/components/Api/Api.tsx
+++ b/src/components/Api/Api.tsx
@@ -255,6 +255,7 @@ export async function PatchStudentStatus(info: StudentStatusPatchType) {
})
.catch((error) => {
let error_message = ParseError(error);
+ console.log("Error!", error.response.data);
return [false, error_message];
});
}
diff --git a/src/interfaces/Interfaces.tsx b/src/interfaces/Interfaces.tsx
index 33844eb..8dd10b1 100644
--- a/src/interfaces/Interfaces.tsx
+++ b/src/interfaces/Interfaces.tsx
@@ -134,6 +134,7 @@ export interface StudentStatusType {
location: LocationType;
landmark: string | null;
active: boolean;
+ study_group: string;
}
export interface StudentStatusPatchType {
@@ -141,6 +142,7 @@ export interface StudentStatusPatchType {
location?: LocationType;
landmark?: string | null;
active?: boolean;
+ study_group?: string;
}
export interface StudentStatusFilterType {
@@ -168,7 +170,7 @@ export interface StudentStatusFilterTypeFlattened {
export interface StudyGroupType {
name: string;
- users: string[];
+ students: string[];
distance: number;
landmark: string | null;
location: LocationType;
diff --git a/src/routes/CreateGroup/CreateGroup.tsx b/src/routes/CreateGroup/CreateGroup.tsx
new file mode 100644
index 0000000..528cdc1
--- /dev/null
+++ b/src/routes/CreateGroup/CreateGroup.tsx
@@ -0,0 +1,194 @@
+import * as React from "react";
+import styles, { Viewport } from "../../styles";
+import {
+ View,
+ Text,
+ ToastAndroid,
+ TextInput,
+ NativeSyntheticEvent,
+ TextInputChangeEventData,
+} from "react-native";
+import { useState } from "react";
+import {
+ UserInfoReturnType,
+ OptionType,
+ RootDrawerParamList,
+ StudentStatusType,
+ StudentStatusReturnType,
+ StudentStatusPatchType,
+ StudyGroupCreateType,
+} from "../../interfaces/Interfaces";
+import Button from "../../components/Button/Button";
+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import {
+ PatchStudentStatus,
+ GetUserInfo,
+ ParseError,
+ CreateStudyGroup,
+} from "../../components/Api/Api";
+import { colors } from "../../styles";
+import DropDownPicker from "react-native-dropdown-picker";
+import AnimatedContainerNoScroll from "../../components/AnimatedContainer/AnimatedContainerNoScroll";
+import { urlProvider } from "../../components/Api/Api";
+import MapView, { UrlTile, Marker } from "react-native-maps";
+import { useNavigation } from "@react-navigation/native";
+import { useToast } from "react-native-toast-notifications";
+
+export default function CreateGroup({ route }: any) {
+ const { location, subject } = route.params;
+ const queryClient = useQueryClient();
+ const navigation = useNavigation();
+ const toast = useToast();
+
+ const [name, setName] = useState("");
+ const study_group_create = useMutation({
+ mutationFn: async (info: StudyGroupCreateType) => {
+ const data = await CreateStudyGroup(info);
+ if (data[0] != true) {
+ return Promise.reject(new Error());
+ }
+ return data;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["user"] });
+ queryClient.invalidateQueries({ queryKey: ["user_status"] });
+ student_status_patch.mutate({
+ study_group: name,
+ });
+ toast.show("Created successfully", {
+ type: "success",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ },
+ onError: (error: Error) => {
+ toast.show(String(error), {
+ type: "warning",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ },
+ });
+
+ const student_status_patch = useMutation({
+ mutationFn: async (info: StudentStatusPatchType) => {
+ const data = await PatchStudentStatus(info);
+ if (data[0] != true) {
+ return Promise.reject(new Error());
+ }
+ return data;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["user"] });
+ queryClient.invalidateQueries({ queryKey: ["user_status"] });
+ toast.show(`Joined group ${name} successfully`, {
+ type: "success",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ navigation.navigate("Home");
+ },
+ onError: (error: Error) => {
+ toast.show(String(error), {
+ type: "warning",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ },
+ });
+
+ if (location) {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ ): void => {
+ setName(e.nativeEvent.text);
+ }}
+ />
+
+
+
+
+
+ );
+ }
+ return ;
+}
diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx
index b3465b3..8adfa3f 100644
--- a/src/routes/Home/Home.tsx
+++ b/src/routes/Home/Home.tsx
@@ -416,7 +416,7 @@ export default function Home() {
Subject: {studygroup.subject}
- Students Studying: {studygroup.users.length}
+ Students Studying: {studygroup.students.length}