Skip to content

Commit

Permalink
remove redundant fragments - #144
Browse files Browse the repository at this point in the history
  • Loading branch information
alan2207 committed May 14, 2024
1 parent fc87fac commit 2ca9398
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 75 deletions.
58 changes: 28 additions & 30 deletions src/components/ui/form/form-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,33 @@ export const FormDrawer = ({
}, [isDone, close]);

return (
<>
<Drawer
open={isOpen}
onOpenChange={(isOpen) => {
if (!isOpen) {
close();
} else {
open();
}
}}
>
<DrawerTrigger asChild>{triggerButton}</DrawerTrigger>
<DrawerContent className="flex max-w-[800px] flex-col justify-between sm:max-w-[540px]">
<div className="flex flex-col">
<DrawerHeader>
<DrawerTitle>{title}</DrawerTitle>
</DrawerHeader>
<div>{children}</div>
</div>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="outline" type="submit">
Close
</Button>
</DrawerClose>
{submitButton}
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
<Drawer
open={isOpen}
onOpenChange={(isOpen) => {
if (!isOpen) {
close();
} else {
open();
}
}}
>
<DrawerTrigger asChild>{triggerButton}</DrawerTrigger>
<DrawerContent className="flex max-w-[800px] flex-col justify-between sm:max-w-[540px]">
<div className="flex flex-col">
<DrawerHeader>
<DrawerTitle>{title}</DrawerTitle>
</DrawerHeader>
<div>{children}</div>
</div>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="outline" type="submit">
Close
</Button>
</DrawerClose>
{submitButton}
</DrawerFooter>
</DrawerContent>
</Drawer>
);
};
84 changes: 39 additions & 45 deletions src/features/comments/components/create-comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,45 @@ type CreateCommentProps = {
export const CreateComment = ({ discussionId }: CreateCommentProps) => {
const createCommentMutation = useCreateComment({ discussionId });
return (
<>
<FormDrawer
isDone={createCommentMutation.isSuccess}
triggerButton={
<Button size="sm" icon={<Plus className="size-4" />}>
Create Comment
</Button>
}
title="Create Comment"
submitButton={
<Button
isLoading={createCommentMutation.isPending}
form="create-comment"
type="submit"
size="sm"
disabled={createCommentMutation.isPending}
>
Submit
</Button>
}
>
<Form
id="create-comment"
onSubmit={async (values) => {
await createCommentMutation.mutateAsync({
data: values,
});
}}
schema={createCommentInputSchema}
options={{
defaultValues: {
body: '',
discussionId: discussionId,
},
}}
<FormDrawer
isDone={createCommentMutation.isSuccess}
triggerButton={
<Button size="sm" icon={<Plus className="size-4" />}>
Create Comment
</Button>
}
title="Create Comment"
submitButton={
<Button
isLoading={createCommentMutation.isPending}
form="create-comment"
type="submit"
size="sm"
disabled={createCommentMutation.isPending}
>
{({ register, formState }) => (
<Textarea
label="Body"
error={formState.errors['body']}
registration={register('body')}
/>
)}
</Form>
</FormDrawer>
</>
Submit
</Button>
}
>
<Form
id="create-comment"
onSubmit={async (values) => {
await createCommentMutation.mutateAsync({
data: values,
});
}}
schema={createCommentInputSchema}
options={{
defaultValues: {
body: '',
discussionId: discussionId,
},
}}
>
{({ register, formState }) => (
<Textarea label="Body" error={formState.errors['body']} registration={register('body')} />
)}
</Form>
</FormDrawer>
);
};

0 comments on commit 2ca9398

Please sign in to comment.