Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create new file api integration #456

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Loading