Blog creation and filling dialog completed #1

Merged
neki merged 10 commits from feature/blogCreationAndFilling into develop 2025-02-01 09:10:18 +00:00
2 changed files with 82 additions and 69 deletions
Showing only changes of commit 19ee51a739 - Show all commits

View File

@ -1,37 +1,44 @@
import * as Dialog from "@radix-ui/react-dialog"; import * as Dialog from "@radix-ui/react-dialog";
import { Cross2Icon, PlusIcon } from "@radix-ui/react-icons"; import { Cross2Icon, PlusIcon } from "@radix-ui/react-icons";
import { Box, Button } from "@radix-ui/themes"; import { Box, Button, Heading, Text, Theme } from "@radix-ui/themes";
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import { useState } from "react"; import { useState } from "react";
import { axiosLocalhost } from "../../../api/axios/axios"; import { axiosLocalhost } from "../../../api/axios/axios";
import queryClient from "../../../api/QueryClient/QueryClient";
import useToast from "../../../hooks/useToast"; import useToast from "../../../hooks/useToast";
export default function BlogCreationDialog() { export default function BlogCreationDialog() {
const createToast = useToast() const createToast = useToast();
const [title, setTitle] = useState<string>("My blog"); const [title, setTitle] = useState<string>("My blog");
const [description, setDescription] = useState<string>(""); const [description, setDescription] = useState<string>("");
const addMutation = useMutation({ const addMutation = useMutation({
onMutate: () => { onMutate: () => {},
},
mutationFn: async () => { mutationFn: async () => {
await axiosLocalhost.post("/blogs", { await axiosLocalhost.post("/blogs", {
title, title,
description description,
}) });
}, },
onSuccess: () => { onSuccess: () => {
createToast({title: `Success!`, description: `Blog created successfully!`}); createToast({
title: `Success!`,
description: `Blog created successfully!`,
});
}, },
onError: (_error) => { onError: (_error) => {
createToast({title: `Error!`, description: `Blog creation failed!`}); createToast({
title: `Error!`,
description: `Blog creation failed!`,
});
}, },
onSettled: () => { onSettled: () => {
queryClient.invalidateQueries({
} queryKey: ["userBlogs"],
});
},
}); });
return ( return (
<Box> <Box>
@ -42,20 +49,22 @@ export default function BlogCreationDialog() {
</Button> </Button>
</Dialog.Trigger> </Dialog.Trigger>
<Dialog.Portal> <Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-blackA6 data-[state=open]:animate-overlayShow" /> <Box>
<Dialog.Content className="fixed left-1/2 top-1/2 max-h-[85vh] w-[90vw] max-w-[450px] -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-[25px] shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] focus:outline-none data-[state=open]:animate-contentShow"> <Theme>
<Dialog.Overlay className="fixed inset-0 bg-black/40 backdrop-blur-sm data-[state=open]:animate-appear" />
<Dialog.Content className="fixed left-1/2 top-1/2 max-h-[85vh] w-[90vw] max-w-[600px] -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-[25px] shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] focus:outline-none data-[state=open]:animate-appear">
<Dialog.Title className="m-0 text-[17px] font-medium text-mauve12"> <Dialog.Title className="m-0 text-[17px] font-medium text-mauve12">
Create blog <Heading>Create blog</Heading>
</Dialog.Title> </Dialog.Title>
<Dialog.Description className="mb-5 mt-2.5 text-[15px] leading-normal text-mauve11"> <Dialog.Description className="mb-5 mt-2.5 text-[15px] leading-normal text-mauve11">
Create your new blog. <Text>Create your new blog.</Text>
</Dialog.Description> </Dialog.Description>
<fieldset className="mb-[15px] flex items-center gap-5"> <fieldset className="mb-[15px] flex items-center gap-5">
<label <label
className="w-[90px] text-right text-[15px] text-violet11" className="w-[90px] text-right text-[15px] text-violet11"
htmlFor="title" htmlFor="title"
> >
Blog title <Text>Blog title</Text>
</label> </label>
<input <input
className="inline-flex h-[35px] w-full flex-1 items-center justify-center rounded px-2.5 text-[15px] leading-none text-violet11 shadow-[0_0_0_1px] shadow-violet7 outline-none focus:shadow-[0_0_0_2px] focus:shadow-violet8" className="inline-flex h-[35px] w-full flex-1 items-center justify-center rounded px-2.5 text-[15px] leading-none text-violet11 shadow-[0_0_0_1px] shadow-violet7 outline-none focus:shadow-[0_0_0_2px] focus:shadow-violet8"
@ -71,7 +80,7 @@ export default function BlogCreationDialog() {
className="w-[90px] text-right text-[15px] text-violet11" className="w-[90px] text-right text-[15px] text-violet11"
htmlFor="Description" htmlFor="Description"
> >
Description <Text>Description</Text>
</label> </label>
<textarea <textarea
className="pt-2 inline-flex h-[35px] w-full flex-1 items-center justify-center rounded px-2.5 text-[15px] leading-none text-violet11 shadow-[0_0_0_1px] shadow-violet7 outline-none focus:shadow-[0_0_0_2px] focus:shadow-violet8" className="pt-2 inline-flex h-[35px] w-full flex-1 items-center justify-center rounded px-2.5 text-[15px] leading-none text-violet11 shadow-[0_0_0_1px] shadow-violet7 outline-none focus:shadow-[0_0_0_2px] focus:shadow-violet8"
@ -83,7 +92,8 @@ export default function BlogCreationDialog() {
/> />
</fieldset> </fieldset>
<div className="mt-[25px] flex justify-end"> <div className="mt-[25px] flex justify-end">
<Dialog.Close asChild <Dialog.Close
asChild
onClick={() => { onClick={() => {
addMutation.mutate(); addMutation.mutate();
}} }}
@ -100,6 +110,8 @@ export default function BlogCreationDialog() {
</button> </button>
</Dialog.Close> </Dialog.Close>
</Dialog.Content> </Dialog.Content>
</Theme>
</Box>
</Dialog.Portal> </Dialog.Portal>
</Dialog.Root> </Dialog.Root>
</Box> </Box>

View File

@ -34,6 +34,7 @@ export default {
} }
}, },
appear: { appear: {
"0%": { opacity: "0" },
"100%": { opacity: "1" }, "100%": { opacity: "1" },
}, },
widthOut: { widthOut: {