Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { queryClient } from "@/app/providers";
- import { ICreateFaqItemBody, faqServie } from "@/shared/api";
- import { removeToken } from "@/shared/lib";
- import { useMutation } from "@tanstack/react-query";
- import { App } from "antd";
- import axios from "axios";
- import { useNavigate } from "react-router-dom";
- export const useCreateFaqItem = () => {
- const { notification } = App.useApp();
- const navigate = useNavigate();
- const createFaqItem = useMutation({
- mutationFn: (body: ICreateFaqItemBody) => faqServie.createFaqItem(body),
- onSuccess: (data) => {
- if (data.data.code === "SUCCESS") {
- notification.success({
- message: data.data.text,
- });
- queryClient.invalidateQueries({
- queryKey: ["faq"],
- });
- }
- if (data.data.code === "ERROR") {
- notification.error({
- message: data.data.text,
- });
- }
- },
- onError: (error) => {
- if (axios.isAxiosError(error)) {
- notification.error({
- message: error.message,
- });
- if (error.response && error.response.status === 401) {
- navigate("/sign-in");
- }
- } else {
- notification.error({
- message: error.message ? error.message : "Что то пошло не так!",
- });
- removeToken();
- navigate("/sign-in");
- console.log("Create Faq Item Error", error);
- }
- },
- });
- return { createFaqItem };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement