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