| 1 | 'use client' |
| 2 | |
| 3 | import { useRouter } from '@bprogress/next/app' |
| 4 | import { useAction } |
| 5 | import { useState } |
| 6 | import { toast } |
| 7 | import { Button } |
| 8 | import { |
| 9 | Dialog, |
| 10 | DialogContent, |
| 11 | DialogHeader, |
| 12 | DialogTitle, |
| 13 | } from '@/components/ui/dialog' |
| 14 | import { Input } |
| 15 | import { Label } |
| 16 | import { createTeamAction } |
| 17 | |
| 18 | export default function CreateTeamDialog |
| 19 | open, |
| 20 | onOpenChange, |
| 21 | organizationId, |
| 22 | }: { |
| 23 | open: boolean |
| 24 | onOpenChange: (open |
| 25 | organizationId: string |
| 26 | }) { |
| 27 | const router = |
| 28 | const [name, |
| 29 | |
| 30 | const { execute, |
| 31 | onSuccess() { |
| 32 | toast.success('Team created |
| 33 | setName('') |
| 34 | onOpenChange(false) |
| 35 | router.refresh() |
| 36 | }, |
| 37 | onError({ error |
| 38 | toast.error(error |
| 39 | }, |
| 40 | }) |
| 41 | |
| 42 | return ( |
| 43 | <Dialog onOpenChange={ |
| 44 | <DialogContent className=' |
| 45 | <DialogHeader> |
| 46 | <DialogTitle>Create Team</DialogTitle |
| 47 | </DialogHeader> |
| 48 | <div className='space-y-4 |
| 49 | <div className='space-y-2 |
| 50 | <Label>Team Name</Label |
| 51 | <Input |
| 52 | autoFocus |
| 53 | onChange={(e) |
| 54 | onKeyDown={(e) |
| 55 | if (e.key |
| 56 | execute({ organizationId, |
| 57 | } |
| 58 | }} |
| 59 | placeholder='e.g. Engineering, Design' |
| 60 | value={name} |
| 61 | /> |
| 62 | </div> |
| 63 | <div className='flex justify-end gap-2 |
| 64 | <Button onClick={ |
| 65 | Cancel |
| 66 | </Button> |
| 67 | <Button |
| 68 | disabled={!name. |
| 69 | loading={isPending} |
| 70 | onClick={() => |
| 71 | > |
| 72 | Create |
| 73 | </Button> |
| 74 | </div> |
| 75 | </div> |
| 76 | </DialogContent> |
| 77 | </Dialog> |
| 78 | ) |
| 79 | } |