|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Button } from "@/components/ui/button"; |
| 4 | +import { Input } from "@/components/ui/input"; |
| 5 | +import { Label } from "@/components/ui/label"; |
| 6 | +import { api } from "@/convex/_generated/api"; |
| 7 | +import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs"; |
| 8 | +import { useMutation } from "convex/react"; |
| 9 | +import { useRouter } from "next/navigation"; |
| 10 | + |
| 11 | +import React, { useState } from "react"; |
| 12 | +import { toast } from "sonner"; |
| 13 | + |
| 14 | +const page = () => { |
| 15 | + const [teamName, setTeamName] = useState("" as string); |
| 16 | + const { user } = useKindeBrowserClient(); |
| 17 | + const createTeam = useMutation(api.teams.createTeam); |
| 18 | + const router = useRouter(); |
| 19 | + const handleCreateTeam = async () => { |
| 20 | + await createTeam({ |
| 21 | + teamName, |
| 22 | + createdBy: user?.email!, |
| 23 | + }).then((res) => { |
| 24 | + console.log(res); |
| 25 | + if (res) { |
| 26 | + router.push("/dashboard"); |
| 27 | + toast.success("Team created successfully"); |
| 28 | + } |
| 29 | + }); |
| 30 | + }; |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className="relative h-screen flex items-center justify-center"> |
| 34 | + <div className="absolute top-8 left-8 flex items-center space-x-2"> |
| 35 | + <img src="/logo.svg" alt="logo" className="w-10 h-10" /> |
| 36 | + <h1 className="text-white font-bold">eraser</h1> |
| 37 | + </div> |
| 38 | + <div className="flex flex-col gap-4 justify-center items-center"> |
| 39 | + <div className="text-center w-full"> |
| 40 | + <h1 className="font-bold text-4xl mb-4"> |
| 41 | + What should we call your team? |
| 42 | + </h1> |
| 43 | + |
| 44 | + <h3 className="text-neutral-400"> |
| 45 | + You can always change this later from settings. |
| 46 | + </h3> |
| 47 | + </div> |
| 48 | + <div className="grid w-full max-w-lg items-center gap-1.5 mt-16 mb-16"> |
| 49 | + <Label htmlFor="team_name">Team Name</Label> |
| 50 | + <Input |
| 51 | + className="bg-neutral-800 m-1" |
| 52 | + type="text" |
| 53 | + id="team_name" |
| 54 | + placeholder="Team Name" |
| 55 | + onChange={(e) => setTeamName(e.target.value)} |
| 56 | + onSubmit={(e) => { |
| 57 | + e.preventDefault(); |
| 58 | + handleCreateTeam(); |
| 59 | + }} |
| 60 | + /> |
| 61 | + </div> |
| 62 | + |
| 63 | + <Button |
| 64 | + onClick={handleCreateTeam} |
| 65 | + disabled={!(teamName && teamName.length > 0)} |
| 66 | + className="bg-blue-500 text-white w-full max-w-[300px] hover:bg-blue-600" |
| 67 | + > |
| 68 | + Create team |
| 69 | + </Button> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + ); |
| 73 | +}; |
| 74 | + |
| 75 | +export default page; |
0 commit comments