update: get all the text from backend
This commit is contained in:
parent
b405fc315b
commit
39bb647b5c
@ -16,7 +16,7 @@ export const POST = async (req: NextRequest) => {
|
|||||||
{
|
{
|
||||||
review: {
|
review: {
|
||||||
_name: validatedRequest.name,
|
_name: validatedRequest.name,
|
||||||
_otzyv: validatedRequest.text,
|
_otzyv: validatedRequest.reviewMessage,
|
||||||
_rejting: validatedRequest.rating,
|
_rejting: validatedRequest.rating,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export const reviewSchema = z.object({
|
|||||||
.string()
|
.string()
|
||||||
.min(2, { message: 'Имя должно содержать не менее 2 символов' }),
|
.min(2, { message: 'Имя должно содержать не менее 2 символов' }),
|
||||||
rating: z.number().min(1, { message: 'Пожалуйста, выберите рейтинг' }).max(5),
|
rating: z.number().min(1, { message: 'Пожалуйста, выберите рейтинг' }).max(5),
|
||||||
text: z
|
reviewMessage: z
|
||||||
.string()
|
.string()
|
||||||
.min(10, { message: 'Отзыв должен содержать не менее 10 символов' }),
|
.min(10, { message: 'Отзыв должен содержать не менее 10 символов' }),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { useState } from 'react';
|
|||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
import { useTextController } from '@/shared/language';
|
||||||
import { Button } from '@/shared/shadcn-ui/button';
|
import { Button } from '@/shared/shadcn-ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -32,6 +33,7 @@ import { useCreateReviewMutation } from '../api/reviews.api';
|
|||||||
import { ReviewFormValues, reviewSchema } from '../model/review-form.schema';
|
import { ReviewFormValues, reviewSchema } from '../model/review-form.schema';
|
||||||
|
|
||||||
export function ReviewForm() {
|
export function ReviewForm() {
|
||||||
|
const { t } = useTextController();
|
||||||
const [openReviewFormDialog, setOpenReviewFormDialog] = useState(false);
|
const [openReviewFormDialog, setOpenReviewFormDialog] = useState(false);
|
||||||
const [hoveredStar, setHoveredStar] = useState(0);
|
const [hoveredStar, setHoveredStar] = useState(0);
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ export function ReviewForm() {
|
|||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: '',
|
name: '',
|
||||||
rating: 0,
|
rating: 0,
|
||||||
text: '',
|
reviewMessage: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,22 +52,16 @@ export function ReviewForm() {
|
|||||||
try {
|
try {
|
||||||
await createReview(data);
|
await createReview(data);
|
||||||
|
|
||||||
toast.success(
|
toast.success(t('about.review-form.dialog.successResponse'), {
|
||||||
'Спасибо за ваш отзыв! Он будет опубликован после модерации.',
|
duration: 5000,
|
||||||
{
|
});
|
||||||
duration: 5000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
form.reset();
|
form.reset();
|
||||||
setOpenReviewFormDialog(false);
|
setOpenReviewFormDialog(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(
|
toast.error(t('about.review-form.dialog.errorResponse'), {
|
||||||
'Произошла ошибка при отправке отзыва. Пожалуйста, попробуйте позже.',
|
duration: 5000,
|
||||||
{
|
});
|
||||||
duration: 5000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -110,17 +106,17 @@ export function ReviewForm() {
|
|||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button className='flex shadow-lg transition-all duration-300 hover:scale-105'>
|
<Button className='flex shadow-lg transition-all duration-300 hover:scale-105'>
|
||||||
<Plus />
|
<Plus />
|
||||||
<span>Добавить отзыв</span>
|
<span>{t('common.buttons.addReview')}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className='overflow-hidden rounded-xl border-none bg-white/95 p-0 shadow-xl backdrop-blur-sm sm:max-w-[500px]'>
|
<DialogContent className='overflow-hidden rounded-xl border-none bg-white/95 p-0 shadow-xl backdrop-blur-sm sm:max-w-[500px]'>
|
||||||
<div className='p-6'>
|
<div className='p-6'>
|
||||||
<DialogHeader className='pb-4'>
|
<DialogHeader className='pb-4'>
|
||||||
<DialogTitle className='text-center text-2xl font-bold'>
|
<DialogTitle className='text-center text-2xl font-bold'>
|
||||||
Оставьте свой отзыв
|
{t('about.review-form.dialog.title')}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className='pt-2 text-center'>
|
<DialogDescription className='pt-2 text-center'>
|
||||||
Поделитесь своим опытом с нашей компанией
|
{t('about.review-form.dialog.description')}
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
@ -133,11 +129,15 @@ export function ReviewForm() {
|
|||||||
control={form.control}
|
control={form.control}
|
||||||
name='name'
|
name='name'
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem className='flex flex-col'>
|
||||||
<FormLabel>Ваше имя</FormLabel>
|
<FormLabel>
|
||||||
|
{t('about.review-form.dialog.field.name')}
|
||||||
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
placeholder='Введите ваше имя'
|
placeholder={t(
|
||||||
|
'about.review-form.dialog.field.name.placeholder',
|
||||||
|
)}
|
||||||
{...field}
|
{...field}
|
||||||
className='bg-white/50'
|
className='bg-white/50'
|
||||||
/>
|
/>
|
||||||
@ -152,7 +152,9 @@ export function ReviewForm() {
|
|||||||
name='rating'
|
name='rating'
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className='space-y-3'>
|
<FormItem className='space-y-3'>
|
||||||
<FormLabel className='block'>Ваша оценка</FormLabel>
|
<FormLabel className='block'>
|
||||||
|
{t('about.review-form.dialog.field.rating')}
|
||||||
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<StarRating
|
<StarRating
|
||||||
value={field.value}
|
value={field.value}
|
||||||
@ -166,19 +168,23 @@ export function ReviewForm() {
|
|||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name='text'
|
name='reviewMessage'
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem className='flex flex-col'>
|
||||||
<FormLabel>Ваш отзыв</FormLabel>
|
<FormLabel>
|
||||||
|
{t('about.review-form.dialog.field.reviewMessage')}
|
||||||
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Textarea
|
<Textarea
|
||||||
placeholder='Расскажите о вашем опыте...'
|
placeholder={t(
|
||||||
|
'about.review-form.dialog.field.reviewMessage.placeholder',
|
||||||
|
)}
|
||||||
className='min-h-[120px] resize-none bg-white/50'
|
className='min-h-[120px] resize-none bg-white/50'
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Ваш отзыв будет опубликован после модерации.
|
{t('about.review-form.dialog.noteMessage')}
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
@ -197,7 +203,7 @@ export function ReviewForm() {
|
|||||||
Отправка...
|
Отправка...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
'Отправить отзыв'
|
t('common.buttons.sendReview')
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user