diff --git a/src/app/teams/create/page.tsx b/src/app/teams/create/page.tsx index 3c1bbc5..a36687a 100644 --- a/src/app/teams/create/page.tsx +++ b/src/app/teams/create/page.tsx @@ -10,34 +10,28 @@ import { toast } from "sonner"; import { useConvex } from "convex/react"; import { useSelector } from 'react-redux'; import { RootState } from '@/config/store'; +import createAxiosInstance from "@/config/AxiosProtectedRoute"; +import { createNewTeamUrl } from "@/lib/API-URLs"; function CreateTeam() { const [teamName, setTeamName] = useState(""); - const createTeam = useMutation(api.teams.createTeam); const user = useSelector((state:RootState)=>state.auth.user) - const convex = useConvex(); const router = useRouter(); + const axiosInstance = createAxiosInstance(user.accessToken); const createNewTeam = async() => { - const result = await convex.query(api.teams.getTeam, { - email: user?.email, - }); - //checking if team with same name alreaady exist. if yes then don't create that team - const team = result.find((team: any) => team?.teamName === teamName) - if(team){ - toast.error(`Team with name "${teamName}" already exists. please enter other name.`) - return; - } - createTeam({ - teamName: teamName, - createdBy: user?.email, - teamMembers:[user.email] - }).then((resp) => { - if (resp) { - router.push("/dashboard"); - toast.success("Team created successfully!!!"); + try { + const res = await axiosInstance.post(createNewTeamUrl,{ + teamName + }); + if(res.status === 200){ + router.push('/dashboard'); + toast.success("File created Successfully"); } - }); + } catch (err) { + + console.log(err); + } }; return ( diff --git a/src/components/shared/SignupForm.tsx b/src/components/shared/SignupForm.tsx index 0ed5c1f..1c0d514 100644 --- a/src/components/shared/SignupForm.tsx +++ b/src/components/shared/SignupForm.tsx @@ -27,8 +27,8 @@ const FormSchema = z firstName: z.string().min(3, { message: "Minimum Length should be 3", }), - lastName: z.string().min(8, { - message: "Minimum Length should be 8", + lastName: z.string().min(3, { + message: "Minimum Length should be 3", }), email: z.string().email().min(1, { message: "Email required!", diff --git a/src/lib/API-URLs.ts b/src/lib/API-URLs.ts index ecb034f..8ba6413 100644 --- a/src/lib/API-URLs.ts +++ b/src/lib/API-URLs.ts @@ -5,4 +5,5 @@ export const deleteTeamMemberUrl = "/api/teams/members"; export const updateReadAccessUrl = "/api/files/read"; export const updateWriteAccessUrl = "/api/files/write"; export const registerUserUrl = "/api/auth/register"; -export const checkHealthUrl = "/api/health"; \ No newline at end of file +export const checkHealthUrl = "/api/health"; +export const createNewTeamUrl = "/api/teams/create"; \ No newline at end of file