-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
create-discussion.tsx
73 lines (68 loc) · 1.93 KB
/
create-discussion.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
import { Plus } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Form, FormDrawer, Input, Textarea } from '@/components/ui/form';
import { useNotifications } from '@/components/ui/notifications';
import { Authorization, ROLES } from '@/lib/authorization';
import {
createDiscussionInputSchema,
useCreateDiscussion,
} from '../api/create-discussion';
export const CreateDiscussion = () => {
const { addNotification } = useNotifications();
const createDiscussionMutation = useCreateDiscussion({
mutationConfig: {
onSuccess: () => {
addNotification({
type: 'success',
title: 'Discussion Created',
});
},
},
});
return (
<Authorization allowedRoles={[ROLES.ADMIN]}>
<FormDrawer
isDone={createDiscussionMutation.isSuccess}
triggerButton={
<Button size="sm" icon={<Plus className="size-4" />}>
Create Discussion
</Button>
}
title="Create Discussion"
submitButton={
<Button
form="create-discussion"
type="submit"
size="sm"
isLoading={createDiscussionMutation.isPending}
>
Submit
</Button>
}
>
<Form
id="create-discussion"
onSubmit={(values) => {
createDiscussionMutation.mutate({ data: values });
}}
schema={createDiscussionInputSchema}
>
{({ register, formState }) => (
<>
<Input
label="Title"
error={formState.errors['title']}
registration={register('title')}
/>
<Textarea
label="Body"
error={formState.errors['body']}
registration={register('body')}
/>
</>
)}
</Form>
</FormDrawer>
</Authorization>
);
};