From ca4a27e5823935cd3ea367fcef9ad6f82f7ad9c1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Jan 2025 14:55:37 +0300 Subject: [PATCH 01/10] Added blog creation --- .../BlogCreationDialog/BlogCreationDialog.tsx | 107 ++++++++++++++++++ .../src/Pages/UserBlogsPage/UserBlogsPage.tsx | 66 +---------- enshi_back/routes/routesSetup.go | 2 +- 3 files changed, 111 insertions(+), 64 deletions(-) create mode 100644 enshi/src/Components/Dialogs/BlogCreationDialog/BlogCreationDialog.tsx diff --git a/enshi/src/Components/Dialogs/BlogCreationDialog/BlogCreationDialog.tsx b/enshi/src/Components/Dialogs/BlogCreationDialog/BlogCreationDialog.tsx new file mode 100644 index 0000000..62dd976 --- /dev/null +++ b/enshi/src/Components/Dialogs/BlogCreationDialog/BlogCreationDialog.tsx @@ -0,0 +1,107 @@ +import * as Dialog from "@radix-ui/react-dialog"; +import { Cross2Icon, PlusIcon } from "@radix-ui/react-icons"; +import { Box, Button } from "@radix-ui/themes"; +import { useMutation } from "@tanstack/react-query"; +import { useState } from "react"; +import { axiosLocalhost } from "../../../api/axios/axios"; +import useToast from "../../../hooks/useToast"; + +export default function BlogCreationDialog() { + const createToast = useToast() + + const [title, setTitle] = useState("My blog"); + const [description, setDescription] = useState(""); + + const addMutation = useMutation({ + onMutate: () => { + }, + mutationFn: async () => { + await axiosLocalhost.post("/blogs", { + title, + description + }) + }, + onSuccess: () => { + createToast({title: `Success!`, description: `Blog created successfully!`}); + }, + onError: (_error) => { + createToast({title: `Error!`, description: `Blog creation failed!`}); + }, + onSettled: () => { + + } + }); + + + return ( + + + + + + + + + + Create blog + + + Create your new blog. + +
+ + { + setTitle(e.target.value); + }} + /> +
+
+ +