Skip to content

Commit b86aa0a

Browse files
committed
Uglily add form validation
1 parent 4804a89 commit b86aa0a

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

frontend/src/app/(auth)/match/page.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import Container from "@/components/ui/Container";
66
import { Form, FormControl, FormField, FormItem } from "@/components/ui/form";
77
import { MultiSelect } from "@/components/ui/multiselect";
88
import MoonLoader from "react-spinners/MoonLoader";
9-
import { useEffect } from "react";
109
import { useForm } from "react-hook-form";
1110
import { Client as StompClient } from "@stomp/stompjs";
1211
import SockJS from "sockjs-client";
13-
import { useRef, useState } from "react";
12+
import { useRef, useState, useEffect } from "react";
1413
import FindPeerHeader from "@/app/(auth)/components/match/FindPeerHeader";
1514
import {
1615
preferredLanguagesList,
@@ -74,7 +73,7 @@ const SOCKET_URL =
7473

7574
const CURRENT_USER = getBaseUserData().username; // Username is unique
7675

77-
const TIMEOUT_TIMER = 3; // in seconds
76+
const TIMEOUT_TIMER = 100; // in seconds
7877

7978
const FindPeer = () => {
8079
const stompClientRef = useRef<StompClient | null>(null);
@@ -189,9 +188,11 @@ const FindPeer = () => {
189188
onDisconnect: () => {
190189
console.log("STOMP connection closed");
191190
setIsConnected(false);
191+
clearTimeout(timeout);
192192
},
193193
onStompError: (error) => {
194194
console.error("STOMP error: ", error);
195+
clearTimeout(timeout);
195196
reject(new Error(error.headers.message));
196197
},
197198
});
@@ -248,6 +249,24 @@ const FindPeer = () => {
248249
});
249250

250251
const onSubmit = (data: FindMatchFormOutput) => {
252+
if (!data.questionDifficulties.length) {
253+
Swal.fire(
254+
"Error",
255+
"Please select at least one difficulty level",
256+
"error"
257+
);
258+
return;
259+
} else if (!data.preferredLanguages.length) {
260+
Swal.fire(
261+
"Error",
262+
"Please select at least one preferred programming language",
263+
"error"
264+
);
265+
return;
266+
} else if (!data.questionTopics.length) {
267+
Swal.fire("Error", "Please select at least one topic", "error");
268+
return;
269+
}
251270
sendMatchRequest(data);
252271
};
253272

0 commit comments

Comments
 (0)