-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateTeamDialog.tsx
112 lines (107 loc) · 4.41 KB
/
CreateTeamDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use client';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { createTeamAction } from '@/data/user/teams';
import { useSAToastMutation } from '@/hooks/useSAToastMutation';
import { PlusIcon } from '@radix-ui/react-icons';
import UsersIcon from 'lucide-react/dist/esm/icons/users';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
type CreateTeamDialogProps = {
organizationId: string;
};
export function CreateTeamDialog({ organizationId }: CreateTeamDialogProps) {
const [teamTitle, setTeamTitle] = useState<string>('');
const [open, setOpen] = useState(false);
const router = useRouter();
const { mutate, isLoading } = useSAToastMutation(
async () => await createTeamAction(organizationId, teamTitle),
{
loadingMessage: 'Creating team...',
successMessage: 'Team created!',
errorMessage: 'Failed to create team.',
onSuccess: (data) => {
if (data.status === 'success') {
setOpen(false);
router.push(`/org/${organizationId}/team/${data.data.id}`);
}
},
},
);
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
mutate();
};
return (
<>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button>
<PlusIcon className='mr-2' /> Create team
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<div className="p-3 w-fit bg-gray-200/50 dark:bg-gray-700/40 mb-2 rounded-lg">
<UsersIcon className=" w-6 h-6" />
</div>
<div className="p-1">
<DialogTitle className="text-lg">Create Team</DialogTitle>
<DialogDescription className="text-base mt-0">
Collaborate with your team members on your project.
</DialogDescription>
</div>
</DialogHeader>
<form onSubmit={handleSubmit}>
<div className="mb-8">
<Label className="text-muted-foreground">Team Name</Label>
<Input
value={teamTitle}
onChange={(event) => {
setTeamTitle(event.target.value);
}}
required
className="mt-1.5 shadow appearance-none border h-11 rounded-lg w-full py-2 px-3 focus:ring-0 text-gray-700 dark:text-gray-300 leading-tight focus:outline-none focus:shadow-outline text-base"
id="name"
type="text"
placeholder="Team Name"
disabled={isLoading}
/>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
disabled={isLoading}
className="w-full"
onClick={() => {
setOpen(false);
}}
>
Cancel
</Button>
<Button
type="submit"
variant="default"
className="w-full"
disabled={isLoading}
>
{isLoading ? 'Creating Team...' : 'Create Team'}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</>
);
}