Skip to content

Commit

Permalink
Merge pull request #456 from Sid-80/feat/453
Browse files Browse the repository at this point in the history
feat: create new file api integration
  • Loading branch information
subhadeeproy3902 authored Jul 11, 2024
2 parents 5a1e52d + 4566a55 commit 3142c46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
34 changes: 14 additions & 20 deletions src/app/teams/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions src/components/shared/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/API-URLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
export const checkHealthUrl = "/api/health";
export const createNewTeamUrl = "/api/teams/create";

0 comments on commit 3142c46

Please sign in to comment.