import { FC } from 'react' import Input from '../../../components/Input' import Textarea from '../../../components/Textarea' import Button from '../../../components/Button' import { useFormik } from 'formik' import * as Yup from 'yup' import { ErrorType } from '../../../helpers/types' import { toast } from 'react-toastify' import { useCreateBlogComment } from '../hooks/useBlogsData' import { CreateBlogCommentType } from '../types/BlogTypes' import { useSharedStore } from '@/shared/store/sharedStore' import Link from 'next/link' import { LOGIN_URL } from '@/config/const' type Props = { refetch: () => void id: string } const CreateReview: FC = ({ refetch, id }) => { const { isLogin } = useSharedStore() const createReview = useCreateBlogComment() const formik = useFormik({ initialValues: { title: '', content: '' }, validationSchema: Yup.object({ title: Yup.string().required('این فیلد الزامی است'), content: Yup.string().required('این فیلد الزامی است'), }), onSubmit: (values) => { createReview.mutate({ id: id, params: values }, { onSuccess: () => { formik.resetForm() refetch() }, onError: (error: ErrorType) => { if (error.response && 'status' in error.response && error.response.status === 401) { window.location.href = LOGIN_URL + '?redirect=' + window.location.href } else { toast.error(error.response?.data?.error?.message?.[0] || 'An error occurred') } } }) }, }) return (
ارسال نظر
{ !isLogin ? (
برای ارسال نظر لطفا وارد حساب کاربری خود شوید
) : (